From f3ac99a84497868aded8ee7ec2822d1b12960fd7 Mon Sep 17 00:00:00 2001
From: Mateus Cruz <mateuscolvr@gmail.com>
Date: Sun, 4 Feb 2024 23:10:30 -0300
Subject: initial commit

---
 script.sql | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 script.sql

(limited to 'script.sql')

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;
-- 
cgit v1.2.3

