-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCreateDatebase.py
55 lines (51 loc) · 1.53 KB
/
CreateDatebase.py
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
import mysql.connector as DbConnector
from time import sleep
CreateUsersTable = '''
CREATE TABLE users(
Id INT PRIMARY KEY AUTO_INCREMENT,
UserName VARCHAR(15) NOT NULL,
Password VARCHAR(20) NOT NULL DEFAULT "e10adc3949ba59abbe56e057f20f883e",
IsAdmin varchar(1) NOT NULL,
ImageDirectory VARCHAR(50) NOT NULL,
CreatedOn TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)
'''
CreateUsersAttendanceTable = '''
CREATE TABLE usersattendance(
Id INT PRIMARY KEY AUTO_INCREMENT,
userId INT NOT NULL,
InTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
OutTime TIMESTAMP,
FOREIGN KEY (userId) REFERENCES users(Id)
)
'''
CreateLastTrainedDateTimeTable = '''
CREATE TABLE lasttrained(
lasttrainedat DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)
'''
InsertDefaultLastTrainedDateTime = '''
INSERT INTO lasttrained() values()
'''
InsertAdminUsers = '''
INSERT INTO
users(UserName,IsAdmin,ImageDirectory,CreatedOn)
VALUES('admin','Y','Images/Admin',CURRENT_TIMESTAMP)
'''
conn = DbConnector.connect(host="localhost", user="root", password="mydatabase123!")
try:
cur = conn.cursor()
cur.execute('DROP DATABASE IF EXISTS attendancemanagementsystem')
cur.execute('CREATE DATABASE attendancemanagementsystem')
cur.execute('USE attendancemanagementsystem')
cur.execute(CreateUsersTable)
cur.execute(CreateUsersAttendanceTable)
cur.execute(CreateLastTrainedDateTimeTable)
cur.execute(InsertDefaultLastTrainedDateTime)
sleep(2)
cur.execute(InsertAdminUsers)
except DbConnector.Error as e:
print(e)
finally:
conn.commit()
conn.close()