Skip to content

Update compliance database schema #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2024
Merged

Update compliance database schema #157

merged 3 commits into from
Jan 5, 2024

Conversation

mprahl
Copy link
Member

@mprahl mprahl commented Dec 20, 2023

This adds a namespace field to the parent policy table so that the root policy namespace and name is recorded instead of the replicated policy name which includes the root policy namespace in it. This is more intuitive since the user interacts with the root policy and not often with the replicated policy.

This also moves the parent policy foreign key to the compliance_events table. This is better as a point in time record of the parent policy associated with the policy that generated the compliance event. It does make filtering more efficient later to see any compliance event associated with a parent policy. It also allows less data duplication on the policies table.

As part of this refactoring, goku was removed in favor of a minimal translation layer of database queries to structs and vice versa.

@mprahl mprahl requested a review from JustinKuli January 3, 2024 16:16
@mprahl
Copy link
Member Author

mprahl commented Jan 3, 2024

@JustinKuli the latest commit makes the SQL queries static. Let me know what you think of this approach!

Comment on lines +472 to +374
// getOrCreate will translate the input object to an INSERT SQL query. When the input object already exists in the
// database, a SELECT query is performed. The primary key is set on the input object when it is inserted or gotten
// from the database. The INSERT first then SELECT approach is a clean way to account for race conditions of multiple
// goroutines creating the same row.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! I don't think I fully appreciated this on my first review.

JustinKuli
JustinKuli previously approved these changes Jan 4, 2024
Copy link
Member

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold

I added some optional comments. Feel free to un-hold if you'd rather address them in a future PR (or not at all)

mprahl added 3 commits January 4, 2024 16:21
This adds a namespace field to the parent policy table so that the root
policy namespace and name is recorded instead of the replicated policy
name which includes the root policy namespace in it. This is more
intuitive since the user interacts with the root policy and not often
with the replicated policy.

This also moves the parent policy foreign key to the compliance_events table.
This is better as a point in time record of the parent policy associated
with the policy that generated the compliance event. It does make
filtering more efficient later to see any compliance event associated with a
parent policy. It also allows less data duplication on the policies
table.

As part of this refactoring, goku was removed in favor of a minimal
translation layer of database queries to structs and vice versa.

Signed-off-by: mprahl <[email protected]>
This simplifies the logic and makes it clearer what query is being made
when reading the code.

Signed-off-by: mprahl <[email protected]>
This also removes the unused fromRow.

Signed-off-by: mprahl <[email protected]>
@mprahl mprahl requested a review from JustinKuli January 4, 2024 21:22
@mprahl
Copy link
Member Author

mprahl commented Jan 4, 2024

@JustinKuli alright, all the complicated "cool" stuff has been removed from the PR now. 😆 I kept them in the commit history in case we decided to go back that route.

@openshift-ci openshift-ci bot added the lgtm label Jan 5, 2024
Copy link

openshift-ci bot commented Jan 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JustinKuli, mprahl

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@JustinKuli
Copy link
Member

/unhold

Thanks (and sorry) for all the back-and-forth, but I think this looks really great now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants