Skip to content

Commit

Permalink
fix removal of NOT NULL constraint
Browse files Browse the repository at this point in the history
I'm retroactively editing an existing migration because this is only
rolled out on QA so far and thus easy to fix.
  • Loading branch information
majewsky committed Sep 12, 2023
1 parent 644c36d commit 01d3bd5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/collector/capacity_scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ type capacityScrapeTask struct {
var (
// upsert a cluster_capacitors entry
initCapacitorQuery = sqlext.SimplifyWhitespace(`
INSERT INTO cluster_capacitors (capacitor_id, scraped_at, next_scrape_at)
VALUES ($1, $2, $2)
INSERT INTO cluster_capacitors (capacitor_id, next_scrape_at)
VALUES ($1, $2)
ON CONFLICT DO NOTHING
`)

Expand All @@ -98,6 +98,7 @@ func (c *Collector) discoverCapacityScrapeTask(_ context.Context, _ prometheus.L

//consistency check: every once in a while (and also immediately on startup),
//check that all required `cluster_capacitors` entries exist
//(this is important because the query below will only find capacitors that have such an entry)
if lastConsistencyCheckAt.Before(task.Timing.StartedAt.Add(-5 * time.Minute)) {
err = sqlext.WithPreparedStatement(c.DB, initCapacitorQuery, func(stmt *sql.Stmt) error {
for capacitorID := range c.Cluster.CapacityPlugins {
Expand Down
4 changes: 2 additions & 2 deletions internal/db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ var sqlMigrations = map[string]string{
`,
"024_move_capacity_scrape_timestamps.up.sql": `
ALTER TABLE cluster_capacitors
ALTER COLUMN scraped_at SET DEFAULT NULL; -- null if scraping did not happen yet
ALTER COLUMN scraped_at DROP NOT NULL; -- null if scraping did not happen yet
ALTER TABLE cluster_services
DROP COLUMN scraped_at;
ALTER TABLE cluster_resources
Expand All @@ -175,7 +175,7 @@ var sqlMigrations = map[string]string{
ALTER TABLE cluster_services
ADD COLUMN scraped_at TIMESTAMP NOT NULL DEFAULT NOW();
ALTER TABLE cluster_resources
ALTER COLUMN capacitor_id SET DEFAULT NULL;
ALTER COLUMN capacitor_id DROP NOT NULL;
`,
"025_capacity_scan_rework.up.sql": `
ALTER TABLE cluster_capacitors
Expand Down

0 comments on commit 01d3bd5

Please sign in to comment.