diff options
author | Mateus Cruz <mateuscolvr@gmail.com> | 2024-02-07 23:51:09 -0300 |
---|---|---|
committer | Mateus Cruz <mateuscolvr@gmail.com> | 2024-02-08 01:04:35 -0300 |
commit | 43977b16f27784233c166ff8fc42cf8ed5c891ed (patch) | |
tree | 56fd1b8dcb75db71f1b4b00e660e412d4090086b /init.sql | |
parent | bdd9f8780b76ad7cd806ce71b55c0882db56549b (diff) |
chore: adjust resources
Diffstat (limited to 'init.sql')
-rw-r--r-- | init.sql | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/init.sql b/init.sql new file mode 100644 index 0000000..a02895a --- /dev/null +++ b/init.sql @@ -0,0 +1,40 @@ +CREATE TABLE clients ( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, + mov_limit INTEGER NOT NULL +); + +CREATE TYPE transaction_type AS ENUM ('credit', 'debit'); + +CREATE TABLE transactions ( + id SERIAL PRIMARY KEY, + client_id INTEGER REFERENCES clients, + value INTEGER NOT NULL, + type transaction_type NOT NULL, + description VARCHAR(10) NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX idx_client_id_transactions ON transactions (client_id); + +CREATE TABLE balances ( + id SERIAL PRIMARY KEY, + client_id INTEGER REFERENCES clients, + value INTEGER NOT NULL +); + +CREATE INDEX idx_client_id_balances ON balances (client_id); + +DO $$ +BEGIN + INSERT INTO clients (name, mov_limit) + VALUES + ('naruto', 100000), + ('mob', 80000), + ('jojo', 1000000), + ('hellboy', 10000000), + ('ultramega', 500000); + INSERT INTO balances (client_id, value) + SELECT id, 0 FROM clients; +END; +$$ |