Restore unique index on board_publications.key (#2568)
* Restore unique index on board_publications.key
The account_id rollout (fe6df7085) replaced the unique index on
board_publications.key with a non-unique composite (account_id, key)
index. This was unintentional — other tables in the same migration
preserved uniqueness (account_join_codes, tags) but this one did not.
Without global uniqueness on key, a crafted data import can insert a
duplicate publication key via insert_all! (which bypasses model
validations). Since find_by_published_key queries globally without
account scoping, this enables public board URL hijacking after the
legitimate owner unpublishes.
Restore the original unique index on key and keep a plain account_id
index for account-scoped queries.
* Reorder index operations: add unique index before dropping composite
On MySQL, DDL is non-transactional. If the unique index creation
fails (e.g. duplicate keys exist), the previous ordering would leave
the composite index already dropped. Adding the unique index first
means a failure leaves the database unchanged.
* Add schema dumps for both SQLite and MySQL
Dump both schema files after running the migration against each
adapter to keep the PR complete for CI.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
class RestoreUniqueIndexOnBoardPublicationKey < ActiveRecord::Migration[8.2]
|
||||
def change
|
||||
add_index :board_publications, :key, unique: true
|
||||
add_index :board_publications, :account_id
|
||||
remove_index :board_publications, [:account_id, :key]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user