-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path001_initial_tables.py
More file actions
65 lines (55 loc) · 2.09 KB
/
001_initial_tables.py
File metadata and controls
65 lines (55 loc) · 2.09 KB
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
"""Initial tables
Revision ID: 001
Revises:
Create Date: 2025-09-09
"""
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from alembic import op
revision = "001"
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
"tenants",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=True),
sa.Column("schema_name", sa.String(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.Column("is_active", sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_tenants_id"), "tenants", ["id"], unique=False)
op.create_index(op.f("ix_tenants_name"), "tenants", ["name"], unique=True)
op.create_index(
op.f("ix_tenants_schema_name"), "tenants", ["schema_name"], unique=True
)
op.create_table(
"users",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("email", sa.String(), nullable=True),
sa.Column("hashed_password", sa.String(), nullable=True),
sa.Column("full_name", sa.String(), nullable=True),
sa.Column(
"role", sa.Enum("ADMIN", "TENANT_USER", name="userrole"), nullable=False
),
sa.Column("is_active", sa.Boolean(), nullable=True),
sa.Column("tenant_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["tenant_id"],
["tenants.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
def downgrade():
op.drop_index(op.f("ix_users_id"), table_name="users")
op.drop_index(op.f("ix_users_email"), table_name="users")
op.drop_table("users")
op.drop_index(op.f("ix_tenants_schema_name"), table_name="tenants")
op.drop_index(op.f("ix_tenants_name"), table_name="tenants")
op.drop_index(op.f("ix_tenants_id"), table_name="tenants")
op.drop_table("tenants")
op.execute("DROP TYPE userrole")