Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions storage/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ func validateDatabaseSchemaVersion(ctx context.Context, db *pg.DB, cfg schemas.C
return model.Version{}, xerrors.Errorf("schema not installed in database")
}

latestVersion := LatestSchemaVersion()
switch {
case latestVersion.Before(dbVersion):
// porridge too hot
return model.Version{}, ErrSchemaTooNew
case dbVersion.Before(model.OldestSupportedSchemaVersion):
// porridge too cold
return model.Version{}, ErrSchemaTooOld
default:
// just right
return dbVersion, nil
if dbVersion.Before(LatestSchemaVersion()) {
// the latest schema version supported by lily (LatestSchemaVersion()) is newer than the schema version in use by the database (`dbVersion`)
// running lily this way will cause models data persistence failures.
return model.Version{}, xerrors.Errorf("the latest schema version supported by lily (%s) is newer than the schema version in use by the database (%s) running lily this way will cause models data persistence failures: %w", LatestSchemaVersion(), dbVersion, ErrSchemaTooOld)
}
if LatestSchemaVersion().Before(dbVersion) {
// the latest schema version supported by lily (LatestSchemaVersion()) is older than the schema version in use by the database (`dbVersion`)
// running lily this way will cause undefined behaviour.
return model.Version{}, xerrors.Errorf("the latest schema version supported by lily (%s) is older than the schema version in use by the database (%s) running lily this way will cause undefined behaviour: %w", LatestSchemaVersion(), dbVersion, ErrSchemaTooNew)
}
return dbVersion, nil
}

// LatestSchemaVersion returns the most recent version of the model schema. It is based on the highest migration version
Expand Down
2 changes: 1 addition & 1 deletion storage/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var (

var (
ErrSchemaTooOld = errors.New("database schema is too old and requires migration")
ErrSchemaTooNew = errors.New("database schema is too new for this version of visor")
ErrSchemaTooNew = errors.New("database schema is too new for this version of lily")
ErrNameTooLong = errors.New("name exceeds maximum length for postgres application names")
)

Expand Down