Skip to content

Commit 0451bc8

Browse files
committed
Fix display number bug
1 parent aa9c518 commit 0451bc8

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

core_backend/app/contents/models.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ class ContentDB(Base):
6969
created_datetime_utc: Mapped[datetime] = mapped_column(
7070
DateTime(timezone=True), nullable=False
7171
)
72+
display_number: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
7273
is_archived: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
7374
positive_votes: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
7475
negative_votes: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
7576
query_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
7677
updated_datetime_utc: Mapped[datetime] = mapped_column(
7778
DateTime(timezone=True), nullable=False
7879
)
79-
display_number: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
8080
workspace_id: Mapped[int] = mapped_column(
8181
Integer,
8282
ForeignKey("workspace.workspace_id", ondelete="CASCADE"),
@@ -100,6 +100,7 @@ def __repr__(self) -> str:
100100
f"content_metadata={self.content_metadata}, "
101101
f"content_tags={self.content_tags}, "
102102
f"created_datetime_utc={self.created_datetime_utc}, "
103+
f"display_number={self.display_number}, "
103104
f"is_archived={self.is_archived}), "
104105
f"updated_datetime_utc={self.updated_datetime_utc}), "
105106
f"workspace_id={self.workspace_id}"
@@ -352,7 +353,7 @@ async def get_list_of_content_from_db(
352353
select(ContentDB)
353354
.options(selectinload(ContentDB.content_tags))
354355
.where(ContentDB.workspace_id == workspace_id)
355-
.order_by(ContentDB.content_id)
356+
.order_by(ContentDB.display_number)
356357
)
357358
if exclude_archived:
358359
stmt = stmt.where(ContentDB.is_archived == false())
@@ -361,7 +362,7 @@ async def get_list_of_content_from_db(
361362
if isinstance(limit, int) and limit > 0:
362363
stmt = stmt.limit(limit)
363364
content_rows = (await asession.execute(stmt)).all()
364-
365+
print([c[0] for c in content_rows])
365366
return [c[0] for c in content_rows] if content_rows else []
366367

367368

core_backend/app/contents/routers.py

+1
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ def _convert_record_to_schema(*, record: ContentDB) -> ContentRetrieve:
10451045
content_text=record.content_text,
10461046
content_title=record.content_title,
10471047
created_datetime_utc=record.created_datetime_utc,
1048+
display_number=record.display_number,
10481049
is_archived=record.is_archived,
10491050
negative_votes=record.negative_votes,
10501051
positive_votes=record.positive_votes,

core_backend/app/contents/schemas.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ContentRetrieve(ContentCreate):
3333
"""Pydantic model for content retrieval response."""
3434

3535
content_id: int
36+
display_number: int
3637
created_datetime_utc: datetime
3738
is_archived: bool
3839
negative_votes: int

core_backend/migrations/versions/2025_03_12_b1daed9f42c4_add_display_number.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,27 @@
2020

2121
def upgrade() -> None:
2222
# ### commands auto generated by Alembic - please adjust! ###
23-
op.add_column("content", sa.Column("display_number", sa.Integer(), nullable=False))
23+
op.add_column(
24+
"content",
25+
sa.Column("display_number", sa.Integer(), nullable=False, server_default="0"),
26+
)
2427

2528
connection = op.get_bind()
2629

2730
# 2
28-
workspaces = connection.execute(sa.text('SELECT * FROM "workspaces"')).mappings()
31+
workspaces = connection.execute(sa.text('SELECT * FROM "workspace"')).mappings()
2932
for workspace in workspaces:
30-
workspace_id = workspace["id"]
33+
workspace_id = workspace["workspace_id"]
3134
content = connection.execute(
3235
sa.text(
33-
f'SELECT * FROM "content" WHERE "workspace_id" = {workspace_id}'
36+
f'SELECT * FROM "content" WHERE "workspace_id" = {workspace_id} '
3437
f'ORDER BY "created_datetime_utc"'
3538
)
3639
).mappings()
3740
for i, row in enumerate(content):
3841
connection.execute(
3942
sa.text(
40-
f'UPDATE "content" SET "display_number" = {i + 1}'
43+
f'UPDATE "content" SET "display_number" = {i + 1} '
4144
f'WHERE "content_id" = {row["content_id"]}'
4245
)
4346
)

0 commit comments

Comments
 (0)