-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tables.py
97 lines (95 loc) · 2.94 KB
/
create_tables.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
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
import psycopg2
from config import load_config, load_config2
def create_table_chats():
commands = (
"""
CREATE TABLE IF NOT EXISTS chats (
user_id UUID NOT NULL,
companion UUID NOT NULL,
unread bigint NOT NULL,
date TIMESTAMP NOT NULL)
""",
)
try:
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
for command in commands:
cur.execute(command)
except (psycopg2.DatabaseError, Exception) as error:
print(error)
def create_table_posts():
commands = (
"""
CREATE TABLE IF NOT EXISTS posts (
author_id UUID NOT NULL,
posts VARCHAR(2550) NOT NULL,
date TIMESTAMP NOT NULL)
""",
)
try:
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
for command in commands:
cur.execute(command)
except (psycopg2.DatabaseError, Exception) as error:
print(error)
def create_table_dialogs():
commands = (
"""
CREATE TABLE IF NOT EXISTS dialogs (
id bigint NOT NULL PRIMARY KEY,
sender UUID NOT NULL,
recipient UUID NOT NULL,
text VARCHAR(2550) NOT NULL,
date TIMESTAMP NOT NULL)
""",
)
try:
config = load_config2()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
for command in commands:
cur.execute(command)
except (psycopg2.DatabaseError, Exception) as error:
print(error)
def create_table_friends():
commands = (
"""
CREATE TABLE IF NOT EXISTS friends (
friend_id_first UUID NOT NULL,
friend_id_second UUID NOT NULL,
date TIMESTAMP NOT NULL,
PRIMARY KEY(friend_id_first, friend_id_second))
""",
)
try:
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
for command in commands:
cur.execute(command)
except (psycopg2.DatabaseError, Exception) as error:
print(error)
def create_table_users():
commands = (
"""
CREATE TABLE IF NOT EXISTS users (
user_id UUID PRIMARY KEY NOT NULL ,
first_name VARCHAR(255) NOT NULL,
second_name VARCHAR(255) NOT NULL,
birthdate DATE NOT NULL,
biography VARCHAR(255),
city VARCHAR(255),
pass_hash VARCHAR(255) NOT NULL )
""",
)
try:
config = load_config()
with psycopg2.connect(**config) as conn:
with conn.cursor() as cur:
for command in commands:
cur.execute(command)
except (psycopg2.DatabaseError, Exception) as error:
print(error)