summaryrefslogtreecommitdiff
path: root/script.sql
diff options
context:
space:
mode:
authorMateus Cruz <mateuscolvr@gmail.com>2024-02-05 03:31:35 -0300
committerMateus Cruz <mateuscolvr@gmail.com>2024-02-05 03:31:35 -0300
commit5a2f5bf9a12b270e15757df48afeb1c1db5b34b3 (patch)
tree2f1797364d78d935b4eb79269fd6b100fa77ec21 /script.sql
parentf0142aa1c3b4d7c2fd0b70c9e62c1ec033e445c2 (diff)
add db queries
Diffstat (limited to 'script.sql')
-rw-r--r--script.sql12
1 files changed, 7 insertions, 5 deletions
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;
+$$