-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store timestamp when marking subgraph as synced (#5566)
We migrate `synced` from a boolean value to a nullable `synced_at` timestamp on `subgraphs.subgraph_deployment` and `unused_deployments`. The default timestamp used in the migration is the unix epoch, `1970-01-01 00:00:00+00`. Note that in the down migration we skip removal of `DEFAULT false` on `unused_deployments.`
- Loading branch information
Showing
6 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
store/postgres/migrations/2024-07-22-140930_track_synced_date/down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
DROP VIEW info.subgraph_info; | ||
|
||
ALTER TABLE subgraphs.subgraph_deployment ADD COLUMN synced BOOLEAN NOT NULL DEFAULT false; | ||
ALTER TABLE unused_deployments ADD COLUMN synced BOOLEAN NOT NULL DEFAULT false; | ||
|
||
UPDATE subgraphs.subgraph_deployment SET synced = synced_at IS NOT NULL; | ||
UPDATE unused_deployments SET synced = synced_at IS NOT NULL; | ||
|
||
-- NB: We keep the default on unused_deployment, as it was there before. | ||
ALTER TABLE subgraphs.subgraph_deployment ALTER COLUMN synced DROP DEFAULT; | ||
|
||
ALTER TABLE subgraphs.subgraph_deployment DROP COLUMN synced_at; | ||
ALTER TABLE unused_deployments DROP COLUMN synced_at; | ||
|
||
CREATE VIEW info.subgraph_info AS | ||
SELECT ds.id AS schema_id, | ||
ds.name AS schema_name, | ||
ds.subgraph, | ||
ds.version, | ||
s.name, | ||
CASE | ||
WHEN s.pending_version = v.id THEN 'pending'::text | ||
WHEN s.current_version = v.id THEN 'current'::text | ||
ELSE 'unused'::text | ||
END AS status, | ||
d.failed, | ||
d.synced | ||
FROM deployment_schemas ds, | ||
subgraphs.subgraph_deployment d, | ||
subgraphs.subgraph_version v, | ||
subgraphs.subgraph s | ||
WHERE d.deployment = ds.subgraph::text AND v.deployment = d.deployment AND v.subgraph = s.id; |
29 changes: 29 additions & 0 deletions
29
store/postgres/migrations/2024-07-22-140930_track_synced_date/up.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
DROP VIEW info.subgraph_info; | ||
|
||
ALTER TABLE subgraphs.subgraph_deployment ADD COLUMN synced_at TIMESTAMPTZ; | ||
ALTER TABLE unused_deployments ADD COLUMN synced_at TIMESTAMPTZ; | ||
|
||
UPDATE subgraphs.subgraph_deployment SET synced_at = '1970-01-01 00:00:00 UTC' WHERE synced; | ||
UPDATE unused_deployments SET synced_at = '1970-01-01 00:00:00 UTC' WHERE synced; | ||
|
||
ALTER TABLE subgraphs.subgraph_deployment DROP COLUMN synced; | ||
ALTER TABLE unused_deployments DROP COLUMN synced; | ||
|
||
CREATE VIEW info.subgraph_info AS | ||
SELECT ds.id AS schema_id, | ||
ds.name AS schema_name, | ||
ds.subgraph, | ||
ds.version, | ||
s.name, | ||
CASE | ||
WHEN s.pending_version = v.id THEN 'pending'::text | ||
WHEN s.current_version = v.id THEN 'current'::text | ||
ELSE 'unused'::text | ||
END AS status, | ||
d.failed, | ||
d.synced_at | ||
FROM deployment_schemas ds, | ||
subgraphs.subgraph_deployment d, | ||
subgraphs.subgraph_version v, | ||
subgraphs.subgraph s | ||
WHERE d.deployment = ds.subgraph::text AND v.deployment = d.deployment AND v.subgraph = s.id; |
This file contains 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
This file contains 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
This file contains 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