Release Drafter / auto_label (push) Skipped
Release Drafter / draft_release (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
Backend Lint and Test / tests (sqlite) (push) Canceled after 0s
Backend Lint and Test / tests (postgres) (push) Canceled after 0s
Docker Nightly Production / Backend Server Tests (push) Canceled after 0s
Frontend Lint and Test / lint (push) Canceled after 0s
Docker Nightly Production / Frontend Tests (push) Canceled after 0s
Build Package / Build frontend and wheel (push) Canceled after 0s
Docker Nightly Production / Build Package (push) Canceled after 0s
Docker Nightly Production / Build E2E Image Cache (push) Canceled after 0s
Docker Nightly Production / Build Tagged Release (push) Canceled after 0s
Docker Nightly Production / Notify Discord (push) Canceled after 0s
53 lines
2.4 KiB
Python
53 lines
2.4 KiB
Python
from importlib.util import module_from_spec, spec_from_file_location
|
|
from io import StringIO
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from alembic.migration import MigrationContext
|
|
from alembic.operations import Operations
|
|
from sqlalchemy import create_engine, inspect, text
|
|
|
|
|
|
def load_migration():
|
|
path = (
|
|
Path(__file__).parents[2]
|
|
/ "mealie/alembic/versions/2026-12-01-00.00.00_e274a9d13c50_fractional_step_duration.py"
|
|
)
|
|
spec = spec_from_file_location("fractional_step_duration_migration", path)
|
|
module = module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def test_postgresql_upgrade_sql():
|
|
output = StringIO()
|
|
context = MigrationContext.configure(dialect_name="postgresql", opts={"as_sql": True, "output_buffer": output})
|
|
with Operations.context(context):
|
|
load_migration().upgrade()
|
|
assert "ALTER COLUMN DURATION_SECONDS TYPE FLOAT" in output.getvalue().upper()
|
|
|
|
|
|
def test_sqlite_migration_and_safe_downgrade():
|
|
engine = create_engine("sqlite://")
|
|
migration = load_migration()
|
|
with engine.begin() as connection:
|
|
connection.execute(text("CREATE TABLE recipe_instructions (id INTEGER PRIMARY KEY, duration_seconds INTEGER)"))
|
|
connection.execute(text("INSERT INTO recipe_instructions VALUES (1, 90), (2, NULL)"))
|
|
with Operations.context(MigrationContext.configure(connection)):
|
|
migration.upgrade()
|
|
assert str(inspect(connection).get_columns("recipe_instructions")[1]["type"]) == "FLOAT"
|
|
durations = connection.execute(text("SELECT duration_seconds FROM recipe_instructions ORDER BY id"))
|
|
assert durations.scalars().all() == [
|
|
90,
|
|
None,
|
|
]
|
|
connection.execute(text("UPDATE recipe_instructions SET duration_seconds = 0.5 WHERE id = 1"))
|
|
with pytest.raises(RuntimeError, match="fractional durations"):
|
|
migration.downgrade()
|
|
assert connection.scalar(text("SELECT duration_seconds FROM recipe_instructions WHERE id = 1")) == 0.5
|
|
connection.execute(text("UPDATE recipe_instructions SET duration_seconds = 90 WHERE id = 1"))
|
|
migration.downgrade()
|
|
assert str(inspect(connection).get_columns("recipe_instructions")[1]["type"]) == "INTEGER"
|
|
assert connection.scalar(text("SELECT duration_seconds FROM recipe_instructions WHERE id = 1")) == 90
|
|
engine.dispose()
|