-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: import operational units from afirev
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
src/api/qualicharge/migrations/versions/fda96abb970d_add_operational_unit_data.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,72 @@ | ||
"""add operational unit data | ||
Revision ID: fda96abb970d | ||
Revises: 9d22385a3ae8 | ||
Create Date: 2024-05-15 16:08:19.687606 | ||
""" | ||
|
||
import json | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from qualicharge.db import get_engine | ||
from qualicharge.schemas import OperationalUnit, OperationalUnitTypeEnum | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "fda96abb970d" | ||
down_revision: Union[str, None] = "9d22385a3ae8" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
# Database globals | ||
engine = get_engine() | ||
metadata = sa.MetaData() | ||
metadata.reflect(bind=engine) | ||
|
||
|
||
def upgrade(): | ||
data_upgrades() | ||
|
||
|
||
def downgrade(): | ||
data_downgrades() | ||
|
||
|
||
def data_upgrades(): | ||
"""Add any optional data upgrade migrations here!""" | ||
|
||
operational_units = [ | ||
OperationalUnit( | ||
code="FR073", | ||
name="ACELEC CHARGE", | ||
type=OperationalUnitTypeEnum.CHARGING, | ||
).model_dump_sa(), | ||
OperationalUnit( | ||
code="FR0NX", name="NEXTENEO", type=OperationalUnitTypeEnum.CHARGING | ||
).model_dump_sa(), | ||
OperationalUnit( | ||
code="FR147", name="E.Z.O", type=OperationalUnitTypeEnum.CHARGING | ||
).model_dump_sa(), | ||
OperationalUnit( | ||
code="FR281", name="WALLCORP", type=OperationalUnitTypeEnum.CHARGING | ||
).model_dump_sa(), | ||
OperationalUnit( | ||
code="FR2AC", | ||
name="SUPERNOVA", | ||
type=OperationalUnitTypeEnum.CHARGING, | ||
).model_dump_sa(), | ||
] | ||
op.bulk_insert( | ||
sa.Table("operationalunit", metadata, autoload_with=engine), | ||
operational_units, | ||
) | ||
|
||
|
||
def data_downgrades(): | ||
"""Add any optional data downgrade migrations here!""" | ||
|
||
op.execute("delete from operationalunit") |
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