1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Stronger security unique index and data migration

Note to self hosters:

If you started self hosting prior to this commit, you may have duplicate securities in your database.

This is usually not a problem, but if you'd like to clean things up, you can run the data migration
by opening a terminal on the machine you're hosting with and running:

```sh
rake data_migration:migrate_duplicate_securities
```
This commit is contained in:
Zach Gollwitzer 2025-05-22 15:15:07 -04:00
parent e4ee06c9f6
commit fe24117c50
3 changed files with 74 additions and 2 deletions

View file

@ -0,0 +1,13 @@
class StrongerUniquenessConstraintOnSecurities < ActiveRecord::Migration[7.2]
def change
remove_index :securities, [ :ticker, :exchange_operating_mic ], unique: true
# Matches our ActiveRecord validation:
# - uppercase ticker
# - either exchange_operating_mic or empty string (unique index doesn't work with NULL values)
add_index :securities,
"UPPER(ticker), COALESCE(UPPER(exchange_operating_mic), '')",
unique: true,
name: "index_securities_on_ticker_and_exchange_operating_mic_unique"
end
end