From e6468b012d5b33dd16992652da57f11dd5a6e82f Mon Sep 17 00:00:00 2001 From: Jokler Date: Sun, 21 Jun 2020 06:37:46 +0200 Subject: Initial commit --- migrations/2020-06-07-160636_create_user/down.sql | 2 ++ migrations/2020-06-07-160636_create_user/up.sql | 13 +++++++++++++ migrations/2020-06-07-161450_create_transaction/down.sql | 1 + migrations/2020-06-07-161450_create_transaction/up.sql | 12 ++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 migrations/2020-06-07-160636_create_user/down.sql create mode 100644 migrations/2020-06-07-160636_create_user/up.sql create mode 100644 migrations/2020-06-07-161450_create_transaction/down.sql create mode 100644 migrations/2020-06-07-161450_create_transaction/up.sql (limited to 'migrations') diff --git a/migrations/2020-06-07-160636_create_user/down.sql b/migrations/2020-06-07-160636_create_user/down.sql new file mode 100644 index 0000000..5808b9c --- /dev/null +++ b/migrations/2020-06-07-160636_create_user/down.sql @@ -0,0 +1,2 @@ +DROP TABLE passwords; +DROP TABLE users; diff --git a/migrations/2020-06-07-160636_create_user/up.sql b/migrations/2020-06-07-160636_create_user/up.sql new file mode 100644 index 0000000..e0ee7f4 --- /dev/null +++ b/migrations/2020-06-07-160636_create_user/up.sql @@ -0,0 +1,13 @@ +CREATE TABLE users ( + id SERIAL NOT NULL PRIMARY KEY, + power_level INTEGER NOT NULL DEFAULT 0, + name VARCHAR(32) UNIQUE NOT NULL, + created timestamp NOT NULL DEFAULT current_timestamp(), + balance bigint UNSIGNED NOT NULL +); + +CREATE TABLE passwords ( + id SERIAL NOT NULL PRIMARY KEY, + hash CHAR(120) BINARY NOT NULL, + CONSTRAINT fk_user_id FOREIGN KEY (id) REFERENCES users (id) +); diff --git a/migrations/2020-06-07-161450_create_transaction/down.sql b/migrations/2020-06-07-161450_create_transaction/down.sql new file mode 100644 index 0000000..91345dc --- /dev/null +++ b/migrations/2020-06-07-161450_create_transaction/down.sql @@ -0,0 +1 @@ +DROP TABLE transactions; diff --git a/migrations/2020-06-07-161450_create_transaction/up.sql b/migrations/2020-06-07-161450_create_transaction/up.sql new file mode 100644 index 0000000..fb81016 --- /dev/null +++ b/migrations/2020-06-07-161450_create_transaction/up.sql @@ -0,0 +1,12 @@ +CREATE TABLE transactions ( + id SERIAL NOT NULL PRIMARY KEY, + `date` timestamp NOT NULL DEFAULT current_timestamp(), + sender bigint UNSIGNED NOT NULL, + receiver bigint UNSIGNED NOT NULL, + amount bigint UNSIGNED NOT NULL, + sender_balance bigint UNSIGNED NOT NULL, + receiver_balance bigint UNSIGNED NOT NULL, + purpose varchar(70) NOT NULL, + CONSTRAINT fk_sender_id FOREIGN KEY (sender) REFERENCES users (id), + CONSTRAINT fk_receiver_id FOREIGN KEY (receiver) REFERENCES users (id) +); -- cgit v1.2.3-70-g09d2