Skip to content

Commit c554946

Browse files
committed
fix: elections and officers datetime to DATE
1 parent c3130b0 commit c554946

File tree

4 files changed

+61
-57
lines changed

4 files changed

+61
-57
lines changed

src/alembic/versions/6b58a293a7df_add_unique_constraint_officer_term_71.py

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""elections-officers-datetime-to-date
2+
3+
Revision ID: 876041e5b41c
4+
Revises: 243190df5588
5+
Create Date: 2025-09-28 18:01:03.913302
6+
7+
"""
8+
from collections.abc import Sequence
9+
from typing import Union
10+
11+
import sqlalchemy as sa
12+
from sqlalchemy.dialects import postgresql
13+
14+
from alembic import op
15+
16+
# revision identifiers, used by Alembic.
17+
revision: str = "876041e5b41c"
18+
down_revision: str | None = "243190df5588"
19+
branch_labels: str | Sequence[str] | None = None
20+
depends_on: str | Sequence[str] | None = None
21+
22+
23+
def upgrade() -> None:
24+
# ### commands auto generated by Alembic - please adjust! ###
25+
op.alter_column("election", "datetime_start_nominations",
26+
existing_type=postgresql.TIMESTAMP(),
27+
type_=sa.Date(),
28+
existing_nullable=False)
29+
op.alter_column("election", "datetime_start_voting",
30+
existing_type=postgresql.TIMESTAMP(),
31+
type_=sa.Date(),
32+
existing_nullable=False)
33+
op.alter_column("election", "datetime_end_voting",
34+
existing_type=postgresql.TIMESTAMP(),
35+
type_=sa.Date(),
36+
existing_nullable=False)
37+
# ### end Alembic commands ###
38+
39+
40+
def downgrade() -> None:
41+
# ### commands auto generated by Alembic - please adjust! ###
42+
op.alter_column("election", "datetime_end_voting",
43+
existing_type=sa.Date(),
44+
type_=postgresql.TIMESTAMP(),
45+
existing_nullable=False)
46+
op.alter_column("election", "datetime_start_voting",
47+
existing_type=sa.Date(),
48+
type_=postgresql.TIMESTAMP(),
49+
existing_nullable=False)
50+
op.alter_column("election", "datetime_start_nominations",
51+
existing_type=sa.Date(),
52+
type_=postgresql.TIMESTAMP(),
53+
existing_nullable=False)
54+
# ### end Alembic commands ###

src/elections/tables.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22

33
from sqlalchemy import (
4+
Date,
45
DateTime,
56
String,
67
)
@@ -25,9 +26,9 @@ class Election(Base):
2526
slug: Mapped[str] = mapped_column(String(MAX_ELECTION_SLUG), primary_key=True)
2627
name: Mapped[str] = mapped_column(String(MAX_ELECTION_NAME), nullable=False)
2728
type: Mapped[ElectionTypeEnum] = mapped_column(String(32), default=ElectionTypeEnum.GENERAL)
28-
datetime_start_nominations: Mapped[datetime] = mapped_column(DateTime, nullable=False)
29-
datetime_start_voting: Mapped[datetime] = mapped_column(DateTime, nullable=False)
30-
datetime_end_voting: Mapped[datetime] = mapped_column(DateTime, nullable=False)
29+
datetime_start_nominations: Mapped[datetime] = mapped_column(Date, nullable=False)
30+
datetime_start_voting: Mapped[datetime] = mapped_column(Date, nullable=False)
31+
datetime_end_voting: Mapped[datetime] = mapped_column(Date, nullable=False)
3132

3233
# a comma-separated string of positions which must be elements of OfficerPosition
3334
# By giving it the type `StringList`, the database entry will automatically be marshalled to the correct form

src/officers/tables.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44

55
from sqlalchemy import (
6+
Date,
67
DateTime,
78
ForeignKey,
89
Integer,
@@ -37,9 +38,9 @@ class OfficerTerm(Base):
3738
)
3839

3940
position: Mapped[OfficerPositionEnum] = mapped_column(String(128), nullable=False)
40-
start_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
41+
start_date: Mapped[datetime] = mapped_column(Date, nullable=False)
4142
# end_date is only not-specified for positions that don't have a length (ie. webmaster)
42-
end_date: Mapped[datetime] = mapped_column(DateTime, nullable=True)
43+
end_date: Mapped[datetime] = mapped_column(Date, nullable=True)
4344

4445
nickname: Mapped[str] = mapped_column(String(128), nullable=True)
4546
favourite_course_0: Mapped[str] = mapped_column(String(64), nullable=True)

0 commit comments

Comments
 (0)