20200622213645_media_attachment_ids_to_timestamp_ids.rb 693 B

12345678910111213141516171819
  1. # frozen_string_literal: true
  2. class MediaAttachmentIdsToTimestampIds < ActiveRecord::Migration[5.2]
  3. def up
  4. # Set up the media_attachments.id column to use our timestamp-based IDs.
  5. safety_assured do
  6. execute("ALTER TABLE media_attachments ALTER COLUMN id SET DEFAULT timestamp_id('media_attachments')")
  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 media_attachments')
  13. execute("SELECT setval('media_attachments_id_seq', (SELECT MAX(id) FROM media_attachments))")
  14. execute("ALTER TABLE media_attachments ALTER COLUMN id SET DEFAULT nextval('media_attachments_id_seq')")
  15. end
  16. end