20200622213645_media_attachment_ids_to_timestamp_ids.rb 662 B

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