diff options
author | Mateus Cruz <mateuscolvr@gmail.com> | 2024-02-04 23:10:30 -0300 |
---|---|---|
committer | Mateus Cruz <mateuscolvr@gmail.com> | 2024-02-04 23:10:57 -0300 |
commit | f3ac99a84497868aded8ee7ec2822d1b12960fd7 (patch) | |
tree | a870e9bb38259e0641c282b2ba524ac9abe85346 /script.sql |
initial commit
Diffstat (limited to 'script.sql')
-rw-r--r-- | script.sql | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/script.sql b/script.sql new file mode 100644 index 0000000..f5da315 --- /dev/null +++ b/script.sql @@ -0,0 +1,33 @@ +CREATE TABLE clients ( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, + limit INTEGER NOT NULL +); + +CREATE TYPE transaction_type AS ENUM ('c', 'd'); + +CREATE TABLE transactions ( + id SERIAL PRIMARY KEY, + client_id REFERENCES clients, + value INTEGER NOT NULL, + type transaction_type NOT NULL, + description VARCHAR(10) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +CREATE TABLE balances ( + id SERIAL PRIMARY KEY, + client_id REFERENCES clients, + value INTEGER NOT NULL +); + +BEGIN + INSERT INTO clients (name, limit) + VALUES + ('naruto', 1000 * 100), + ('mob', 800 * 100), + ('jojo', 10000 * 100), + ('hellboy', 5000 * 100); + INSERT INTO balances (client_id, value) + SELECT id, 0 FROM clients; +END; |