fix: recreate ops_alert_silences table dropped by goose-style migration#877
Open
labuladong wants to merge 1 commit intoWei-Shaw:mainfrom
Open
fix: recreate ops_alert_silences table dropped by goose-style migration#877labuladong wants to merge 1 commit intoWei-Shaw:mainfrom
labuladong wants to merge 1 commit intoWei-Shaw:mainfrom
Conversation
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.
9a40d18 to
4c918eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Migration
037_ops_alert_silences.sqluses 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.sqlthat recreates the table usingIF NOT EXISTSfor idempotency.Root cause
The custom migration runner at
internal/repository/migrations_runner.go:230callstx.ExecContext(ctx, content)with the full file content. SQL treats-- +goose Downas a plain comment, so the DROP statement executes unconditionally.