Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Change account ids to snowflake ids (mastodon#15844)
Browse files Browse the repository at this point in the history
Co-authored-by: Eugen Rochko <[email protected]>
  • Loading branch information
ClearlyClaire and Gargron authored Apr 15, 2021
1 parent ce2148c commit d5edf22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions db/migrate/20210306164523_account_ids_to_timestamp_ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AccountIdsToTimestampIds < ActiveRecord::Migration[5.1]
def up
# Set up the accounts.id column to use our timestamp-based IDs.
safety_assured do
execute("ALTER TABLE accounts ALTER COLUMN id SET DEFAULT timestamp_id('accounts')")
end

# Make sure we have a sequence to use.
Mastodon::Snowflake.ensure_id_sequences_exist
end

def down
execute("LOCK accounts")
execute("SELECT setval('accounts_id_seq', (SELECT MAX(id) FROM accounts))")
execute("ALTER TABLE accounts ALTER COLUMN id SET DEFAULT nextval('accounts_id_seq')")
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
t.index ["target_account_id"], name: "index_account_warnings_on_target_account_id"
end

create_table "accounts", force: :cascade do |t|
create_table "accounts", id: :bigint, default: -> { "timestamp_id('statuses'::text)" }, force: :cascade do |t|
t.string "username", default: "", null: false
t.string "domain"
t.string "secret", default: "", null: false
Expand Down

0 comments on commit d5edf22

Please sign in to comment.