class CreateDomainE621Users < ActiveRecord::Migration[7.2]
  def change
    up_only { execute <<~SQL }
        SET DEFAULT_TABLESPACE = mirai;
      SQL

    create_table :domain_e621_users do |t|
      t.integer :e621_user_id, null: false, index: { unique: true }
      t.datetime :scanned_favs_at
      t.string :name, null: false
      t.timestamps
    end

    create_table :domain_e621_favs do |t|
      t.references :user,
                   null: false,
                   index: false,
                   foreign_key: {
                     to_table: :domain_e621_users,
                   }
      t.references :post,
                   null: false,
                   foreign_key: {
                     to_table: :domain_e621_posts,
                   }

      t.index %i[user_id post_id], unique: true
      t.timestamps
    end
  end
end
