Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve admin webui #112

Merged
merged 17 commits into from
Feb 25, 2024
Merged
Prev Previous commit
Next Next commit
Amend major_version check
- 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
mreid-tt committed Jan 15, 2024
commit ad1cf1772d925b6ee7e7c1bdb83db7f85360755c
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")
3 changes: 2 additions & 1 deletion spkrepo/models.py
Original file line number Diff line number Diff line change
@@ -134,8 +134,9 @@ class Firmware(db.Model):

# Columns
id = db.Column(db.Integer, primary_key=True)
version = db.Column(db.Unicode(3), nullable=False)
version = db.Column(db.Unicode(4), nullable=False)
build = db.Column(db.Integer, unique=True, nullable=False)
type = db.Column(db.Unicode(4), nullable=False)

@classmethod
def find(cls, build):
5 changes: 4 additions & 1 deletion spkrepo/utils.py
Original file line number Diff line number Diff line change
@@ -398,7 +398,10 @@ def populate_db():
)
db.session.execute(
Firmware.__table__.insert().values(
[{"version": "3.1", "build": 1594}, {"version": "5.0", "build": 4458}]
[
{"version": "3.1", "build": 1594, "type": "dsm"},
{"version": "5.0", "build": 4458, "type": "dsm"},
]
)
)
db.session.execute(
2 changes: 1 addition & 1 deletion spkrepo/views/nas.py
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ def is_valid_language(language):
def get_catalog(arch, build, language, beta):
# Find the closest matching firmware for the provided build
closest_firmware = (
Firmware.query.filter(Firmware.build <= build)
Firmware.query.filter(Firmware.build <= build, Firmware.type == "dsm")
.order_by(Firmware.build.desc())
.first()
)