Skip to content

Commit

Permalink
alerts-server: Add currency_name to currencies table
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed May 14, 2018
1 parent ef60ef7 commit 5ebf2f0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions alerts-server/conf/evolutions/default/7.sql
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;

0 comments on commit 5ebf2f0

Please sign in to comment.