-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add type column to Firmware table - Increase length of version column - Filter by type for closest firmware when getting catalog - Update populate_db with firmware type
- Loading branch information
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
migrations/versions/f95855ce9471_add_firmware_type_and_increase_version_.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,47 @@ | ||
"""Add firmware type and increase version length | ||
Revision ID: f95855ce9471 | ||
Revises: 76d559b4e873 | ||
Create Date: 2024-01-15 13:58:34.160242 | ||
""" | ||
revision = "f95855ce9471" | ||
down_revision = "76d559b4e873" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
def upgrade(): | ||
op.add_column("firmware", sa.Column("type", sa.Unicode(length=4))) | ||
# Set type based on version | ||
op.execute( | ||
""" | ||
UPDATE firmware | ||
SET type = CASE | ||
WHEN version LIKE '1.%' THEN 'srm' | ||
ELSE 'dsm' | ||
END | ||
""" | ||
) | ||
# Modify the column to be NOT NULL after setting the values | ||
op.alter_column("firmware", "type", nullable=False) | ||
|
||
op.alter_column( | ||
"firmware", | ||
"version", | ||
existing_type=sa.VARCHAR(length=3), | ||
type_=sa.Unicode(length=4), | ||
existing_nullable=False, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.alter_column( | ||
"firmware", | ||
"version", | ||
existing_type=sa.Unicode(length=4), | ||
type_=sa.VARCHAR(length=3), | ||
existing_nullable=False, | ||
) | ||
op.drop_column("firmware", "type") |
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
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