MAG-Capstone / Capstone

0 stars 0 forks source link

Database #21

Open GaddPetrivoki opened 1 month ago

GaddPetrivoki commented 3 weeks ago

Created a database in postgress and nodejs.

GaddPetrivoki commented 3 weeks ago

Nodejs handles daos controllers

axelperez2 commented 3 weeks ago

Codigos implementados en PostgresSQL (pgAdmin) para las diferentes tablas

-- 1. Crea la tabla de Estaciones CREATE TABLE stations ( station_id SERIAL PRIMARY KEY, location VARCHAR(100) NOT NULL, available_umbrellas INT DEFAULT 0, status VARCHAR(20) DEFAULT 'active' );

-- 2. Crea la tabla de Sombrillas CREATE TABLE umbrellas ( umbrella_id SERIAL PRIMARY KEY, station_id INT, status VARCHAR(20) DEFAULT 'available', last_charge_time TIMESTAMP, FOREIGN KEY (station_id) REFERENCES stations(station_id) );

-- 3. crea la tabla de Usuarios CREATE TABLE users ( user_id SERIAL PRIMARY KEY, university_id VARCHAR(50) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(100) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, umbrella_rented INT, FOREIGN KEY (umbrella_rented) REFERENCES umbrellas(umbrella_id) );

-- 4. Crea la tabla de Reportes CREATE TABLE reports ( report_id SERIAL PRIMARY KEY, umbrella_id INT, description TEXT, report_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, status VARCHAR(20) DEFAULT 'pending', FOREIGN KEY (umbrella_id) REFERENCES umbrellas(umbrella_id) );

-- 5. Crea la tabla de Códigos QR CREATE TABLE qr_codes ( qr_id SERIAL PRIMARY KEY, qr_code TEXT, expiration_time TIMESTAMP, umbrella_id INT, station_id INT, user_id INT, action VARCHAR(10), -- rent or return FOREIGN KEY (umbrella_id) REFERENCES umbrellas(umbrella_id), FOREIGN KEY (station_id) REFERENCES stations(station_id), FOREIGN KEY (user_id) REFERENCES users(user_id) );

-- 6. Crea la tabla de Logs de Alquiler y Devolución CREATE TABLE rental_logs ( log_id SERIAL PRIMARY KEY, user_id INT, umbrella_id INT, station_id INT, rental_time TIMESTAMP, return_time TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(user_id), FOREIGN KEY (umbrella_id) REFERENCES umbrellas(umbrella_id), FOREIGN KEY (station_id) REFERENCES stations(station_id) );