diff --git a/db/migrate/20250425134308_quote_ids_to_timestamp_ids.rb b/db/migrate/20250425134308_quote_ids_to_timestamp_ids.rb new file mode 100644 index 0000000000..0be0aaecd2 --- /dev/null +++ b/db/migrate/20250425134308_quote_ids_to_timestamp_ids.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class QuoteIdsToTimestampIds < ActiveRecord::Migration[8.0] + def up + # Set up the media_attachments.id column to use our timestamp-based IDs. + safety_assured do + execute("ALTER TABLE quotes ALTER COLUMN id SET DEFAULT timestamp_id('quotes')") + end + + # Make sure we have a sequence to use. + Mastodon::Snowflake.ensure_id_sequences_exist + end + + def down + execute('LOCK quotes') + execute("SELECT setval('quotes_id_seq', (SELECT MAX(id) FROM quotes))") + execute("ALTER TABLE quotes ALTER COLUMN id SET DEFAULT nextval('quotes_id_seq')") + end +end diff --git a/db/schema.rb b/db/schema.rb index 9c3ecd4d2d..ce3d87d00c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_04_23_224935) do +ActiveRecord::Schema[8.0].define(version: 2025_04_25_134308) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -1180,7 +1180,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_23_224935) do t.string "url" end - create_table "quotes", force: :cascade do |t| + create_table "quotes", id: :bigint, default: -> { "timestamp_id('quotes'::text)" }, force: :cascade do |t| t.bigint "account_id", null: false t.bigint "status_id", null: false t.bigint "quoted_status_id" diff --git a/spec/config/initializers/rack/attack_spec.rb b/spec/config/initializers/rack/attack_spec.rb index 23c65cff87..b13efd1e06 100644 --- a/spec/config/initializers/rack/attack_spec.rb +++ b/spec/config/initializers/rack/attack_spec.rb @@ -41,7 +41,7 @@ RSpec.describe Rack::Attack, type: :request do end shared_examples 'throttled endpoint' do - include_examples 'with throttled endpoint base' + it_behaves_like 'with throttled endpoint base' context 'when the number of requests is lower than the limit' do before do @@ -73,7 +73,7 @@ RSpec.describe Rack::Attack, type: :request do end shared_examples 'does not throttle endpoint' do - include_examples 'with throttled endpoint base' + it_behaves_like 'with throttled endpoint base' context 'when the number of requests is lower than the limit' do before do