-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
32 lines (20 loc) · 846 Bytes
/
models.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
from sqlalchemy import Column, String, Integer, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from config import DATABASE_USER, DATABASE_PASS, DATABASE_HOST, DATABASE_NAME
db_string = f'postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASS}@{DATABASE_HOST}/{DATABASE_NAME}'
db = create_engine(db_string)
base = declarative_base()
class Schedule(base):
__tablename__ = 'schedule'
id = Column("schedule_weekday_id", Integer, primary_key=True)
name = Column(String)
weekday = Column(Integer)
class ErrorSchedule(base):
__tablename__ = 'error_schedule'
id = Column("error_schedule_id", Integer, primary_key=True)
error_text = Column(String)
weekday = Column(Integer)
Session = sessionmaker(db)
session = Session()
base.metadata.create_all(db)