  class CreateUserAssets < ActiveRecord::Migration
    def self.up
      execute(<<-SQL
        CREATE TABLE public.user_assets (
          id character varying(64) DEFAULT public.uuid_generate_v4() PRIMARY KEY NOT NULL,
          user_id character varying(64) NOT NULL,
          asset_type character varying(64),
          created_at timestamp without time zone DEFAULT now() NOT NULL,
          uri character varying(1024),
          filename character varying(256),
          recording_id character varying(64),
          session_id character varying(64),
          ext_id character varying(64),
          metadata json
        );    
      SQL
      )
      execute("CREATE INDEX index_user_assets_asset_type ON public.user_assets USING btree (asset_type);");
      execute("CREATE INDEX index_user_assets_recording_id ON public.user_assets USING btree (recording_id);");
      execute("CREATE INDEX index_user_assets_session_id ON public.user_assets USING btree (session_id);");
    end
    
    def self.down
      execute("DROP INDEX index_user_assets_asset_type;")
      execute("DROP INDEX index_user_assets_recording_id;")
      execute("DROP INDEX index_user_assets_session_id;")
      execute("DROP TABLE public.user_assets;")
    end
  end
