Fix noinlineerr findings: internal/database (refs #61)

This commit is contained in:
2026-08-07 16:59:56 +00:00
parent dca3c50cd2
commit bf1d3c6bad
4 changed files with 49 additions and 22 deletions

View File

@@ -117,7 +117,8 @@ func New(ctx context.Context, path string) (*DB, error) {
log.Debug("Database opened successfully with WAL mode", "path", path)
// Enable foreign keys explicitly
if _, err := conn.ExecContext(ctx, "PRAGMA foreign_keys = ON"); err != nil {
_, err = conn.ExecContext(ctx, "PRAGMA foreign_keys = ON")
if err != nil {
log.Warn("Failed to enable foreign keys", "error", err)
}
@@ -159,7 +160,8 @@ func New(ctx context.Context, path string) (*DB, error) {
conn.SetMaxOpenConns(1)
conn.SetMaxIdleConns(1)
if err := conn.PingContext(ctx); err != nil {
err = conn.PingContext(ctx)
if err != nil {
log.Debug("Failed to ping database in recovery mode, closing", "path", path, "error", err)
_ = conn.Close()
@@ -175,17 +177,21 @@ func New(ctx context.Context, path string) (*DB, error) {
// Switch back to WAL mode
log.Debug("Switching database back to WAL mode", "path", path)
if _, err := conn.ExecContext(ctx, "PRAGMA journal_mode=WAL"); err != nil {
_, err = conn.ExecContext(ctx, "PRAGMA journal_mode=WAL")
if err != nil {
log.Warn("Failed to switch back to WAL mode", "path", path, "error", err)
}
// Ensure foreign keys are enabled
if _, err := conn.ExecContext(ctx, "PRAGMA foreign_keys=ON"); err != nil {
_, err = conn.ExecContext(ctx, "PRAGMA foreign_keys=ON")
if err != nil {
log.Warn("Failed to enable foreign keys", "path", path, "error", err)
}
db := &DB{conn: conn, path: path}
if err := applyMigrations(ctx, conn); err != nil {
err = applyMigrations(ctx, conn)
if err != nil {
_ = conn.Close()
return nil, fmt.Errorf("applying migrations: %w", err)
@@ -323,7 +329,8 @@ func bootstrapMigrationsTable(ctx context.Context, db *sql.DB) error {
// the schema_migrations table via 000.sql, then iterates through remaining
// migration files in order.
func applyMigrations(ctx context.Context, db *sql.DB) error {
if err := bootstrapMigrationsTable(ctx, db); err != nil {
err := bootstrapMigrationsTable(ctx, db)
if err != nil {
return err
}