-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcreate_tables.py
50 lines (32 loc) · 1020 Bytes
/
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
import os
from enum import Enum
from typing import Optional
from sqlalchemy import Integer, MetaData, create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class Status(Enum):
DRAFT = "draft"
IN_PROGRESS = "in progress"
COMPLETE = "complete"
meta = MetaData()
class Task(Base):
__tablename__ = "task"
metadata = meta
id = mapped_column(Integer, primary_key=True)
description: Mapped[str]
status: Mapped[Status]
class User(Base):
__tablename__ = "profile"
metadata = meta
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str]
hashed_password: Mapped[str]
email: Mapped[Optional[str]]
full_name: Mapped[Optional[str]]
disabled: Mapped[Optional[bool]]
uri = os.getenv("DATABASE_URL") # or other relevant config var
if uri.startswith("postgres://"):
uri = uri.replace("postgres://", "postgresql://", 1)
engine = create_engine(uri)
meta.create_all(engine)