20210306164523_account_ids_to_timestamp_ids.rb 582 B

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