ck 1
Dependencies
- [2]
AVQ66WO4tools/ refactor - [3]
RUVJ3V4Ncyclo to 14 now - [4]
GPQSOVBPcyclo complexity over 25 - [5]
JZRF7OBJrefactor to get db omports out of utils, but still have failing tests, may need updating - [6]
T2WZBTVFcyclo 22 - [7]
KLUEQ6X5cyclo 21+ - [8]
E27ZWCDPcyclo over 18 - [9]
2P27XV3Dfixed cyclo over 30 - [10]
KZKLAINJrun out of space on nest, cleaned out - [11]
JAT3DXOLcyclo over 15 - [*]
LQLC7S3Atrying gemini: Inconsistent Standards in @utils/ refactoring
Change contents
- edit in tools/sql.go at line 16
// Deprecated: use Input.DBPath instead. Will be removed after all callers are migrated. - replacement in tools/sql.go at line 20
// Called from main.go during initialization// Deprecated: use Input.DBPath instead. Will be removed after all callers are migrated. - edit in tools/sql.go at line 23
}// resolveDBPath returns the DBPath from the input if set, otherwise falls back// to the package-level dbPath. This supports the incremental migration from// the global variable to explicit input fields.func resolveDBPath(inputPath string) string {if inputPath != "" {return inputPath}return dbPath - edit in tools/sql.go at line 37
DBPath string `json:"db_path"` - replacement in tools/sql.go at line 89
err := db.WithReadDB(dbPath, func(database *sql.DB) error {err := db.WithReadDB(resolveDBPath(input.DBPath), func(database *sql.DB) error { - edit in tools/pattern.go at line 14
DBPath string `json:"db_path"` - replacement in tools/pattern.go at line 102
err := db.WithWriteTx(ctx, dbPath, "create_or_update_pattern", func(database *sql.DB, tx *db.LoggedTx) error {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_pattern", func(database *sql.DB, tx *db.LoggedTx) error { - edit in tools/pattern.go at line 144[2.10551]→[3.285160:285163](∅→∅),[3.285160]→[3.285160:285163](∅→∅),[3.285163]→[2.10552:10706](∅→∅),[2.10706]→[3.285985:286010](∅→∅),[3.285985]→[3.285985:286010](∅→∅),[3.286010]→[2.10707:10734](∅→∅),[2.10734]→[3.286036:286185](∅→∅),[3.286036]→[3.286036:286185](∅→∅),[3.286185]→[2.10735:10759](∅→∅),[3.7982]→[3.286209:286252](∅→∅),[2.10759]→[3.286209:286252](∅→∅),[3.286209]→[3.286209:286252](∅→∅),[3.286252]→[2.10760:10816](∅→∅),[2.10816]→[3.286316:286333](∅→∅),[3.286316]→[3.286316:286333](∅→∅),[3.286333]→[2.10817:10873](∅→∅),[3.8047]→[3.286397:286414](∅→∅),[2.10873]→[3.286397:286414](∅→∅),[3.286397]→[3.286397:286414](∅→∅),[3.286414]→[2.10874:10969](∅→∅),[3.8151]→[3.286517:286520](∅→∅),[2.10969]→[3.286517:286520](∅→∅),[3.286517]→[3.286517:286520](∅→∅),[3.286520]→[2.10970:10982](∅→∅)
}// verifyPatternExistsAndActive checks that a pattern exists and is active.func verifyPatternExistsAndActive(database *sql.DB, patternID string) error {var exists, active boolerr := database.QueryRow("SELECT EXISTS(SELECT 1 FROM cyclic_recording_pattern WHERE id = ?), COALESCE((SELECT active FROM cyclic_recording_pattern WHERE id = ?), false)",patternID, patternID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to query pattern: %w", err)}if !exists {return fmt.Errorf("pattern not found: %s", patternID)}if !active {return fmt.Errorf("pattern '%s' is not active (cannot update inactive patterns)", patternID)}return nil - replacement in tools/pattern.go at line 178
err := db.WithWriteTx(ctx, dbPath, "create_or_update_pattern", func(database *sql.DB, tx *db.LoggedTx) error {if err := verifyPatternExistsAndActive(database, *input.ID); err != nil {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_pattern", func(database *sql.DB, tx *db.LoggedTx) error {if err := db.PatternExistsAndActive(database, *input.ID); err != nil { - edit in tools/location.go at line 14
DBPath string `json:"db_path"` - replacement in tools/location.go at line 113
err := db.WithWriteTx(ctx, dbPath, "create_or_update_location", func(database *sql.DB, tx *db.LoggedTx) error {if err := verifyDatasetExistsAndActive(ctx, tx, *input.DatasetID); err != nil {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_location", func(database *sql.DB, tx *db.LoggedTx) error {if _, err := db.DatasetExistsAndActive(tx, *input.DatasetID); err != nil { - edit in tools/location.go at line 175[3.295057]→[3.7930:8006](∅→∅),[3.8006]→[2.14339:14497](∅→∅),[2.14497]→[3.8654:8657](∅→∅),[3.8654]→[3.8654:8657](∅→∅)
// verifyDatasetExistsAndActive checks that a dataset exists and is active.func verifyDatasetExistsAndActive(ctx context.Context, q db.Querier, datasetID string) error {_, err := db.DatasetExistsAndActive(q, datasetID)return err} - replacement in tools/location.go at line 193
err := db.WithWriteTx(ctx, dbPath, "create_or_update_location", func(database *sql.DB, tx *db.LoggedTx) error {if err := verifyLocationExistsAndActive(database, locationID); err != nil {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_location", func(database *sql.DB, tx *db.LoggedTx) error {if err := db.LocationExistsAndActive(database, locationID); err != nil { - replacement in tools/location.go at line 200
if err := verifyDatasetExistsAndActive(ctx, database, *input.DatasetID); err != nil {if _, err := db.DatasetExistsAndActive(database, *input.DatasetID); err != nil { - edit in tools/location.go at line 226[2.15599]→[3.9906:10591](∅→∅),[3.9906]→[3.9906:10591](∅→∅),[3.10591]→[3.297075:297078](∅→∅),[3.297075]→[3.297075:297078](∅→∅),[3.297078]→[3.10592:10604](∅→∅)
}// verifyLocationExistsAndActive checks that a location exists and is active.func verifyLocationExistsAndActive(queryer interface {QueryRow(string, ...any) *sql.Row}, locationID string) error {var exists, active boolerr := queryer.QueryRow("SELECT EXISTS(SELECT 1 FROM location WHERE id = ?), COALESCE((SELECT active FROM location WHERE id = ?), false)",locationID, locationID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to query location: %w", err)}if !exists {return fmt.Errorf("location not found: %s", locationID)}if !active {return fmt.Errorf("location '%s' is not active (cannot update inactive locations)", locationID)}return nil - edit in tools/import_unstructured.go at line 19
DBPath string `json:"db_path"` - replacement in tools/import_unstructured.go at line 67
err := db.WithWriteTx(ctx, dbPath, "import_unstructured", func(database *sql.DB, tx *db.LoggedTx) error {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "import_unstructured", func(database *sql.DB, tx *db.LoggedTx) error { - replacement in tools/import_unstructured.go at line 191
return db.WithReadDB(dbPath, func(database *sql.DB) error {return db.WithReadDB(resolveDBPath(input.DBPath), func(database *sql.DB) error { - edit in tools/import_segments.go at line 18
DBPath string `json:"db_path"` - replacement in tools/import_segments.go at line 174
database, err := db.OpenWriteableDB(dbPath)database, err := db.OpenWriteableDB(resolveDBPath(input.DBPath)) - edit in tools/import_files.go at line 16
DBPath string `json:"db_path"` - replacement in tools/import_files.go at line 57
if err := validateImportInput(input, dbPath); err != nil {if err := validateImportInput(input, resolveDBPath(input.DBPath)); err != nil { - replacement in tools/import_files.go at line 62
database, err := db.OpenWriteableDB(dbPath)database, err := db.OpenWriteableDB(resolveDBPath(input.DBPath)) - edit in tools/import_file.go at line 18
DBPath string `json:"db_path"` - replacement in tools/import_file.go at line 55
if err := validateHierarchyIDs(input.DatasetID, input.LocationID, input.ClusterID, dbPath); err != nil {if err := validateHierarchyIDs(input.DatasetID, input.LocationID, input.ClusterID, resolveDBPath(input.DBPath)); err != nil { - replacement in tools/import_file.go at line 60
database, err := db.OpenWriteableDB(dbPath)database, err := db.OpenWriteableDB(resolveDBPath(input.DBPath)) - edit in tools/export.go at line 17
DBPath string `json:"db_path"` - replacement in tools/export.go at line 85
sourceDB, err := db.OpenReadOnlyDB(dbPath)sourceDB, err := db.OpenReadOnlyDB(resolveDBPath(input.DBPath)) - replacement in tools/export.go at line 90
datasetName, err := verifyExportDataset(ctx, sourceDB, input)datasetName, err := db.ValidateDatasetTypeForExport(sourceDB, input.DatasetID) - replacement in tools/export.go at line 132
if err := copyDataToOutput(ctx, outputDB, orderedTables, input.DatasetID); err != nil {if err := copyDataToOutput(ctx, outputDB, orderedTables, input.DatasetID, resolveDBPath(input.DBPath)); err != nil { - edit in tools/export.go at line 175
// verifyExportDataset checks the dataset exists, is active, and is structured.func verifyExportDataset(ctx context.Context, sourceDB *sql.DB, input ExportDatasetInput) (string, error) {var datasetName, datasetType stringerr := sourceDB.QueryRowContext(ctx,"SELECT name, type FROM dataset WHERE id = ? AND active = true",input.DatasetID,).Scan(&datasetName, &datasetType)if err != nil {return "", fmt.Errorf("dataset not found: %s", input.DatasetID)}if datasetType != "structured" {return "", fmt.Errorf("cannot export dataset of type '%s': only structured datasets are supported", datasetType)}return datasetName, nil} - replacement in tools/export.go at line 210
func copyDataToOutput(ctx context.Context, outputDB *sql.DB, tables []TableRelationship, datasetID string) error {_, err := outputDB.ExecContext(ctx, fmt.Sprintf("ATTACH '%s' AS source", dbPath))func copyDataToOutput(ctx context.Context, outputDB *sql.DB, tables []TableRelationship, datasetID string, sourceDBPath string) error {_, err := outputDB.ExecContext(ctx, fmt.Sprintf("ATTACH '%s' AS source", sourceDBPath)) - edit in tools/dataset.go at line 14
DBPath string `json:"db_path"` - replacement in tools/dataset.go at line 60
err = db.WithWriteTx(ctx, dbPath, "create_or_update_dataset", func(database *sql.DB, tx *db.LoggedTx) error {err = db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_dataset", func(database *sql.DB, tx *db.LoggedTx) error { - replacement in tools/dataset.go at line 227
err := db.WithWriteTx(ctx, dbPath, "create_or_update_dataset", func(database *sql.DB, tx *db.LoggedTx) error {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_dataset", func(database *sql.DB, tx *db.LoggedTx) error { - replacement in tools/dataset.go at line 229
if err := verifyDatasetActive(database, datasetID); err != nil {if _, err := db.DatasetExistsAndActive(database, datasetID); err != nil { - edit in tools/dataset.go at line 259
// verifyDatasetActive checks that a dataset exists and is active.func verifyDatasetActive(database *sql.DB, datasetID string) error {var exists, active boolerr := database.QueryRow("SELECT EXISTS(SELECT 1 FROM dataset WHERE id = ?), COALESCE((SELECT active FROM dataset WHERE id = ?), false)", datasetID, datasetID).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to query dataset: %w", err)}if !exists {return fmt.Errorf("dataset not found: %s", datasetID)}if !active {return fmt.Errorf("dataset '%s' is not active (cannot update inactive datasets)", datasetID)}return nil} - edit in tools/cluster.go at line 14
DBPath string `json:"db_path"` - replacement in tools/cluster.go at line 86
err := db.WithWriteTx(ctx, dbPath, "create_or_update_cluster", func(database *sql.DB, tx *db.LoggedTx) error {err := db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_cluster", func(database *sql.DB, tx *db.LoggedTx) error { - replacement in tools/cluster.go at line 124
if err := verifyPatternExists(ctx, tx, *input.CyclicRecordingPatternID); err != nil {if err := db.PatternExistsAndActive(tx, *input.CyclicRecordingPatternID); err != nil { - edit in tools/cluster.go at line 183
}// verifyPatternExists verifies a cyclic recording pattern exists and is activefunc verifyPatternExists(ctx context.Context, tx *db.LoggedTx, patternID string) error {var exists, active boolerr := tx.QueryRowContext(ctx,"SELECT EXISTS(SELECT 1 FROM cyclic_recording_pattern WHERE id = ?), COALESCE((SELECT active FROM cyclic_recording_pattern WHERE id = ?), false)",patternID, patternID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to verify cyclic recording pattern: %w", err)}if !exists {return fmt.Errorf("cyclic recording pattern with ID '%s' does not exist", patternID)}if !active {return fmt.Errorf("cyclic recording pattern with ID '%s' is not active", patternID)}return nil - replacement in tools/cluster.go at line 211[3.11184]→[3.388791:388816](∅→∅),[3.388791]→[3.388791:388816](∅→∅),[3.388816]→[3.11185:11212](∅→∅),[3.11212]→[3.388842:389024](∅→∅),[3.388842]→[3.388842:389024](∅→∅),[3.389024]→[3.11213:11269](∅→∅),[3.11269]→[3.389088:389105](∅→∅),[3.389088]→[3.389088:389105](∅→∅),[3.389105]→[3.11270:11326](∅→∅),[3.11326]→[3.389169:389186](∅→∅),[3.389169]→[3.389169:389186](∅→∅),[3.389186]→[3.11327:11422](∅→∅),[3.11422]→[3.389289:389292](∅→∅),[3.389289]→[3.389289:389292](∅→∅),[3.389292]→[3.11423:11435](∅→∅)
var exists, active boolerr := database.QueryRow("SELECT EXISTS(SELECT 1 FROM cluster WHERE id = ?), COALESCE((SELECT active FROM cluster WHERE id = ?), false)",clusterID, clusterID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to query cluster: %w", err)}if !exists {return fmt.Errorf("cluster not found: %s", clusterID)}if !active {return fmt.Errorf("cluster '%s' is not active (cannot update inactive clusters)", clusterID)}return nilreturn db.ClusterExistsAndActive(database, clusterID) - replacement in tools/cluster.go at line 223
return validateCyclicPattern(database, trimmed)return db.PatternExistsAndActive(database, trimmed) - edit in tools/cluster.go at line 226[3.389293]→[3.11438:11937](∅→∅),[3.11937]→[3.390148:390151](∅→∅),[3.390148]→[3.390148:390151](∅→∅),[3.390151]→[3.11938:12137](∅→∅),[3.12137]→[3.390151:390152](∅→∅),[3.390151]→[3.390151:390152](∅→∅)
// validateCyclicPattern checks that a cyclic recording pattern exists and is active.func validateCyclicPattern(database *sql.DB, patternID string) error {var exists, active boolerr := database.QueryRow("SELECT EXISTS(SELECT 1 FROM cyclic_recording_pattern WHERE id = ?), COALESCE((SELECT active FROM cyclic_recording_pattern WHERE id = ?), false)",patternID, patternID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to verify cyclic recording pattern: %w", err)}if !exists {return fmt.Errorf("cyclic recording pattern not found: %s", patternID)}if !active {return fmt.Errorf("cyclic recording pattern '%s' is not active", patternID)}return nil} - replacement in tools/cluster.go at line 297
err = db.WithWriteTx(ctx, dbPath, "create_or_update_cluster", func(database *sql.DB, tx *db.LoggedTx) error {err = db.WithWriteTx(ctx, resolveDBPath(input.DBPath), "create_or_update_cluster", func(database *sql.DB, tx *db.LoggedTx) error { - edit in tools/bulk_file_import.go at line 20
DBPath string `json:"db_path"` - replacement in tools/bulk_file_import.go at line 132
if err := bulkValidateLocations(logger, locations, input.DatasetID); err != nil {if err := bulkValidateLocations(logger, locations, input.DatasetID, resolveDBPath(input.DBPath)); err != nil { - replacement in tools/bulk_file_import.go at line 140
database, err := db.OpenWriteableDB(dbPath)database, err := db.OpenWriteableDB(resolveDBPath(input.DBPath)) - replacement in tools/bulk_file_import.go at line 201
database, err := db.OpenReadOnlyDB(dbPath)database, err := db.OpenReadOnlyDB(resolveDBPath(input.DBPath)) - replacement in tools/bulk_file_import.go at line 237
func bulkValidateLocations(logger *progressLogger, locations []bulkLocationData, datasetID string) error {func bulkValidateLocations(logger *progressLogger, locations []bulkLocationData, datasetID string, dbPath string) error { - edit in db/validation.go at line 121
}// ClusterExistsAndActive checks that a cluster exists and is active.func ClusterExistsAndActive(q Querier, clusterID string) error {var exists, active boolerr := q.QueryRow("SELECT EXISTS(SELECT 1 FROM cluster WHERE id = ?), COALESCE((SELECT active FROM cluster WHERE id = ?), false)",clusterID, clusterID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to verify cluster: %w", err)}if !exists {return fmt.Errorf("cluster not found: %s", clusterID)}if !active {return fmt.Errorf("cluster '%s' is not active (cannot update inactive clusters)", clusterID)}return nil - edit in db/validation.go at line 142
// PatternExistsAndActive checks that a cyclic recording pattern exists and is active.func PatternExistsAndActive(q Querier, patternID string) error {var exists, active boolerr := q.QueryRow("SELECT EXISTS(SELECT 1 FROM cyclic_recording_pattern WHERE id = ?), COALESCE((SELECT active FROM cyclic_recording_pattern WHERE id = ?), false)",patternID, patternID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to verify cyclic recording pattern: %w", err)}if !exists {return fmt.Errorf("cyclic recording pattern with ID '%s' does not exist", patternID)}if !active {return fmt.Errorf("cyclic recording pattern with ID '%s' is not active", patternID)}return nil}// LocationExistsAndActive checks that a location exists and is active.func LocationExistsAndActive(q Querier, locationID string) error {var exists, active boolerr := q.QueryRow("SELECT EXISTS(SELECT 1 FROM location WHERE id = ?), COALESCE((SELECT active FROM location WHERE id = ?), false)",locationID, locationID,).Scan(&exists, &active)if err != nil {return fmt.Errorf("failed to verify location: %w", err)}if !exists {return fmt.Errorf("location not found: %s", locationID)}if !active {return fmt.Errorf("location '%s' is not active (cannot update inactive locations)", locationID)}return nil}// ValidateDatasetTypeForExport checks that a dataset exists, is active, and is 'structured'.// Returns the dataset name if valid.func ValidateDatasetTypeForExport(q Querier, datasetID string) (string, error) {name, err := DatasetExistsAndActive(q, datasetID)if err != nil {return "", err}datasetType, exists, err := GetDatasetType(q, datasetID)if err != nil {return "", fmt.Errorf("failed to query dataset type: %w", err)}if !exists {return "", fmt.Errorf("dataset not found: %s", datasetID)}if datasetType != "structured" {return "", fmt.Errorf("cannot export dataset of type '%s': only structured datasets are supported", datasetType)}return name, nil} - replacement in cmd/sql.go at line 65
Query: query,DBPath: *dbPath,Query: query, - edit in cmd/pattern.go at line 70
DBPath: *dbPath, - replacement in cmd/pattern.go at line 146
ID: id,DBPath: *dbPath,ID: id, - edit in cmd/location.go at line 98
DBPath: *dbPath, - replacement in cmd/location.go at line 192
ID: id,DBPath: *dbPath,ID: id, - edit in cmd/import.go at line 115
DBPath: *dbPath, - edit in cmd/import.go at line 206
DBPath: *dbPath, - edit in cmd/import.go at line 293
DBPath: *dbPath, - edit in cmd/import.go at line 421
DBPath: *dbPath, - edit in cmd/import.go at line 520
DBPath: *dbPath, - edit in cmd/export.go at line 94
DBPath: *dbPath, - edit in cmd/dataset.go at line 68
DBPath: *dbPath, - replacement in cmd/dataset.go at line 128
ID: id,DBPath: *dbPath,ID: id, - edit in cmd/cluster.go at line 89
DBPath: *dbPath, - replacement in cmd/cluster.go at line 161
ID: id,DBPath: *dbPath,ID: id,