···11+class AddImportCollections < ActiveRecord::Migration[7.2]
22+ def change
33+ add_column :imports, :collection, :string, limit: 20, null: true
44+55+ reversible do |dir|
66+ dir.up do
77+ execute "UPDATE imports SET collection = 'likes'"
88+ end
99+ end
1010+1111+ change_column_null :imports, :collection, false
1212+1313+ remove_index :imports, :user_id, unique: true
1414+ add_index :imports, [:user_id, :collection], unique: true
1515+1616+ reversible do |dir|
1717+ dir.down do
1818+ execute "DELETE FROM imports WHERE collection != 'likes'"
1919+ end
2020+ end
2121+ end
2222+end
+3-2
db/schema.rb
···1010#
1111# It's strongly recommended that you check this file into your version control system.
12121313-ActiveRecord::Schema[7.2].define(version: 2025_08_31_210930) do
1313+ActiveRecord::Schema[7.2].define(version: 2025_09_03_215014) do
1414 # These are extensions that must be enabled in order to support this database
1515 enable_extension "plpgsql"
1616···1919 t.string "cursor"
2020 t.datetime "started_from"
2121 t.datetime "last_completed"
2222- t.index ["user_id"], name: "index_imports_on_user_id", unique: true
2222+ t.string "collection", limit: 20, null: false
2323+ t.index ["user_id", "collection"], name: "index_imports_on_user_id_and_collection", unique: true
2324 end
24252526 create_table "likes", force: :cascade do |t|