Use snowflake ids for collections and their items (#37514)

This commit is contained in:
David Roetzel 2026-01-16 10:49:53 +01:00 committed by GitHub
parent 0d9fcb59a4
commit be00db4fa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -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