forked from madisvain/vatcomply
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
48 lines (42 loc) · 1.82 KB
/
db.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
from enum import unique
import databases
import pendulum
import sqlalchemy
from settings import DATABASE_URL, TEST_DATABASE_URL, TESTING
metadata = sqlalchemy.MetaData()
Countries = sqlalchemy.Table(
"countries",
metadata,
sqlalchemy.Column("name", sqlalchemy.String, nullable=False),
sqlalchemy.Column("iso2", sqlalchemy.String, nullable=False, unique=True),
sqlalchemy.Column("iso3", sqlalchemy.String, nullable=False),
sqlalchemy.Column("numeric_code", sqlalchemy.Integer),
sqlalchemy.Column("phone_code", sqlalchemy.Integer),
sqlalchemy.Column("capital", sqlalchemy.String, nullable=False),
sqlalchemy.Column("currency", sqlalchemy.String, nullable=False),
sqlalchemy.Column("tld", sqlalchemy.String, nullable=False),
sqlalchemy.Column("region", sqlalchemy.String, nullable=False),
sqlalchemy.Column("subregion", sqlalchemy.String, nullable=False),
sqlalchemy.Column("latitude", sqlalchemy.String, nullable=False),
sqlalchemy.Column("longitude", sqlalchemy.String, nullable=False),
sqlalchemy.Column("emoji", sqlalchemy.String, nullable=False),
)
Rates = sqlalchemy.Table(
"rates",
metadata,
sqlalchemy.Column("date", sqlalchemy.Date, primary_key=True),
sqlalchemy.Column("rates", sqlalchemy.JSON),
)
Users = sqlalchemy.Table(
"users",
metadata,
sqlalchemy.Column("pk", sqlalchemy.Integer, primary_key=True),
sqlalchemy.Column("email", sqlalchemy.String, nullable=False, unique=True),
sqlalchemy.Column("password", sqlalchemy.String, nullable=False),
sqlalchemy.Column("created_at", sqlalchemy.DateTime, default=sqlalchemy.func.now(), nullable=False),
sqlalchemy.Column("last_login", sqlalchemy.DateTime),
)
if TESTING:
database = databases.Database(TEST_DATABASE_URL, force_rollback=True)
else:
database = databases.Database(DATABASE_URL)