refactor(platform): Extract a per-engine CatalogDialect#9
Conversation
|
Warning Review limit reached
Next review available in: 58 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughIntroduces a ChangesCatalogDialect refactor
Estimated code review effort: 3 (Moderate) | ~30 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoRefactor: extract per-engine CatalogDialect for catalog audit SQL
AI Description
Diagram
High-Level Assessment
Files changed (13)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
22 rules 1.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/java/io/github/databaseaudits/platform/DatabasePlatform.java (1)
45-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTwo
MysqlCatalogDialectinstances for MariaDB/MySQL.Since the dialect is stateless, consider sharing one instance between
MARIADBandMYSQLinstead of instantiating twice.♻️ Suggested tweak
+ private static final MysqlCatalogDialect MYSQL_DIALECT = new MysqlCatalogDialect(); + ... - MARIADB(new MysqlCatalogDialect()), + MARIADB(MYSQL_DIALECT), ... - MYSQL(new MysqlCatalogDialect()), + MYSQL(MYSQL_DIALECT),Also applies to: 48-48
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/io/github/databaseaudits/platform/DatabasePlatform.java` at line 45, The DatabasePlatform enum currently creates two separate MysqlCatalogDialect instances for MARIADB and MYSQL even though the dialect is stateless. Update DatabasePlatform so both enum constants reuse a shared MysqlCatalogDialect instance, and verify any constructor or field setup in DatabasePlatform still exposes the same behavior for both MARIADB and MYSQL.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/io/github/databaseaudits/platform/H2CatalogDialect.java`:
- Around line 64-98: The H2 type rendering in foreignKeyColumnTypesSql() only
uses data_type and character_maximum_length, so precision-sensitive numeric
types are flattened and mismatches can be missed. Update the SQL in
H2CatalogDialect.foreignKeyColumnTypesSql() to render numeric types with
numeric_precision and numeric_scale (while preserving existing length handling
for text types) for both column_type and referenced_type so
ForeignKeyTypeMatchAudit compares the full type signature.
In `@src/test/java/io/github/databaseaudits/platform/DatabasePlatformTest.java`:
- Around line 68-79: The assertions in
DatabasePlatformTest.testCatalogDialect_EachPlatform_HoldsItsDialectType should
all include AssertJ .as() fail messages ending with a period, not just the
MariaDB check. Update the PostgreSQL, MYSQL, and H2 catalogDialect() assertions
to add clear descriptive .as() messages so each assertion has consistent failure
context.
---
Nitpick comments:
In `@src/main/java/io/github/databaseaudits/platform/DatabasePlatform.java`:
- Line 45: The DatabasePlatform enum currently creates two separate
MysqlCatalogDialect instances for MARIADB and MYSQL even though the dialect is
stateless. Update DatabasePlatform so both enum constants reuse a shared
MysqlCatalogDialect instance, and verify any constructor or field setup in
DatabasePlatform still exposes the same behavior for both MARIADB and MYSQL.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b70c04d0-cb40-4d97-9f93-5aafc106aaf6
📒 Files selected for processing (13)
src/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyIndexAudit.javasrc/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyNotNullAudit.javasrc/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyTypeMatchAudit.javasrc/main/java/io/github/databaseaudits/audit/catalog/PrimaryKeyPresenceAudit.javasrc/main/java/io/github/databaseaudits/catalog/IndexCatalog.javasrc/main/java/io/github/databaseaudits/platform/CatalogDialect.javasrc/main/java/io/github/databaseaudits/platform/DatabasePlatform.javasrc/main/java/io/github/databaseaudits/platform/H2CatalogDialect.javasrc/main/java/io/github/databaseaudits/platform/MysqlCatalogDialect.javasrc/main/java/io/github/databaseaudits/platform/PostgresqlCatalogDialect.javasrc/site/asciidoc/architecture.adocsrc/test/java/io/github/databaseaudits/platform/CatalogDialectTest.javasrc/test/java/io/github/databaseaudits/platform/DatabasePlatformTest.java
Move the catalog audits' per-platform SQL out of exhaustive switches and *_SQL constants scattered across IndexCatalog and the four catalog audits into a CatalogDialect held by each DatabasePlatform constant. IndexCatalog and the audits now ask platform.catalogDialect() for their SQL instead of switching on the platform. * Add CatalogDialect: abstract methods for the SQL that genuinely diverges between engines (indexCatalogSql, foreignKeysSql, foreignKeyColumnTypesSql) — a new dialect will not compile until it supplies all three, preserving the exhaustive-switch completeness guarantee — and default methods for the standard information_schema SQL every engine shares (tablesWithoutPrimaryKeySql, nullableForeignKeyColumnSql). * Add PostgresqlCatalogDialect, MysqlCatalogDialect, H2CatalogDialect; MARIADB reuses MysqlCatalogDialect. DatabasePlatform holds one dialect per constant and exposes catalogDialect(). * Replace the *_SQL constants + sql() switches in IndexCatalog, ForeignKeyIndexAudit, ForeignKeyTypeMatchAudit, ForeignKeyNotNullAudit, and PrimaryKeyPresenceAudit with platform.catalogDialect() calls. The audits still take a DatabasePlatform, so callers (including the spring-boot DatabaseAuditSuite) are unchanged; QueryPlanExplainer's PostgreSQL-only guard is untouched. * Add CatalogDialectTest; extend DatabasePlatformTest to assert each constant's dialect type. The existing catalog audit and IndexCatalog tests pass unchanged (the SQL text is identical), and CatalogAuditsIT stays green on all four engines. * Update the "add a platform" narrative in DatabasePlatform javadoc and architecture.adoc. Completes WS1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0141skitWw3Cdgkf2kP3vve6
bcd5a54 to
49e1c2e
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/test/java/io/github/databaseaudits/platform/H2CatalogDialectIT.java (1)
26-54: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winNo exclusion-pass case in this IT.
Per path instructions, each audit IT should report the planted violation then pass once excluded, to guard against a vacuously green audit. This class only covers report/no-mismatch, not exclusion of the planted decimal mismatch. If exclusion behavior for
ForeignKeyTypeMatchAuditis already fully exercised inCatalogAuditsIT, this narrower dialect-focused test may be an acceptable exception — please confirm.As per path instructions, "Each audit must be verified against planted violations: REPORT the planted violation, then PASS once it is excluded — a vacuously green audit is a bug."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/io/github/databaseaudits/platform/H2CatalogDialectIT.java` around lines 26 - 54, Add an exclusion-pass assertion to H2CatalogDialectIT for ForeignKeyTypeMatchAudit so the planted decimal mismatch is first reported and then excluded; use the existing testForeignKeyTypeMatchAudit_DecimalPrecisionMismatchOnH2_ReportsBothTypesWithPrecisionAndScale setup with audit.audit("PUBLIC", Set.of(...)) to verify it becomes empty after excluding the planted violation, while keeping the equal-type test intact.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/test/java/io/github/databaseaudits/platform/H2CatalogDialectIT.java`:
- Around line 26-54: Add an exclusion-pass assertion to H2CatalogDialectIT for
ForeignKeyTypeMatchAudit so the planted decimal mismatch is first reported and
then excluded; use the existing
testForeignKeyTypeMatchAudit_DecimalPrecisionMismatchOnH2_ReportsBothTypesWithPrecisionAndScale
setup with audit.audit("PUBLIC", Set.of(...)) to verify it becomes empty after
excluding the planted violation, while keeping the equal-type test intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f7697c85-6d6e-4de3-b949-a07c821cb3ac
📒 Files selected for processing (17)
src/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyIndexAudit.javasrc/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyNotNullAudit.javasrc/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyTypeMatchAudit.javasrc/main/java/io/github/databaseaudits/audit/catalog/PrimaryKeyPresenceAudit.javasrc/main/java/io/github/databaseaudits/catalog/IndexCatalog.javasrc/main/java/io/github/databaseaudits/platform/CatalogDialect.javasrc/main/java/io/github/databaseaudits/platform/DatabasePlatform.javasrc/main/java/io/github/databaseaudits/platform/H2CatalogDialect.javasrc/main/java/io/github/databaseaudits/platform/MysqlCatalogDialect.javasrc/main/java/io/github/databaseaudits/platform/PostgresqlCatalogDialect.javasrc/site/asciidoc/adding-a-database.adocsrc/site/asciidoc/adding-an-audit.adocsrc/site/asciidoc/architecture.adocsrc/site/site.xmlsrc/test/java/io/github/databaseaudits/platform/CatalogDialectTest.javasrc/test/java/io/github/databaseaudits/platform/DatabasePlatformTest.javasrc/test/java/io/github/databaseaudits/platform/H2CatalogDialectIT.java
✅ Files skipped from review due to trivial changes (2)
- src/site/asciidoc/architecture.adoc
- src/site/asciidoc/adding-an-audit.adoc
🚧 Files skipped from review as they are similar to previous changes (12)
- src/test/java/io/github/databaseaudits/platform/CatalogDialectTest.java
- src/main/java/io/github/databaseaudits/platform/CatalogDialect.java
- src/main/java/io/github/databaseaudits/platform/PostgresqlCatalogDialect.java
- src/main/java/io/github/databaseaudits/platform/H2CatalogDialect.java
- src/test/java/io/github/databaseaudits/platform/DatabasePlatformTest.java
- src/main/java/io/github/databaseaudits/platform/MysqlCatalogDialect.java
- src/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyNotNullAudit.java
- src/main/java/io/github/databaseaudits/catalog/IndexCatalog.java
- src/main/java/io/github/databaseaudits/audit/catalog/PrimaryKeyPresenceAudit.java
- src/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyIndexAudit.java
- src/main/java/io/github/databaseaudits/platform/DatabasePlatform.java
- src/main/java/io/github/databaseaudits/audit/catalog/ForeignKeyTypeMatchAudit.java
The asciidoctor-parser doxia module drops inline NOTE/TIP/WARNING bodies (it logs "Fallback behaviour for node: admonition"), so the text never reached the rendered site. Convert the ForeignKeyIndex note to a bold "*Note:*" lead-in paragraph — matching the extending guides — so the content shows. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UEuiBscyCyDrtzszMwiAo8
The plan-based audits matched PostgreSQL EXPLAIN field names ("Node Type",
"Relation Name", "Plans", …) and node-type values ("Seq Scan", "Sort",
"Nested Loop", …) as repeated string literals across the three audits and their
shared template. Extract them into a package-private PlanJson holder so the
production detection logic carries no duplicated magic strings.
The audit unit tests build their fixture plans as literal JSON text, where a
Java constant cannot sit inside a JSON string literal, so they are intentionally
left unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UEuiBscyCyDrtzszMwiAo8
Extracts the catalog audits' per-engine SQL into a
CatalogDialectheld by eachDatabasePlatformconstant, so adding a database engine no longer means editing an exhaustiveswitchin five classes. Scaling-plan WS1; behavior-preserving.CatalogDialect: abstract methods for the SQL that genuinely diverges between engines (indexCatalogSql,foreignKeysSql,foreignKeyColumnTypesSql) — a new dialect won't compile until it supplies all three, keeping the exhaustive-switch completeness guarantee — and default methods for the standardinformation_schemaSQL every engine shares (tablesWithoutPrimaryKeySql,nullableForeignKeyColumnSql).PostgresqlCatalogDialect,MysqlCatalogDialect,H2CatalogDialect;MARIADBreusesMysqlCatalogDialect.DatabasePlatformholds one dialect per constant and exposescatalogDialect().IndexCatalogand the four catalog audits drop their*_SQLconstants +sql()switches forplatform.catalogDialect().…()calls. The audits still take aDatabasePlatform, so callers (including the spring-bootDatabaseAuditSuite) are unchanged;QueryPlanExplainer's PostgreSQL-only guard is untouched.CatalogDialectTest; extendedDatabasePlatformTestto assert each constant's dialect type.The SQL text moved verbatim: every existing catalog audit /
IndexCatalogtest passes unchanged, andCatalogAuditsITis green on all four engines (mvnw clean install).🤖 Generated with Claude Code
https://claude.ai/code/session_0141skitWw3Cdgkf2kP3vve6
Summary by CodeRabbit
New Features
Refactor
Bug Fixes
Tests
Documentation