-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EXPECTORATE tests for virtual_provisioning_collection CTE (#5081)
This is a direct follow-up to #5063, focused on the `virtual_provisioning_collection` CTE. This PR adds a test which validates the current SQL query, before re-structuring it to use `TypedSqlQuery`.
- Loading branch information
Showing
7 changed files
with
602 additions
and
16 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
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
97 changes: 97 additions & 0 deletions
97
nexus/db-queries/tests/output/virtual_provisioning_collection_update_delete_instance.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,97 @@ | ||
WITH | ||
parent_silo AS (SELECT project.silo_id AS id FROM project WHERE project.id = $1), | ||
all_collections | ||
AS ( | ||
((SELECT $2 AS id) UNION (SELECT parent_silo.id AS id FROM parent_silo)) | ||
UNION (SELECT $3 AS id) | ||
), | ||
quotas | ||
AS ( | ||
SELECT | ||
silo_quotas.silo_id, | ||
silo_quotas.cpus, | ||
silo_quotas.memory_bytes AS memory, | ||
silo_quotas.storage_bytes AS storage | ||
FROM | ||
silo_quotas INNER JOIN parent_silo ON silo_quotas.silo_id = parent_silo.id | ||
), | ||
silo_provisioned | ||
AS ( | ||
SELECT | ||
virtual_provisioning_collection.id, | ||
virtual_provisioning_collection.cpus_provisioned, | ||
virtual_provisioning_collection.ram_provisioned, | ||
virtual_provisioning_collection.virtual_disk_bytes_provisioned | ||
FROM | ||
virtual_provisioning_collection | ||
INNER JOIN parent_silo ON virtual_provisioning_collection.id = parent_silo.id | ||
), | ||
do_update | ||
AS ( | ||
SELECT | ||
( | ||
SELECT | ||
count(*) | ||
FROM | ||
virtual_provisioning_resource | ||
WHERE | ||
virtual_provisioning_resource.id = $4 | ||
LIMIT | ||
$5 | ||
) | ||
= $6 | ||
AS update | ||
), | ||
unused_cte_arm | ||
AS ( | ||
DELETE FROM | ||
virtual_provisioning_resource | ||
WHERE | ||
virtual_provisioning_resource.id = $7 | ||
AND virtual_provisioning_resource.id | ||
= ( | ||
SELECT | ||
instance.id | ||
FROM | ||
instance | ||
WHERE | ||
instance.id = $8 AND instance.state_generation < $9 | ||
LIMIT | ||
$10 | ||
) | ||
RETURNING | ||
virtual_provisioning_resource.id, | ||
virtual_provisioning_resource.time_modified, | ||
virtual_provisioning_resource.resource_type, | ||
virtual_provisioning_resource.virtual_disk_bytes_provisioned, | ||
virtual_provisioning_resource.cpus_provisioned, | ||
virtual_provisioning_resource.ram_provisioned | ||
), | ||
virtual_provisioning_collection | ||
AS ( | ||
UPDATE | ||
virtual_provisioning_collection | ||
SET | ||
time_modified = current_timestamp(), | ||
cpus_provisioned = virtual_provisioning_collection.cpus_provisioned - $11, | ||
ram_provisioned = virtual_provisioning_collection.ram_provisioned - $12 | ||
WHERE | ||
virtual_provisioning_collection.id = ANY (SELECT all_collections.id FROM all_collections) | ||
AND (SELECT do_update.update FROM do_update LIMIT $13) | ||
RETURNING | ||
virtual_provisioning_collection.id, | ||
virtual_provisioning_collection.time_modified, | ||
virtual_provisioning_collection.collection_type, | ||
virtual_provisioning_collection.virtual_disk_bytes_provisioned, | ||
virtual_provisioning_collection.cpus_provisioned, | ||
virtual_provisioning_collection.ram_provisioned | ||
) | ||
SELECT | ||
virtual_provisioning_collection.id, | ||
virtual_provisioning_collection.time_modified, | ||
virtual_provisioning_collection.collection_type, | ||
virtual_provisioning_collection.virtual_disk_bytes_provisioned, | ||
virtual_provisioning_collection.cpus_provisioned, | ||
virtual_provisioning_collection.ram_provisioned | ||
FROM | ||
virtual_provisioning_collection |
86 changes: 86 additions & 0 deletions
86
nexus/db-queries/tests/output/virtual_provisioning_collection_update_delete_storage.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,86 @@ | ||
WITH | ||
parent_silo AS (SELECT project.silo_id AS id FROM project WHERE project.id = $1), | ||
all_collections | ||
AS ( | ||
((SELECT $2 AS id) UNION (SELECT parent_silo.id AS id FROM parent_silo)) | ||
UNION (SELECT $3 AS id) | ||
), | ||
quotas | ||
AS ( | ||
SELECT | ||
silo_quotas.silo_id, | ||
silo_quotas.cpus, | ||
silo_quotas.memory_bytes AS memory, | ||
silo_quotas.storage_bytes AS storage | ||
FROM | ||
silo_quotas INNER JOIN parent_silo ON silo_quotas.silo_id = parent_silo.id | ||
), | ||
silo_provisioned | ||
AS ( | ||
SELECT | ||
virtual_provisioning_collection.id, | ||
virtual_provisioning_collection.cpus_provisioned, | ||
virtual_provisioning_collection.ram_provisioned, | ||
virtual_provisioning_collection.virtual_disk_bytes_provisioned | ||
FROM | ||
virtual_provisioning_collection | ||
INNER JOIN parent_silo ON virtual_provisioning_collection.id = parent_silo.id | ||
), | ||
do_update | ||
AS ( | ||
SELECT | ||
( | ||
SELECT | ||
count(*) | ||
FROM | ||
virtual_provisioning_resource | ||
WHERE | ||
virtual_provisioning_resource.id = $4 | ||
LIMIT | ||
$5 | ||
) | ||
= $6 | ||
AS update | ||
), | ||
unused_cte_arm | ||
AS ( | ||
DELETE FROM | ||
virtual_provisioning_resource | ||
WHERE | ||
virtual_provisioning_resource.id = $7 | ||
RETURNING | ||
virtual_provisioning_resource.id, | ||
virtual_provisioning_resource.time_modified, | ||
virtual_provisioning_resource.resource_type, | ||
virtual_provisioning_resource.virtual_disk_bytes_provisioned, | ||
virtual_provisioning_resource.cpus_provisioned, | ||
virtual_provisioning_resource.ram_provisioned | ||
), | ||
virtual_provisioning_collection | ||
AS ( | ||
UPDATE | ||
virtual_provisioning_collection | ||
SET | ||
time_modified = current_timestamp(), | ||
virtual_disk_bytes_provisioned | ||
= virtual_provisioning_collection.virtual_disk_bytes_provisioned - $8 | ||
WHERE | ||
virtual_provisioning_collection.id = ANY (SELECT all_collections.id FROM all_collections) | ||
AND (SELECT do_update.update FROM do_update LIMIT $9) | ||
RETURNING | ||
virtual_provisioning_collection.id, | ||
virtual_provisioning_collection.time_modified, | ||
virtual_provisioning_collection.collection_type, | ||
virtual_provisioning_collection.virtual_disk_bytes_provisioned, | ||
virtual_provisioning_collection.cpus_provisioned, | ||
virtual_provisioning_collection.ram_provisioned | ||
) | ||
SELECT | ||
virtual_provisioning_collection.id, | ||
virtual_provisioning_collection.time_modified, | ||
virtual_provisioning_collection.collection_type, | ||
virtual_provisioning_collection.virtual_disk_bytes_provisioned, | ||
virtual_provisioning_collection.cpus_provisioned, | ||
virtual_provisioning_collection.ram_provisioned | ||
FROM | ||
virtual_provisioning_collection |
Oops, something went wrong.