source: backend/src/main/resources/db/migration/V1.2__Create_Users_Table.sql

Last change on this file was cdcff72, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance and fix bugs

  • Property mode set to 100644
File size: 1.5 KB
Line 
1-- Create users table
2CREATE TABLE IF NOT EXISTS users (
3 user_id SERIAL PRIMARY KEY,
4 username VARCHAR(255) NOT NULL UNIQUE,
5 password VARCHAR(255) NOT NULL,
6 role VARCHAR(50) NOT NULL,
7 first_name VARCHAR(100),
8 last_name VARCHAR(100),
9 patient_id BIGINT,
10 doctor_id BIGINT,
11 is_active BOOLEAN DEFAULT true,
12 FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
13 FOREIGN KEY (doctor_id) REFERENCES doctors(doctor_id)
14);
15
16-- Create index for username lookup
17CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
18
19-- Insert admin user (password: admin123)
20INSERT INTO users (username, password, role, first_name, last_name, is_active)
21VALUES ('admin', 'admin123', 'ADMIN', 'System', 'Administrator', true)
22ON CONFLICT (username) DO NOTHING;
23
24-- Insert sample patient users (password: password123 for all)
25-- These will be linked to existing patients by EMBG
26INSERT INTO users (username, password, role, first_name, last_name, patient_id, is_active)
27SELECT p.embg, 'password123', 'PATIENT', p.first_name, p.last_name, p.patient_id, true
28FROM patients p
29WHERE NOT EXISTS (
30 SELECT 1 FROM users u WHERE u.username = p.embg
31)
32LIMIT 39;
33
34-- Insert doctor users (password: doctor123 for all)
35-- These will be linked to existing doctors by email
36INSERT INTO users (username, password, role, first_name, last_name, doctor_id, is_active)
37SELECT d.email_address, 'doctor123', 'DOCTOR', d.first_name, d.last_name, d.doctor_id, true
38FROM doctors d
39WHERE NOT EXISTS (
40 SELECT 1 FROM users u WHERE u.username = d.email_address
41);
Note: See TracBrowser for help on using the repository browser.