Skip to content

Commit

Permalink
update db model
Browse files Browse the repository at this point in the history
  • Loading branch information
motty-mio2 committed Nov 18, 2023
1 parent 5a3132f commit cd42dbd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/alembic/versions/2023_11_18_2152-78f98d411652_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""empty message
Revision ID: 0ea1059c8f7c
Revises: 8bd32b7bb552
Create Date: 2023-11-18 21:52:58.786979
"""
from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op


# revision identifiers, used by Alembic.
revision: str = "0ea1059c8f7c"
down_revision: Union[str, None] = "8bd32b7bb552"
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.add_column("session", sa.Column("created_at", sa.DateTime(), nullable=False))
op.add_column("session", sa.Column("weather_code", sa.Integer(), nullable=False))
op.add_column("user", sa.Column("ido_longitude", sa.Float(), nullable=False))
op.add_column("user", sa.Column("keido_latitude", sa.Float(), nullable=False))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("user", "keido_latitude")
op.drop_column("user", "ido_longitude")
op.drop_column("session", "weather_code")
op.drop_column("session", "created_at")
# ### end Alembic commands ###
6 changes: 5 additions & 1 deletion src/kb_2315/backend/models/model_session.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import uuid
from datetime import datetime
from typing import TYPE_CHECKING
from uuid import UUID

from sqlalchemy import ForeignKey, Integer, Uuid
from sqlalchemy import DateTime, ForeignKey, Integer, Uuid
from sqlalchemy.orm import Mapped, mapped_column, relationship

from kb_2315.backend.db.base import Base
Expand All @@ -21,4 +22,7 @@ class Session(Base):
device_id: Mapped[int] = mapped_column(Integer, nullable=False)
shoe_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("shoe.id"), nullable=True)

weather_code: Mapped[int] = mapped_column(Integer, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)

sensors: Mapped[list[Sensor]] = relationship("Sensor", backref="event")
5 changes: 4 additions & 1 deletion src/kb_2315/backend/models/model_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Integer, String
from sqlalchemy import Float, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from kb_2315.backend.db.base import Base
Expand All @@ -8,3 +8,6 @@ class User(Base):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
name: Mapped[str] = mapped_column(String, default="Taro")
line_channel_id: Mapped[str] = mapped_column(String, nullable=True)

ido_longitude: Mapped[float] = mapped_column(Float, nullable=False)
keido_latitude: Mapped[float] = mapped_column(Float, nullable=False)

0 comments on commit cd42dbd

Please sign in to comment.