-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define rule instance table for Minder (#3459)
Rule instances are currently stored as serialized protobuf structures in the database, grouped by entity type. A separate join table exists to track the relationship between a profile-entity and the rule types which are used. This arrangement leads to some rather awkward code and database queries making the profile-related code in Minder more complex than it should be. This PR adds in a definition of a dedicated rule instance table. Subsequent PRs will migrate data over to it and then change the codebase to query this table instead of the current tables.
- Loading branch information
Showing
5 changed files
with
103 additions
and
8 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
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; | ||
|
||
DROP TABLE rule_instances; | ||
ALTER TABLE entity_profiles DROP COLUMN migrated; | ||
|
||
COMMIT; |
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,39 @@ | ||
-- 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; | ||
|
||
CREATE TABLE IF NOT EXISTS rule_instances( | ||
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, | ||
profile_id UUID NOT NULL REFERENCES profiles(id) ON DELETE CASCADE, | ||
rule_type_id UUID NOT NULL REFERENCES rule_type(id), | ||
name TEXT NOT NULL, | ||
entity_type entities NOT NULL, | ||
def JSONB, -- stores the values needed by the rule type's `def` | ||
params JSONB, -- stores the values needed by the rule type's `params` | ||
created_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
-- equivalent to constraints enforced by rule validation | ||
UNIQUE (profile_id, entity_type, name) | ||
); | ||
|
||
-- this reflects likely access patterns for this table - retrieving all rule | ||
-- instances for a given profile, and all rules by profile and entity type | ||
CREATE INDEX idx_rule_instances_profile ON rule_instances(profile_id); | ||
CREATE INDEX idx_rule_instances_profile_entity ON rule_instances(profile_id, entity_type); | ||
|
||
-- this will be used for migration purposes | ||
ALTER TABLE entity_profiles ADD COLUMN migrated BOOL DEFAULT FALSE NOT NULL; | ||
|
||
COMMIT; |
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
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.