diff options
author | ThibG <thib@sitedethib.com> | 2020-06-21 12:41:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 12:41:38 +0200 |
commit | c6904c0d3766a2ea8a81ab025c127169ecb51373 (patch) | |
tree | 864a6b63fdaa28b8bf59b42fc68131ec10230b6a /db/migrate | |
parent | 75a2b8f8153ce3a6496fcaf6eedf9f2bb7c729e6 (diff) |
Fix unique username constraint for local users not being enforced in database (#14099)
This should not be an issue in practice because of the Rails-level uniqueness check, but local accounts having a NULL domain means the uniqueness constraint did not apply to them (since no two NULL values are considered equal).
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20200620164023_add_fixed_lowercase_index_to_accounts.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/db/migrate/20200620164023_add_fixed_lowercase_index_to_accounts.rb b/db/migrate/20200620164023_add_fixed_lowercase_index_to_accounts.rb new file mode 100644 index 000000000..c5688681f --- /dev/null +++ b/db/migrate/20200620164023_add_fixed_lowercase_index_to_accounts.rb @@ -0,0 +1,15 @@ +class AddFixedLowercaseIndexToAccounts < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def up + rename_index :accounts, 'index_accounts_on_username_and_domain_lower', 'old_index_accounts_on_username_and_domain_lower' unless index_name_exists?(:accounts, 'old_index_accounts_on_username_and_domain_lower') + add_index :accounts, "lower (username), COALESCE(lower(domain), '')", name: 'index_accounts_on_username_and_domain_lower', unique: true, algorithm: :concurrently + remove_index :accounts, name: 'old_index_accounts_on_username_and_domain_lower' + end + + def down + add_index :accounts, 'lower (username), lower(domain)', name: 'old_index_accounts_on_username_and_domain_lower', unique: true, algorithm: :concurrently + remove_index :accounts, name: 'index_accounts_on_username_and_domain_lower' + rename_index :accounts, 'old_index_accounts_on_username_and_domain_lower', 'index_accounts_on_username_and_domain_lower' + end +end |