-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_setup.sql
More file actions
40 lines (38 loc) · 1.52 KB
/
database_setup.sql
File metadata and controls
40 lines (38 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Users Table (Existing + Updates)
CREATE TABLE IF NOT EXISTS users (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
company_id INT(11) UNSIGNED,
login_id VARCHAR(50) NOT NULL UNIQUE,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
phone VARCHAR(20) NOT NULL,
password VARCHAR(255) NOT NULL,
role ENUM('admin', 'employee', 'pending') DEFAULT 'pending',
salary DECIMAL(10,2) DEFAULT 0.00,
designation VARCHAR(100) DEFAULT 'Employee',
joining_date DATE DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
-- FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE -- Assume companies table exists or remove if standalone
);
-- Attendance Table
CREATE TABLE IF NOT EXISTS attendance (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT(11) UNSIGNED NOT NULL,
date DATE NOT NULL,
check_in_time TIME,
check_out_time TIME,
status ENUM('Present', 'Absent', 'Half-day', 'Leave') DEFAULT 'Absent',
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY unique_attendance (user_id, date)
);
-- Leave Requests Table
CREATE TABLE IF NOT EXISTS leave_requests (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT(11) UNSIGNED NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
reason TEXT,
status ENUM('Pending', 'Approved', 'Rejected') DEFAULT 'Pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);