-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alerts-server: Add currency_name to currencies table
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- In order to support coinmarketcap, we need to store the currency name | ||
-- to differentiate repeated currencies. | ||
-- | ||
-- while the new column currency_name could be nullable, that have conflicts with | ||
-- the unique constraint because PostgreSQL doesn't consider null values as equal | ||
-- (at least when working with unique constraint), setting the empty string instead | ||
-- give us the expected effect. | ||
|
||
# --- !Ups | ||
|
||
-- add the new column | ||
ALTER TABLE currencies | ||
ADD COLUMN currency_name CITEXT NOT NULL DEFAULT ''; | ||
|
||
-- update unique constraint to include the name | ||
ALTER TABLE currencies | ||
DROP CONSTRAINT currencies_unique; | ||
|
||
ALTER TABLE currencies | ||
ADD CONSTRAINT currencies_unique UNIQUE (exchange, market, currency, currency_name); | ||
|
||
# --- !Downs | ||
|
||
-- rollback unique constraint | ||
ALTER TABLE currencies | ||
DROP CONSTRAINT currencies_unique; | ||
|
||
ALTER TABLE currencies | ||
ADD CONSTRAINT currencies_unique UNIQUE (exchange, market, currency); | ||
|
||
|
||
-- drop the name column | ||
ALTER TABLE currencies | ||
DROP COLUMN currency_name; |