HMS-10821: create template advisories table#2234
Merged
TenSt merged 1 commit intoJun 17, 2026
Merged
Conversation
Reviewer's GuideIntroduces a new partitioned template_advisory join table between templates and advisory_metadata, wires it into the GORM data model, and updates schema/migrations and table-size tests to account for the new table and its partitions. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In the
TemplateAdvisorymodel, consider adding explicit GORM tags for theAdvisoryrelationship (e.g.,foreignKey:AdvisoryID;references:ID) so that the ORM correctly wires the association toadvisory_metadatarather than relying on default naming. - The down migration simply
DROPstemplate_advisory; if your partition helper creates child tables explicitly, confirm that dropping the parent will clean up all partitions as expected or call the corresponding drop-partitions helper to avoid leaving orphaned partition tables.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the `TemplateAdvisory` model, consider adding explicit GORM tags for the `Advisory` relationship (e.g., `foreignKey:AdvisoryID;references:ID`) so that the ORM correctly wires the association to `advisory_metadata` rather than relying on default naming.
- The down migration simply `DROP`s `template_advisory`; if your partition helper creates child tables explicitly, confirm that dropping the parent will clean up all partitions as expected or call the corresponding drop-partitions helper to avoid leaving orphaned partition tables.
## Individual Comments
### Comment 1
<location path="database_admin/schema/create_schema.sql" line_range="800-801" />
<code_context>
+ CONSTRAINT template_advisory_template_id
+ FOREIGN KEY (rh_account_id, template_id)
+ REFERENCES template (rh_account_id, id) ON DELETE CASCADE,
+ CONSTRAINT template_advisory_advisory_id
+ FOREIGN KEY (advisory_id)
+ REFERENCES advisory_metadata (id)
+) PARTITION BY HASH (rh_account_id);
</code_context>
<issue_to_address>
**question (bug_risk):** Consider whether `advisory_id` should cascade on delete to avoid blocking advisory deletions.
`template_advisory_template_id` uses `ON DELETE CASCADE`, but `template_advisory_advisory_id` does not. As a result, deleting an `advisory_metadata` row will fail if related `template_advisory` rows exist. If you want those rows cleaned up automatically, add `ON DELETE CASCADE` here as well; otherwise, confirm callers correctly handle constraint violations when deletes are blocked.
</issue_to_address>
### Comment 2
<location path="base/models/models.go" line_range="55-60" />
<code_context>
return "template"
}
+type TemplateAdvisory struct {
+ RhAccountID int `gorm:"primaryKey"`
+ TemplateID int64 `gorm:"primaryKey"`
+ AdvisoryID int64 `gorm:"primaryKey"`
+ Advisory AdvisoryMetadata
+}
+
</code_context>
<issue_to_address>
**suggestion:** Clarify the GORM relationship configuration for the `Advisory` field.
GORM will infer the `Advisory`–`AdvisoryID` relationship by name, but there are no explicit `gorm` tags for this association. For predictable `Preload("Advisory")`/joins and to future-proof against naming changes, consider making it explicit, e.g.:
```go
Advisory AdvisoryMetadata `gorm:"foreignKey:AdvisoryID;references:ID"`
```
```suggestion
type TemplateAdvisory struct {
RhAccountID int `gorm:"primaryKey"`
TemplateID int64 `gorm:"primaryKey"`
AdvisoryID int64 `gorm:"primaryKey"`
Advisory AdvisoryMetadata `gorm:"foreignKey:AdvisoryID;references:ID"`
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2234 +/- ##
==========================================
- Coverage 59.07% 59.03% -0.05%
==========================================
Files 138 138
Lines 8845 8848 +3
==========================================
- Hits 5225 5223 -2
- Misses 3074 3079 +5
Partials 546 546
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e4eefb6 to
c2c1e63
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
template_advisorytable to store template↔advisory associations (one row per pair, keyed byrh_account_id,template_id,advisory_id)(rh_account_id, advisory_id)for reverse lookups by advisoryrh_account_id(16 partitions, matchingtemplate) with FKs totemplate(CASCADE on delete) and advisory_metadataTemplateAdvisorymodelTestTableSizesexpected table count for the new partitioned tableSummary by Sourcery
Introduce a partitioned template_advisory table to store associations between templates and advisories and expose it via a new GORM model.
New Features:
Build:
Tests: