Skip to content

fix: recreate ops_alert_silences table dropped by goose-style migration#877

Open
labuladong wants to merge 1 commit intoWei-Shaw:mainfrom
labuladong:fix/recreate-ops-alert-silences-table
Open

fix: recreate ops_alert_silences table dropped by goose-style migration#877
labuladong wants to merge 1 commit intoWei-Shaw:mainfrom
labuladong:fix/recreate-ops-alert-silences-table

Conversation

@labuladong
Copy link

Problem

Migration 037_ops_alert_silences.sql uses goose-style annotations (-- +goose Up / -- +goose Down), but the project's custom migration runner (migrations_runner.go) does not parse goose directives — it executes the entire file content as plain SQL.

This means the Down section (DROP TABLE IF EXISTS ops_alert_silences) runs immediately after the Up section (CREATE TABLE), leaving the table missing in production.

Impact: The alert silence feature (CreateAlertSilence, IsAlertSilenced) is silently broken — database queries fail because the table does not exist.

Note: Two other migrations (019, 024) have the same goose annotation issue but with lower severity (data-level rather than table-level).

Fix

Add a new migration 071_recreate_ops_alert_silences.sql that recreates the table using IF NOT EXISTS for idempotency.

Root cause

The custom migration runner at internal/repository/migrations_runner.go:230 calls tx.ExecContext(ctx, content) with the full file content. SQL treats -- +goose Down as a plain comment, so the DROP statement executes unconditionally.

Migration 037_ops_alert_silences.sql uses goose annotations (-- +goose Up /
-- +goose Down), but the project's migration runner does not parse goose
directives. It executes the entire file as plain SQL, so the Down section
(DROP TABLE IF EXISTS) runs immediately after the Up section (CREATE TABLE),
leaving the table missing.

This caused the alert silence feature (CreateAlertSilence, IsAlertSilenced)
to be silently broken.

This migration recreates the table with IF NOT EXISTS for idempotency.
@labuladong labuladong force-pushed the fix/recreate-ops-alert-silences-table branch from 9a40d18 to 4c918eb Compare March 9, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant