Created
January 17, 2019 01:45
-
-
Save vicly/fc4fb005285f6fcd77950017808baf41 to your computer and use it in GitHub Desktop.
[SQL example] #SQL
This file contains hidden or 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
| CREATE TABLE product ( | |
| id UUID PRIMARY KEY, | |
| name VARCHAR(64) NOT NULL, | |
| -- max 999999.9999 | |
| price_amount NUMERIC(10, 4) NOT NULL CHECK (price_amount >= 0), | |
| price_currency VARCHAR(10) NOT NULL, | |
| created_at TIMESTAMP WITH TIME ZONE NOT NULL, | |
| updated_at TIMESTAMP WITH TIME ZONE NULL | |
| ); | |
| CREATE TABLE product_price ( | |
| product_id VARCHAR(64) REFERENCES product, | |
| money_currency VARCHAR(10) NOT NULL, | |
| money_amount NUMERIC(10, 4) NOT NULL CHECK (money_amount >= 0), | |
| UNIQUE(product_id, money_currency) | |
| ); | |
| CREATE INDEX idx_payment_by_user_priceamount ON payment (user_id, price_amount); | |
| ALTER TABLE payment ADD COLUMN payment_method VARCHAR(128); | |
| ALTER TABLE payment DROP COLUMN IF EXISTS payment_method; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment