Skip to content

Commit

Permalink
fix: record when modules are activated
Browse files Browse the repository at this point in the history
Use the activation time to determine which module is the current one.

fixes: 2961
  • Loading branch information
stuartwdouglas committed Oct 2, 2024
1 parent 1e4223a commit 4143499
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 53 deletions.
15 changes: 8 additions & 7 deletions backend/controller/cronjobs/internal/sql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions backend/controller/cronjobs/internal/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions backend/controller/dal/internal/sql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/dal/internal/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ FROM deployments d
LEFT JOIN runners r ON d.id = r.deployment_id
WHERE min_replicas > 0
GROUP BY d.id, m.name, m.language
ORDER BY d.created_at;
ORDER BY d.last_activated_at;

-- name: GetDeploymentsWithMinReplicas :many
SELECT sqlc.embed(d), m.name AS module_name, m.language
Expand Down Expand Up @@ -119,7 +119,7 @@ ORDER BY d.key;

-- name: SetDeploymentDesiredReplicas :exec
UPDATE deployments
SET min_replicas = $2
SET min_replicas = $2, last_activated_at = CASE WHEN min_replicas = 0 THEN (NOW() AT TIME ZONE 'utc') ELSE last_activated_at END
WHERE key = sqlc.arg('key')::deployment_key
RETURNING 1;

Expand Down
80 changes: 45 additions & 35 deletions backend/controller/dal/internal/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- migrate:up
ALTER TABLE deployments ADD COLUMN last_activated_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc');
UPDATE deployments SET last_activated_at = created_at;
-- migrate:down

1 change: 1 addition & 0 deletions deployment/base/db-migrate/kustomization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ configMapGenerator:
- ./schema/20240917062716_change_deployments_index.sql
- ./schema/20240919001309_create_identity_keys_table.sql
- ./schema/20240926231955_timeline_async_call_event_types.sql
- ./schema/20241002225509_create_last_activated.sql

0 comments on commit 4143499

Please sign in to comment.