changed database scheme

This commit is contained in:
2025-08-19 14:38:27 +02:00
parent 8fbcd069b5
commit ef78523ccf

View File

@@ -1,32 +1,47 @@
CREATE TABLE users ( -- All necessary tables for the borrowing system
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL UNIQUE, -- IMPORTANT: You need mySQL version 8.0 or newer!
password VARCHAR(255) NOT NULL
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL,
`password` varchar(255) NOT NULL,
`role` int DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
); );
CREATE TABLE items ( CREATE TABLE `loans` (
id INT AUTO_INCREMENT PRIMARY KEY, `id` int NOT NULL AUTO_INCREMENT,
item_name VARCHAR(255) NOT NULL UNIQUE, `username` varchar(100) NOT NULL,
can_borrow_role VARCHAR(255) NOT NULL `loan_code` int NOT NULL,
`start_date` timestamp NOT NULL,
`end_date` timestamp NOT NULL,
`returned_date` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`loaned_items_id` json NOT NULL DEFAULT ('[]'),
PRIMARY KEY (`id`),
UNIQUE KEY `loan_code` (`loan_code`)
); );
CREATE TABLE loans ( CREATE TABLE `items` (
id INT AUTO_INCREMENT PRIMARY KEY, `id` int NOT NULL AUTO_INCREMENT,
username VARCHAR(100) NOT NULL, `item_name` varchar(255) NOT NULL,
loan_code INT(6) NOT NULL UNIQUE, `can_borrow_role` varchar(255) NOT NULL,
start_date TIMESTAMP NOT NULL, `inSafe` tinyint(1) NOT NULL DEFAULT '1',
end_date TIMESTAMP NOT NULL, PRIMARY KEY (`id`),
returned_date TIMESTAMP, UNIQUE KEY `item_name` (`item_name`)
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
CREATE TABLE lockers ( CREATE TABLE `lockers` (
id INT AUTO_INCREMENT PRIMARY KEY, `id` int NOT NULL AUTO_INCREMENT,
item VARCHAR(255) NOT NULL UNIQUE, `item` varchar(255) NOT NULL,
locker_number INT NOT NULL UNIQUE `locker_number` int NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `item` (`item`),
UNIQUE KEY `locker_number` (`locker_number`)
); );
-- Mock data -- Mock data
-- Users -- Users