-
Notifications
You must be signed in to change notification settings - Fork 22
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
Update compliance database schema #157
Conversation
controllers/complianceeventsapi/migrations/000001_compliance_history_initial_tables.up.sql
Outdated
Show resolved
Hide resolved
controllers/complianceeventsapi/migrations/000001_compliance_history_initial_tables.up.sql
Outdated
Show resolved
Hide resolved
@JustinKuli the latest commit makes the SQL queries static. Let me know what you think of this approach! |
// 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this 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)
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]>
@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. |
[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 |
/unhold Thanks (and sorry) for all the back-and-forth, but I think this looks really great now |
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.