add sql model and php basice

This commit is contained in:
0nano
2022-11-19 23:29:44 +01:00
parent d29d8ad7c8
commit c4e04787da
5 changed files with 91 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.vscode

28
resources/config.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
/**
* PHP version 8.1.11
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Basice parameters to connect to the database
const DB_SERVER = '127.0.0.1';
const DB_PORT = '5432';
const DB_NAME = 'fermentardoise';
const DB_USER = 'postgres';
const DB_PASSWORD = '';
// Some constants to use in the application
const ACCESS_TOKEN_NAME = 'fermentardoise_session';
/*
Creating constants for heavily used paths makes things a lot easier.
ex. require_once(LIBRARY_PATH . "exceptions.php")
*/
defined("LIBRARY_PATH")
or define("LIBRARY_PATH", realpath(dirname(__FILE__) . '/library'));
?>

View File

@@ -0,0 +1,8 @@
<?php
/**
* This exception is thrown when the authentication failed.
*/
class AuthenticationException extends Exception {}
?>

View File

@@ -0,0 +1,13 @@
<?php
/**
* Redirects to a new page
*
* @param string $page The requested page.
*/
function redirect(string $page): void{
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: //$host$uri/$page");
exit;
}
?>

41
sql/model.sql Normal file
View File

@@ -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
);