-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibraryyyyyyy.sql
More file actions
219 lines (181 loc) · 6.31 KB
/
libraryyyyyyy.sql
File metadata and controls
219 lines (181 loc) · 6.31 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root@123';
create database library;
use library;
show databases;
create database library_management;
use library_management;
show TABLES;
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
full_name VARCHAR(100) NOT NULL,
role VARCHAR(20) NOT NULL,
is_approved BOOLEAN DEFAULT FALSE
);
drop table users;
USE library_management;
-- Drop the old users table
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(100),
username VARCHAR(50) UNIQUE,
password VARCHAR(100),
role VARCHAR(20),
type VARCHAR(20),
email VARCHAR(100),
phone VARCHAR(20),
is_approved BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS books (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200),
author VARCHAR(100),
isbn VARCHAR(50),
quantity INT DEFAULT 1,
available INT DEFAULT 1
);
CREATE TABLE IF NOT EXISTS issued_books (
id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT,
user_id INT,
issue_date DATE,
due_date DATE,
return_date DATE,
fine DOUBLE DEFAULT 0
);
CREATE TABLE IF NOT EXISTS notifications (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
message TEXT,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_read BOOLEAN DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS fines (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
amount DOUBLE,
paid BOOLEAN DEFAULT FALSE,
date DATE
);
USE library_management;
CREATE TABLE IF NOT EXISTS book_borrowings (
id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT,
user_id INT,
borrow_date DATE,
due_date DATE,
return_date DATE,
status VARCHAR(20) DEFAULT 'BORROWED',
fine DOUBLE DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
USE library_management;
CREATE TABLE IF NOT EXISTS settings (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
theme VARCHAR(20) DEFAULT 'Light',
notifications_enabled TINYINT(1) DEFAULT 1,
language VARCHAR(20) DEFAULT 'English',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS book_borrowings (
id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT,
user_id INT,
borrow_date DATE,
due_date DATE,
return_date DATE,
status VARCHAR(20) DEFAULT 'BORROWED',
fine DOUBLE DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS book_requests (
id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT,
user_id INT,
request_date DATE,
status VARCHAR(20) DEFAULT 'PENDING'
);
CREATE TABLE IF NOT EXISTS book_reviews (
id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT,
user_id INT,
rating INT,
review TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
USE library_management;
INSERT INTO books (title, author, isbn, quantity, available) VALUES
('The Great Gatsby', 'F. Scott Fitzgerald', '978-0743273565', 3, 3),
('To Kill a Mockingbird', 'Harper Lee', '978-0061935466', 2, 1),
('1984', 'George Orwell', '978-0451524935', 5, 0),
('Harry Potter', 'J.K. Rowling', '978-0439708180', 4, 2);
USE library_management;
UPDATE users SET password = 'vishwa@123' WHERE username = 'Vishwa_Leanrs';
ALTER TABLE users ADD COLUMN is_active TINYINT(1) DEFAULT 1;
SET SQL_SAFE_UPDATES = 0;
UPDATE users SET is_active = 1;
SET SQL_SAFE_UPDATES = 1;
SET SQL_SAFE_UPDATES = 0;
-- Fix all users
UPDATE users SET is_active = 1, is_approved = 1;
-- Check admin user exists with correct data
SELECT username, password, role, is_active, is_approved FROM users WHERE username = 'admin';
SET SQL_SAFE_UPDATES = 1;
INSERT INTO users (full_name, username, password, role, type, email, is_approved, is_active)
VALUES ('Admin', 'admin', 'admin123', 'ADMIN', 'ADMIN', 'admin@library.com', 1, 1);
USE library_management;
ALTER TABLE users ADD COLUMN type VARCHAR(20);
SET SQL_SAFE_UPDATES = 0;
UPDATE users SET type = role;
SET SQL_SAFE_UPDATES = 1;
USE library_management;
INSERT INTO users (full_name, username, password, role, type, email, is_approved, is_active)
VALUES ('Sujal Jadhav', 'sujya7781', 'sujal@123', 'STUDENT', 'STUDENT', 'sujaljadhav@gmail.com', 1, 1);
USE library_management;
ALTER TABLE books ADD COLUMN available_quantity INT DEFAULT 0;
SET SQL_SAFE_UPDATES = 0;
UPDATE books SET available_quantity = available;
SET SQL_SAFE_UPDATES = 1;
USE library_management;
ALTER TABLE books ADD COLUMN book_id INT;
SET SQL_SAFE_UPDATES = 0;
UPDATE books SET book_id = id;
SET SQL_SAFE_UPDATES = 1;
USE library_management;
ALTER TABLE book_borrowings ADD COLUMN fine_amount DOUBLE DEFAULT 0;
ALTER TABLE book_borrowings ADD COLUMN borrowing_id INT;
SET SQL_SAFE_UPDATES = 0;
UPDATE book_borrowings SET borrowing_id = id;
SET SQL_SAFE_UPDATES = 1;
USE library_management;
ALTER TABLE book_borrowings ADD COLUMN fine_paid TINYINT(1) DEFAULT 0;
ALTER TABLE book_borrowings ADD COLUMN user_id INT;
ALTER TABLE book_borrowings ADD COLUMN book_id INT;
USE library_management;
ALTER TABLE books ADD COLUMN category VARCHAR(50) DEFAULT 'General';
ALTER TABLE books ADD COLUMN shelf_location VARCHAR(50) DEFAULT 'A1';
USE library_management;
ALTER TABLE users ADD COLUMN user_id INT;
SET SQL_SAFE_UPDATES = 0;
UPDATE users SET user_id = id;
SET SQL_SAFE_UPDATES = 1;
USE library_management;
SELECT id, username, full_name, role, is_approved FROM users;
USE library_management;
INSERT INTO users (full_name, username, password, role, type, email, is_approved, is_active)
VALUES ('Aarya Jambhulkar', 'aarya123', 'aarya123', 'STUDENT', 'STUDENT', 'aaryaj@gmail.com', 1, 1);
USE library_management;
ALTER TABLE notifications ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE notifications ADD COLUMN is_read TINYINT(1) DEFAULT 0;
USE library_management;
INSERT INTO users (full_name, username, password, role, type, email, is_approved, is_active)
VALUES ('Anil Deshmukh', 'anil_123', 'anil123', 'STUDENT', 'STUDENT', 'anildesh@gmail.com', 1, 1);
USE library_management;
INSERT INTO users (full_name, username, password, role, type, email, is_approved, is_active)
VALUES ('Vishaka Deshpande', 'Vishaka_Librarian', 'vish@123', 'LIBRARIAN', 'LIBRARIAN', 'vishakadesh@gmail.com', 1, 1);