From 5a2f5bf9a12b270e15757df48afeb1c1db5b34b3 Mon Sep 17 00:00:00 2001 From: Mateus Cruz Date: Mon, 5 Feb 2024 03:31:35 -0300 Subject: add db queries --- script.sql | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'script.sql') diff --git a/script.sql b/script.sql index f5da315..25e5ffe 100644 --- a/script.sql +++ b/script.sql @@ -1,14 +1,14 @@ CREATE TABLE clients ( id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, - limit INTEGER NOT NULL + mov_limit INTEGER NOT NULL ); -CREATE TYPE transaction_type AS ENUM ('c', 'd'); +CREATE TYPE transaction_type AS ENUM ('credit', 'debit'); CREATE TABLE transactions ( id SERIAL PRIMARY KEY, - client_id REFERENCES clients, + client_id INTEGER REFERENCES clients, value INTEGER NOT NULL, type transaction_type NOT NULL, description VARCHAR(10) NOT NULL, @@ -17,12 +17,13 @@ CREATE TABLE transactions ( CREATE TABLE balances ( id SERIAL PRIMARY KEY, - client_id REFERENCES clients, + client_id INTEGER REFERENCES clients, value INTEGER NOT NULL ); +DO $$ BEGIN - INSERT INTO clients (name, limit) + INSERT INTO clients (name, mov_limit) VALUES ('naruto', 1000 * 100), ('mob', 800 * 100), @@ -31,3 +32,4 @@ BEGIN INSERT INTO balances (client_id, value) SELECT id, 0 FROM clients; END; +$$ -- cgit v1.2.3