-
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.
Dual write rule instances to new and old tables (#3486)
Relates to #3485 Any time a profile is created or updated, write the rule instances to both the new and old rule instance tables. Mark the entries in the old tables as migrated so that we skip over them when we run the migration process. Also made def/params field nullable.
- Loading branch information
Showing
10 changed files
with
442 additions
and
16 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
database/migrations/000061_rule_instance_not_null_def.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,20 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
BEGIN; | ||
|
||
ALTER TABLE rule_instances ALTER COLUMN def DROP NOT NULL; | ||
ALTER TABLE rule_instances ALTER COLUMN params DROP NOT NULL; | ||
|
||
COMMIT; |
20 changes: 20 additions & 0 deletions
20
database/migrations/000061_rule_instance_not_null_def.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,20 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
BEGIN; | ||
|
||
ALTER TABLE rule_instances ALTER COLUMN def SET NOT NULL; | ||
ALTER TABLE rule_instances ALTER COLUMN params SET NOT NULL; | ||
|
||
COMMIT; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
-- name: UpsertRuleInstance :one | ||
INSERT INTO rule_instances ( | ||
profile_id, | ||
rule_type_id, | ||
name, | ||
entity_type, | ||
def, | ||
params, | ||
created_at, | ||
updated_at | ||
) VALUES( | ||
$1, | ||
$2, | ||
$3, | ||
$4, | ||
$5, | ||
$6, | ||
NOW(), | ||
NOW() | ||
) | ||
ON CONFLICT (profile_id, entity_type, name) DO UPDATE SET | ||
rule_type_id = $2, | ||
def = $5, | ||
params = $6, | ||
updated_at = NOW() | ||
RETURNING id; | ||
|
||
-- name: GetRuleInstancesForProfile :many | ||
SELECT * FROM rule_instances WHERE profile_id = $1; | ||
|
||
-- name: GetRuleInstancesForProfileEntity :many | ||
SELECT * FROM rule_instances WHERE profile_id = $1 AND entity_type = $2; | ||
|
||
-- name: DeleteNonUpdatedRules :exec | ||
DELETE FROM rule_instances | ||
WHERE profile_id = $1 | ||
AND entity_type = $2 | ||
AND NOT id = ANY(sqlc.arg(updated_ids)::UUID[]); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.