fix(schema): distinguish optional ML budget installation from corruption
This commit is contained in:
1 parent
367bfa3a2a
commit
cbcb8a24b4
4 files changed
+64
-1
No files matched your search
@@ -28,6 +28,13 @@ type MigrationInspection struct {
|
||||
// Pending definitions are a plan, not a successful rehearsal: data-dependent
|
||||
// DDL and assertions on not-yet-created objects require a disposable DB copy.
|
||||
func InspectSQLiteMigrations(ctx context.Context, database *sql.DB, plans map[string][]SQLMigration) ([]MigrationInspection, error) {
|
||||
return InspectSQLiteMigrationsWithOptional(ctx, database, plans, nil)
|
||||
}
|
||||
|
||||
// Optional components are omitted only when neither a migration record nor any
|
||||
// owned schema object exists. Detection and inspection share one read snapshot;
|
||||
// partial installation or a missing table after installation is never ignored.
|
||||
func InspectSQLiteMigrationsWithOptional(ctx context.Context, database *sql.DB, plans map[string][]SQLMigration, optional map[string][]string) ([]MigrationInspection, error) {
|
||||
tx, err := database.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -80,6 +87,19 @@ func InspectSQLiteMigrations(ctx context.Context, database *sql.DB, plans map[st
|
||||
return nil, err
|
||||
}
|
||||
steps, known := plans[name]
|
||||
if objects, opt := optional[name]; opt && len(history[name]) == 0 && len(objects) > 0 {
|
||||
present := false
|
||||
for _, object := range objects {
|
||||
var exists bool
|
||||
if err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE name=?)`, object).Scan(&exists); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
present = present || exists
|
||||
}
|
||||
if !present {
|
||||
continue
|
||||
}
|
||||
}
|
||||
item := MigrationInspection{Component: name, State: "current", LatestVersion: len(steps)}
|
||||
for i, step := range steps {
|
||||
if step.Version != i+1 || step.Name == "" || (len(step.Statements) == 0 && len(step.AddColumns) == 0 && len(step.Assertions) == 0) {
|
||||
|
||||
Reference in new issue
Block a user