feat(store): complete v2 runtime state repositories
This commit is contained in:
@@ -129,6 +129,33 @@ func TestStoreInitRecordsMigrationLedgerOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreAppliesLatestMigration(t *testing.T) {
|
||||
store := openTestStore(t)
|
||||
defer closeTestStore(t, store)
|
||||
|
||||
for _, table := range []string{"import_runs", "import_run_items", "import_run_item_events"} {
|
||||
if !tableExists(t, store.SQLDB(), table) {
|
||||
t.Fatalf("table %q does not exist after latest migration", table)
|
||||
}
|
||||
}
|
||||
|
||||
for _, column := range []string{
|
||||
"api_key_fingerprint",
|
||||
"canonical_model_families_json",
|
||||
"matched_account_state",
|
||||
"account_resolution",
|
||||
"provision_reused",
|
||||
"reused_from_provider_id",
|
||||
"reused_from_account_id",
|
||||
"lease_owner",
|
||||
"lease_until",
|
||||
} {
|
||||
if !tableColumnExists(t, store.SQLDB(), "import_run_items", column) {
|
||||
t.Fatalf("column %q missing from import_run_items", column)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreInitBackfillsLedgerForCompletePreLedgerSchema(t *testing.T) {
|
||||
dbPath := filepath.Join(t.TempDir(), "state.db")
|
||||
dsn := fmt.Sprintf("file:%s?_busy_timeout=5000", filepath.ToSlash(dbPath))
|
||||
@@ -303,3 +330,34 @@ func countRows(t *testing.T, db *sql.DB, table string) int {
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func tableColumnExists(t *testing.T, db *sql.DB, table, column string) bool {
|
||||
t.Helper()
|
||||
|
||||
rows, err := db.QueryContext(context.Background(), "PRAGMA table_info("+table+")")
|
||||
if err != nil {
|
||||
t.Fatalf("table_info(%q) query error = %v", table, err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
cid int
|
||||
name string
|
||||
columnType string
|
||||
notNull int
|
||||
defaultVal sql.NullString
|
||||
pk int
|
||||
)
|
||||
if err := rows.Scan(&cid, &name, &columnType, ¬Null, &defaultVal, &pk); err != nil {
|
||||
t.Fatalf("table_info(%q) scan error = %v", table, err)
|
||||
}
|
||||
if name == column {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
t.Fatalf("table_info(%q) rows error = %v", table, err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user