Skip to content

Commit

Permalink
give defaults to models during __init__, use PENDING as default test …
Browse files Browse the repository at this point in the history
…status
  • Loading branch information
elfkuzco committed Jun 9, 2024
1 parent 7b83097 commit 9865a19
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
51 changes: 27 additions & 24 deletions backend/src/mirrors_qa_backend/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ class Mirror(Base):
base_url: Mapped[str]
enabled: Mapped[bool]
# metadata of a mirror from MirroBrain (https://mirrorbrain-docs.readthedocs.io/en/latest/mirrors.html#displaying-details-about-a-mirror)
region: Mapped[str | None]
asn: Mapped[str | None]
score: Mapped[int | None]
latitude: Mapped[float | None]
longitude: Mapped[float | None]
country_only: Mapped[bool | None]
region_only: Mapped[bool | None]
as_only: Mapped[bool | None]
other_countries: Mapped[list[str] | None]
region: Mapped[str | None] = mapped_column(default=None)
asn: Mapped[str | None] = mapped_column(default=None)
score: Mapped[int | None] = mapped_column(default=None)
latitude: Mapped[float | None] = mapped_column(default=None)
longitude: Mapped[float | None] = mapped_column(default=None)
country_only: Mapped[bool | None] = mapped_column(default=None)
region_only: Mapped[bool | None] = mapped_column(default=None)
as_only: Mapped[bool | None] = mapped_column(default=None)
other_countries: Mapped[list[str] | None] = mapped_column(default=None)

country_code: Mapped[str] = mapped_column(
ForeignKey("country.code"),
Expand All @@ -97,9 +97,9 @@ class Worker(Base):
# RSA public key in PKCS8 format for generating access tokens required
# to make requests to the web server
pubkey_pkcs8: Mapped[str]
pubkey_fingerprint: Mapped[str | None]
pubkey_fingerprint: Mapped[str | None] = mapped_column(default=None)

last_seen_on: Mapped[datetime | None]
last_seen_on: Mapped[datetime | None] = mapped_column(default=None)
countries: Mapped[list[Country]] = relationship(back_populates="worker", init=False)


Expand All @@ -109,22 +109,25 @@ class Test(Base):
init=False, primary_key=True, server_default=text("uuid_generate_v4()")
)
requested_on: Mapped[datetime]
started_on: Mapped[datetime | None]
status: Mapped[StatusEnum | None] = mapped_column(
started_on: Mapped[datetime | None] = mapped_column(default=None)
status: Mapped[StatusEnum] = mapped_column(
Enum(
StatusEnum,
native_enum=False,
validate_strings=True,
create_constraint=True,
name="status",
)
),
default=StatusEnum.PENDING,
)
error: Mapped[str | None]
isp: Mapped[str | None]
ip_address: Mapped[IPv4Address | None]
asn: Mapped[str | None] # autonomous system based on IP
country: Mapped[str | None] # country based on IP
location: Mapped[str | None] # city based on IP
latency: Mapped[int | None] # milliseconds
download_size: Mapped[int | None] # bytes
duration: Mapped[int | None] # seconds
speed: Mapped[float | None] # bytes per second
error: Mapped[str | None] = mapped_column(default=None)
isp: Mapped[str | None] = mapped_column(default=None)
ip_address: Mapped[IPv4Address | None] = mapped_column(default=None)
# autonomous system based on IP
asn: Mapped[str | None] = mapped_column(default=None)
country: Mapped[str | None] = mapped_column(default=None) # country based on IP
location: Mapped[str | None] = mapped_column(default=None) # city based on IP
latency: Mapped[int | None] = mapped_column(default=None) # milliseconds
download_size: Mapped[int | None] = mapped_column(default=None) # bytes
duration: Mapped[int | None] = mapped_column(default=None) # seconds
speed: Mapped[float | None] = mapped_column(default=None) # bytes per second
7 changes: 4 additions & 3 deletions backend/src/mirrors_qa_backend/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class StatusEnum(Enum):
MISSED = 0
SUCCEEDED = 1
ERRORED = 2
PENDING = 0
MISSED = 1
SUCCEEDED = 2
ERRORED = 3
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ def upgrade() -> None:
sa.Column("started_on", sa.DateTime(), nullable=True),
sa.Column(
"status",
sa.Enum(name="status", native_enum=False, create_constraint=True),
nullable=True,
sa.Enum(
"PENDING",
"MISSED",
"SUCCEEDED",
"ERRORED",
name="status",
native_enum=False,
create_constraint=True,
),
nullable=False,
),
sa.Column("error", sa.String(), nullable=True),
sa.Column("isp", sa.String(), nullable=True),
Expand Down

0 comments on commit 9865a19

Please sign in to comment.