-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path55eae8bd7f1e_initial_schema.py
92 lines (79 loc) · 2.97 KB
/
55eae8bd7f1e_initial_schema.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
"""initial schema
Revision ID: 55eae8bd7f1e
Revises:
Create Date: 2019-10-09 20:59:21.799403
"""
from datetime import datetime, timezone
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "55eae8bd7f1e"
down_revision = None
branch_labels = None
depends_on = None
status_table = sa.table(
"status",
sa.column("id", sa.Integer),
sa.column("name", sa.String),
sa.column("created_at", sa.DateTime),
sa.column("updated_at", sa.DateTime),
)
def upgrade():
bind = op.get_bind()
op.create_table(
"status",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_status_created_at"), "status", ["created_at"], unique=False
)
op.create_index(op.f("ix_status_id"), "status", ["id"], unique=False)
op.create_index(
op.f("ix_status_updated_at"), "status", ["updated_at"], unique=False
)
op.create_table(
"events",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("book_id", sa.String(), nullable=True),
sa.Column("status_id", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["status_id"],
["status.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_events_book_id"), "events", ["book_id"], unique=False
)
op.create_index(
op.f("ix_events_created_at"), "events", ["created_at"], unique=False
)
op.create_index(op.f("ix_events_id"), "events", ["id"], unique=False)
# ### end Alembic commands ###
utcnow = datetime.now(timezone.utc)
status_data = [
{"name": "queued", "created_at": utcnow, "updated_at": utcnow},
{"name": "assigned", "created_at": utcnow, "updated_at": utcnow},
{"name": "processing", "created_at": utcnow, "updated_at": utcnow},
{"name": "failed", "created_at": utcnow, "updated_at": utcnow},
{"name": "completed", "created_at": utcnow, "updated_at": utcnow},
]
insert = status_table.insert().values(status_data)
bind.execute(insert)
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_events_id"), table_name="events")
op.drop_index(op.f("ix_events_created_at"), table_name="events")
op.drop_index(op.f("ix_events_book_id"), table_name="events")
op.drop_table("events")
op.drop_index(op.f("ix_status_updated_at"), table_name="status")
op.drop_index(op.f("ix_status_id"), table_name="status")
op.drop_index(op.f("ix_status_created_at"), table_name="status")
op.drop_table("status")
# ### end Alembic commands ###