20210306164523_account_ids_to_timestamp_ids.rb 613 B

12345678910111213141516171819
  1. # frozen_string_literal: true
  2. class AccountIdsToTimestampIds < ActiveRecord::Migration[5.2]
  3. def up
  4. # Set up the accounts.id column to use our timestamp-based IDs.
  5. safety_assured do
  6. execute("ALTER TABLE accounts ALTER COLUMN id SET DEFAULT timestamp_id('accounts')")
  7. end
  8. # Make sure we have a sequence to use.
  9. Mastodon::Snowflake.ensure_id_sequences_exist
  10. end
  11. def down
  12. execute('LOCK accounts')
  13. execute("SELECT setval('accounts_id_seq', (SELECT MAX(id) FROM accounts))")
  14. execute("ALTER TABLE accounts ALTER COLUMN id SET DEFAULT nextval('accounts_id_seq')")
  15. end
  16. end