Skip to content

Commit

Permalink
added created_at column
Browse files Browse the repository at this point in the history
  • Loading branch information
zurdi15 committed Jun 27, 2024
1 parent 24d6770 commit d3324b6
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""empty message
Revision ID: 0020_update_at_added
Revision ID: 0020_created_and_updated
Revises: 0019_resources_refactor
Create Date: 2024-06-27 11:33:06.962897
Create Date: 2024-06-27 12:08:13.886766
"""

Expand All @@ -11,7 +11,7 @@
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "0020_update_at_added"
revision = "0020_created_and_updated"
down_revision = "0019_resources_refactor"
branch_labels = None
depends_on = None
Expand All @@ -20,6 +20,14 @@
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("firmware", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
)
)
batch_op.add_column(
sa.Column(
"updated_at",
Expand All @@ -30,6 +38,14 @@ def upgrade() -> None:
)

with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
)
)
batch_op.add_column(
sa.Column(
"updated_at",
Expand All @@ -51,6 +67,14 @@ def upgrade() -> None:
batch_op.drop_column("last_edited_at")

with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
)
)
batch_op.add_column(
sa.Column(
"updated_at",
Expand All @@ -61,6 +85,14 @@ def upgrade() -> None:
)

with op.batch_alter_table("users", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
)
)
batch_op.add_column(
sa.Column(
"updated_at",
Expand All @@ -77,9 +109,11 @@ def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("users", schema=None) as batch_op:
batch_op.drop_column("updated_at")
batch_op.drop_column("created_at")

with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.drop_column("updated_at")
batch_op.drop_column("created_at")

with op.batch_alter_table("rom_notes", schema=None) as batch_op:
batch_op.add_column(
Expand All @@ -94,8 +128,10 @@ def downgrade() -> None:

with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.drop_column("updated_at")
batch_op.drop_column("created_at")

with op.batch_alter_table("firmware", schema=None) as batch_op:
batch_op.drop_column("updated_at")
batch_op.drop_column("created_at")

# ### end Alembic commands ###
5 changes: 5 additions & 0 deletions backend/endpoints/responses/firmware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from pydantic import BaseModel
from typing_extensions import TypedDict

Expand All @@ -18,6 +20,9 @@ class FirmwareSchema(BaseModel):
md5_hash: str
sha1_hash: str

created_at: datetime
updated_at: datetime

class Config:
from_attributes = True

Expand Down
3 changes: 3 additions & 0 deletions backend/endpoints/responses/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ class UserSchema(BaseModel):
last_login: datetime | None
last_active: datetime | None

created_at: datetime
updated_at: datetime

class Config:
from_attributes = True
5 changes: 5 additions & 0 deletions backend/endpoints/responses/platform.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from pydantic import BaseModel, Field

from .firmware import FirmwareSchema
Expand All @@ -15,5 +17,8 @@ class PlatformSchema(BaseModel):
logo_path: str | None = ""
firmware: list[FirmwareSchema] = Field(default_factory=list)

created_at: datetime
updated_at: datetime

class Config:
from_attributes = True
1 change: 1 addition & 0 deletions backend/endpoints/responses/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class RomSchema(BaseModel):
files: list[str]
full_path: str

created_at: datetime
updated_at: datetime

class Config:
Expand Down
3 changes: 3 additions & 0 deletions backend/models/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Firmware(BaseModel):
platform: Mapped["Platform"] = relationship(
lazy="joined", back_populates="firmware"
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now()
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
Expand Down
3 changes: 3 additions & 0 deletions backend/models/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Platform(BaseModel):
firmware: Mapped[list["Firmware"]] = relationship(
lazy="selectin", back_populates="platform"
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now()
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
Expand Down
3 changes: 3 additions & 0 deletions backend/models/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Rom(BaseModel):
states: Mapped[list["State"]] = relationship(back_populates="rom")
screenshots: Mapped[list["Screenshot"]] = relationship(back_populates="rom")
notes: Mapped[list["RomNote"]] = relationship(back_populates="rom")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now()
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
Expand Down
3 changes: 3 additions & 0 deletions backend/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class User(BaseModel, SimpleUser):
states: Mapped[list["State"]] = relationship(back_populates="user")
screenshots: Mapped[list["Screenshot"]] = relationship(back_populates="user")
notes: Mapped[list["RomNote"]] = relationship(back_populates="user")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now()
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/__generated__/models/DetailedRomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/__generated__/models/FirmwareSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/__generated__/models/PlatformSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/__generated__/models/RomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/__generated__/models/UserSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3324b6

Please sign in to comment.