generated from owl-corp/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add users and products to the database
- Loading branch information
1 parent
61d6174
commit e45394f
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
thallium-backend/migrations/versions/1723831312-ac28edf8dd84_users_and_products.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Add users and products to the DB. | ||
Revision ID: ac28edf8dd84 | ||
Revises: | ||
Create Date: 2024-08-16 18:01:52.768054+00:00 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ac28edf8dd84" | ||
down_revision = None | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Apply this migration.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"products", | ||
sa.Column("product_id", sa.Integer(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("description", sa.String(), nullable=False), | ||
sa.Column("price", sa.Numeric(), nullable=False), | ||
sa.Column("image", sa.LargeBinary(), nullable=False), | ||
sa.Column("id", sa.Uuid(), nullable=False), | ||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), | ||
sa.PrimaryKeyConstraint("product_id", "id", name=op.f("products_pk")), | ||
) | ||
op.create_table( | ||
"users", | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.Column("is_admin", sa.Boolean(), nullable=False), | ||
sa.Column("id", sa.Uuid(), nullable=False), | ||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), | ||
sa.PrimaryKeyConstraint("user_id", "id", name=op.f("users_pk")), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
"""Revert this migration.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("users") | ||
op.drop_table("products") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from decimal import Decimal | ||
|
||
from sqlalchemy.orm import Mapped, mapped_column | ||
from sqlalchemy.types import LargeBinary | ||
|
||
from .base import AuditBase, Base | ||
|
||
|
||
class Product(AuditBase, Base): | ||
"""A product available to be ordered.""" | ||
|
||
__tablename__ = "products" | ||
|
||
product_id: Mapped[int] = mapped_column(primary_key=True) | ||
name: Mapped[str] | ||
description: Mapped[str] | ||
price: Mapped[Decimal] | ||
image: Mapped[bytes] = mapped_column(LargeBinary, deferred=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from .base import AuditBase, Base | ||
|
||
|
||
class User(AuditBase, Base): | ||
"""An authenticated user of the service.""" | ||
|
||
__tablename__ = "users" | ||
|
||
user_id: Mapped[int] = mapped_column(primary_key=True) | ||
is_admin: Mapped[bool] |