From c4e04787dab25dec220f8905915b6d5489ab9cb9 Mon Sep 17 00:00:00 2001 From: 0nano <35236525+0nano@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:29:44 +0100 Subject: [PATCH] add sql model and php basice --- .gitignore | 1 + resources/config.php | 28 ++++++++++++++++++++++ resources/library/exceptions.php | 8 +++++++ resources/library/redirect.php | 13 ++++++++++ sql/model.sql | 41 ++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 .gitignore create mode 100644 resources/config.php create mode 100644 resources/library/exceptions.php create mode 100644 resources/library/redirect.php create mode 100644 sql/model.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..722d5e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode diff --git a/resources/config.php b/resources/config.php new file mode 100644 index 0000000..92bdb53 --- /dev/null +++ b/resources/config.php @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/resources/library/exceptions.php b/resources/library/exceptions.php new file mode 100644 index 0000000..17cf538 --- /dev/null +++ b/resources/library/exceptions.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/resources/library/redirect.php b/resources/library/redirect.php new file mode 100644 index 0000000..e0acd04 --- /dev/null +++ b/resources/library/redirect.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/sql/model.sql b/sql/model.sql new file mode 100644 index 0000000..ab44c3e --- /dev/null +++ b/sql/model.sql @@ -0,0 +1,41 @@ +/************************************************************************ +Creation Date: 2022-11-19 +Description: Creates the database tables and relations. +Usage: psql -U postgres -d fermentardoise -a -f model.sql + https://stackoverflow.com/a/23992045/12619942 +************************************************************************/ + +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS clients CASCADE; +DROP TABLE IF EXISTS payments CASCADE; + +-- Table users +CREATE TABLE users ( + id SERIAL PRIMARY KEY, + login VARCHAR(255) NOT NULL, + password_hash VARCHAR(50) NOT NULL +); + +-- Table clients +CREATE TABLE clients ( + id SERIAL PRIMARY KEY, + lastname VARCHAR(64) NOT NULL, + firstname VARCHAR(64) NOT NULL +); + +-- Table payments +CREATE TABLE payments ( + id SERIAL PRIMARY KEY, + amount FLOAT NOT NULL, + comment TEXT, + date_time TIMESTAMP NOT NULL, + client_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + + FOREIGN KEY (client_id) REFERENCES clients(id) + ON UPDATE CASCADE + ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES users(id) + ON UPDATE CASCADE + ON DELETE CASCADE +); \ No newline at end of file