Skip to content

Commit d407dd7

Browse files
aksOpsclaude
andcommitted
feat(detector): SQL/migration detector + SQL_ENTITY NodeKind (#48)
Adds a SqlMigrationDetector under detector/sql that extracts schema-level entities (tables, views, schemas) from raw SQL DDL and framework-specific migration files: Flyway (V*__*.sql), Liquibase (XML + YAML), Alembic (versions/*.py with alembic/op marker guard), Rails (db/migrate/*.rb), and Prisma (migrations/*/migration.sql). Path/marker discriminators prevent false positives on arbitrary .py/.rb/.xml/.yml. Enum additions: - NodeKind.SQL_ENTITY (new): schema-level table/view/schema node, distinct from the code-level ENTITY (JPA/ORM) kind. - EdgeKind.REFERENCES_TABLE (new): any node (JPA ENTITY, ORM model, raw SQL_ENTITY) -> SQL_ENTITY, pairing with existing ORM detectors. - EdgeKind.MIGRATES (reused): MIGRATION -> SQL_ENTITY. Unused in production code elsewhere; only referenced by ModelCoverageTest. LayerClassifier: SQL_ENTITY classified as `infra`. Deterministic output (sorted by id on emit); detector is stateless. ALTER TABLE ADD COLUMN enriches the owning entity via columns_added property; did not model columns as child nodes to keep graph size reasonable. DROP TABLE is skipped with a debug log. Tests: 16 new tests covering positive paths (raw SQL, Flyway, Alembic, Liquibase XML, Liquibase YAML, Rails, Prisma), negative paths (plain .py/.yaml, Alembic path without marker), determinism, and DDL variants (DROP, CREATE INDEX, ALTER TABLE). Test count 3278 -> 3294. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 84e8e65 commit d407dd7

9 files changed

Lines changed: 937 additions & 11 deletions

File tree

src/main/java/io/github/randomcodespace/iq/analyzer/LayerClassifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public class LayerClassifier {
3636
);
3737

3838
private static final Set<NodeKind> INFRA_NODE_KINDS = Set.of(
39-
NodeKind.INFRA_RESOURCE, NodeKind.AZURE_RESOURCE, NodeKind.AZURE_FUNCTION
39+
NodeKind.INFRA_RESOURCE, NodeKind.AZURE_RESOURCE, NodeKind.AZURE_FUNCTION,
40+
NodeKind.SQL_ENTITY
4041
);
4142

4243
private static final Set<String> INFRA_LANGUAGES = Set.of(

src/main/java/io/github/randomcodespace/iq/detector/sql/SqlMigrationDetector.java

Lines changed: 542 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* SQL and migration detectors.
3+
* <p>
4+
* Extracts schema-level entities (tables, views, schemas) from raw SQL DDL and
5+
* framework-specific migration files (Flyway, Liquibase, Alembic, Rails, Prisma),
6+
* and links migrations to the SQL entities they create or alter.
7+
*/
8+
package io.github.randomcodespace.iq.detector.sql;

src/main/java/io/github/randomcodespace/iq/model/EdgeKind.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public enum EdgeKind {
3232
SENDS_TO("sends_to"),
3333
RECEIVES_FROM("receives_from"),
3434
PROTECTS("protects"),
35-
RENDERS("renders");
35+
RENDERS("renders"),
36+
REFERENCES_TABLE("references_table");
3637

3738
private final String value;
3839

src/main/java/io/github/randomcodespace/iq/model/NodeKind.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public enum NodeKind {
3838
MIDDLEWARE("middleware"),
3939
HOOK("hook"),
4040
SERVICE("service"),
41-
EXTERNAL("external");
41+
EXTERNAL("external"),
42+
SQL_ENTITY("sql_entity");
4243

4344
private final String value;
4445

0 commit comments

Comments
 (0)