forked from openml-labs/server-demo
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from aiondemand/enh/entry_status
Make `aiod_entry.status` a true ENUM
- Loading branch information
Showing
17 changed files
with
174 additions
and
118 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
alembic/alembic/versions/1662d64ebe23_make_draft_status_enum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""make draft status enum | ||
Revision ID: 1662d64ebe23 | ||
Revises: d09ed8ad4533 | ||
Create Date: 2024-12-17 09:02:30.480835 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy import Column, INT, String, Enum | ||
|
||
from database.model.field_length import NORMAL | ||
from database.model.concept.aiod_entry import EntryStatus | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "1662d64ebe23" | ||
down_revision: Union[str, None] = "d09ed8ad4533" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.drop_table("aiod_entry_status_link") | ||
op.add_column( | ||
"aiod_entry", | ||
Column("status", Enum(EntryStatus)), | ||
) | ||
op.execute( | ||
""" | ||
UPDATE aiod_entry | ||
INNER JOIN status | ||
ON status.identifier = aiod_entry.status_identifier | ||
SET aiod_entry.status = status.name | ||
""" | ||
) | ||
op.drop_constraint( | ||
constraint_name="aiod_entry_ibfk_1", | ||
table_name="aiod_entry", | ||
type_="foreignkey", | ||
) | ||
op.drop_column( | ||
table_name="aiod_entry", | ||
column_name="status_identifier", | ||
) | ||
op.drop_table("status") | ||
|
||
|
||
def downgrade() -> None: | ||
# No need to recreate table status link, it was not used. | ||
op.create_table( | ||
"status", | ||
Column("identifier", type_=INT, primary_key=True), | ||
Column( | ||
"name", | ||
unique=True, | ||
type_=String(NORMAL), | ||
index=True, | ||
), | ||
) | ||
op.execute( | ||
""" | ||
INSERT INTO status | ||
VALUES (1, 'draft'), (2, 'published'), (3, 'rejected'), (4, 'submitted') | ||
""" | ||
) | ||
op.add_column( | ||
"aiod_entry", | ||
Column("status_identifier", INT), | ||
) | ||
op.execute( | ||
""" | ||
UPDATE aiod_entry | ||
INNER JOIN status | ||
ON aiod_entry.status = status.name | ||
SET aiod_entry.status_identifier = status.identifier | ||
""" | ||
) | ||
op.drop_column( | ||
"aiod_entry", | ||
"status", | ||
) | ||
op.create_foreign_key( | ||
"aiod_entry_ibfk_1", | ||
"aiod_entry", | ||
"status", | ||
["status_identifier"], | ||
["identifier"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker exec -it sqlserver mysql -uroot -pok --database=aiod -e "UPDATE alembic_version SET version_num = '$1'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from connectors.example.enum import EnumConnectorStatus | ||
from connectors.example.enum import EnumConnectorEventMode | ||
|
||
|
||
def test_fetch_happy_path(): | ||
connector = EnumConnectorStatus() | ||
connector = EnumConnectorEventMode() | ||
resources = list(connector.fetch()) | ||
assert set(resources) == {"published", "draft", "rejected"} | ||
|
||
allowed_modes = {"offline", "online", "hybrid"} | ||
assert set(resources) == allowed_modes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.