-
Notifications
You must be signed in to change notification settings - Fork 0
/
ff861c79333d_preregistered_users.py
72 lines (61 loc) · 2.34 KB
/
ff861c79333d_preregistered_users.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
"""preregistered users
Revision ID: ff861c79333d
Revises: 952a100dae1e
Create Date: 2024-10-15 16:34:16.459332
"""
from typing import Sequence, Union
import sqlalchemy as sa
import sqlmodel.sql.sqltypes
from sqlmodel import Session, insert
from alembic import op
from deep_ice.core.security import get_password_hash
from deep_ice.models import User
# revision identifiers, used by Alembic.
revision: str = "ff861c79333d"
down_revision: Union[str, None] = "952a100dae1e"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"users",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column(
"hashed_password", sqlmodel.sql.sqltypes.AutoString(), nullable=False
),
sa.Column("is_active", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
# ### end Alembic commands ###
# Insert initial data.
with Session(bind=op.get_bind()) as session:
session.exec( # type: ignore
insert(User).values(
[
{
"name": "Cosmin Poieana",
"email": "[email protected]",
"hashed_password": get_password_hash("cosmin-password"),
},
{
"name": "John Doe",
"email": "[email protected]",
"hashed_password": get_password_hash("john-password"),
},
{
"name": "Sam Smith",
"email": "[email protected]",
"hashed_password": get_password_hash("sam-password"),
},
]
)
)
session.commit()
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_users_email"), table_name="users")
op.drop_table("users")
# ### end Alembic commands ###