mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 18:53:17 -05:00 
			
		
		
		
	Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import pathlib
 | 
						|
 | 
						|
from pydantic import BaseModel
 | 
						|
 | 
						|
from tests.utils.alembic_reader import ALEMBIC_MIGRATIONS, import_file
 | 
						|
 | 
						|
 | 
						|
class AlembicMigration(BaseModel):
 | 
						|
    path: pathlib.Path
 | 
						|
    revision: str | None = None
 | 
						|
    down_revision: str | None = None
 | 
						|
 | 
						|
 | 
						|
def test_alembic_revisions_are_in_order() -> None:
 | 
						|
    # read all files
 | 
						|
    paths = sorted(ALEMBIC_MIGRATIONS.glob("*.py"))
 | 
						|
 | 
						|
    # convert to sorted list of AlembicMigration
 | 
						|
    migrations: list[AlembicMigration] = []
 | 
						|
 | 
						|
    for path in paths:
 | 
						|
        mod = import_file("alembic_version", path)
 | 
						|
 | 
						|
        revision = getattr(mod, "revision", None)
 | 
						|
        down_revision = getattr(mod, "down_revision", None)
 | 
						|
 | 
						|
        migrations.append(
 | 
						|
            AlembicMigration(
 | 
						|
                path=path,
 | 
						|
                revision=revision,
 | 
						|
                down_revision=down_revision,
 | 
						|
            )
 | 
						|
        )
 | 
						|
 | 
						|
    # step through each migration and check
 | 
						|
    #   - revision is in order
 | 
						|
    #   - down_revision is in order
 | 
						|
    #   - down_revision is the previous revision
 | 
						|
    last = None
 | 
						|
    for migration in migrations:
 | 
						|
        if last is not None:
 | 
						|
            assert last.revision == migration.down_revision, (
 | 
						|
                f"{last.revision} != {migration.down_revision} for {migration.path}"
 | 
						|
            )
 | 
						|
 | 
						|
        last = migration
 | 
						|
        last = migration
 |