diff --git a/db/migrate/20260115153219_use_snowflake_ids_for_collections.rb b/db/migrate/20260115153219_use_snowflake_ids_for_collections.rb new file mode 100644 index 00000000000..25aad0732ed --- /dev/null +++ b/db/migrate/20260115153219_use_snowflake_ids_for_collections.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class UseSnowflakeIdsForCollections < ActiveRecord::Migration[8.0] + def up + safety_assured do + execute(<<~SQL.squish) + ALTER TABLE collections ALTER COLUMN id SET DEFAULT timestamp_id('collections'); + ALTER TABLE collection_items ALTER COLUMN id SET DEFAULT timestamp_id('collection_items'); + SQL + end + + Mastodon::Snowflake.ensure_id_sequences_exist + end + + def down + execute(<<~SQL.squish) + LOCK collections; + SELECT setval('collections_id_seq', (SELECT MAX(id) FROM collections)); + ALTER TABLE collections ALTER COLUMN id SET DEFAULT nextval('collections_id_seq'); + LOCK collection_items; + SELECT setval('collection_items_id_seq', (SELECT MAX(id) FROM collection_items)); + ALTER TABLE collection_items ALTER COLUMN id SET DEFAULT nextval('collection_items_id_seq'); + SQL + end +end diff --git a/db/schema.rb b/db/schema.rb index 78d7ef68261..8dc1e88fd17 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_12_17_091936) do +ActiveRecord::Schema[8.0].define(version: 2026_01_15_153219) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -352,7 +352,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_12_17_091936) do t.index ["reference_account_id"], name: "index_canonical_email_blocks_on_reference_account_id" end - create_table "collection_items", force: :cascade do |t| + create_table "collection_items", id: :bigint, default: -> { "timestamp_id('collection_items'::text)" }, force: :cascade do |t| t.bigint "collection_id", null: false t.bigint "account_id" t.integer "position", default: 1, null: false @@ -369,7 +369,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_12_17_091936) do t.index ["object_uri"], name: "index_collection_items_on_object_uri", unique: true, where: "(activity_uri IS NOT NULL)" end - create_table "collections", force: :cascade do |t| + create_table "collections", id: :bigint, default: -> { "timestamp_id('collections'::text)" }, force: :cascade do |t| t.bigint "account_id", null: false t.string "name", null: false t.text "description", null: false