-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmigrate.py
64 lines (51 loc) · 1.85 KB
/
migrate.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
56
57
58
59
60
61
62
63
64
import psycopg2
import os
from passlib.hash import sha256_crypt
from app.db_config import conn
curr = conn.cursor()
password = sha256_crypt.hash("Cate@95#")
def create_tables():
queries = tables()
for query in queries:
curr.execute(query)
curr.execute("INSERT INTO users( firstname, lastname, othernames,\
email, phonenumber, username, password, isAdmin)\
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
("cate", "chep", "kimetto", "root@gmail.com", "0725277948",
"catechep", password, True))
curr.execute("SELECT * FROM users")
conn.commit()
print("Users and Incidents tables created!")
def destroy_tables():
pass
def tables():
drop_users = """DROP TABLE IF EXISTS users"""
drop_incidents = """DROP TABLE IF EXISTS incidents"""
users = """CREATE TABLE users(
user_id serial PRIMARY KEY NOT NULL,
firstname VARCHAR(50) NOT NULL,
lastname VARCHAR(50) NOT NULL,
othernames VARCHAR(50) NULL,
username VARCHAR(20) NOT NULL,
email VARCHAR(40) NOT NULL,
phonenumber VARCHAR(40) NOT NULL,
date_created timestamp with time zone DEFAULT('now'::text)::date
NOT NULL,
password VARCHAR NOT NULL,
registered timestamp with time zone DEFAULT('now'::text)::date
NOT NULL,
isAdmin BOOLEAN NOT NULL
)"""
incidents = """CREATE TABLE incidents(
id serial PRIMARY KEY NOT NULL,
createdOn timestamp with time zone DEFAULT('now'::text)::date NOT NULL,
createdBy int NOT NULL,
incidentType VARCHAR(50) NOT NULL,
location VARCHAR(10) NOT NULL,
status VARCHAR(10) NOT NULL,
comment VARCHAR(100) NOT NULL,
image VARCHAR(300)[] NULL
)"""
queries = [drop_users, drop_incidents, users, incidents]
return queries
create_tables()