๐ก๏ธ Sentinel: [๊ธฐ๋ฅ ํฅ์] ERD ์์ง๋์ด๋ง ๋๊ตฌ ๊ธฐ๋ฅ ํ์ฅ ๋ฐ ์ฐธ์กฐ ๋ฌด๊ฒฐ์ฑ ๊ฒ์ฆ ์ถ๊ฐ#295
Conversation
|
๐ Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a ๐ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
Expands the in-memory ERD modeling utility (ERDModel) used in @argos/web to support schema element deletion (tables/columns/foreign keys), enforce referential-integrity constraints during deletion, and generate Mermaid ER diagram output for visualization.
Changes:
- Added
removeTable,removeColumn, andremoveForeignKeywith defensive referential-integrity checks. - Added
generateMermaid()to emit MermaiderDiagramoutput including PK/FK annotations and relationships. - Added Vitest coverage for removal operations and Mermaid generation; documented the security/learning note in
.jules/sentinel.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/web/src/lib/erd.ts | Adds removal APIs with integrity checks and Mermaid diagram generation. |
| packages/web/src/lib/erd.test.ts | Adds unit tests covering removals and Mermaid output formatting. |
| .jules/sentinel.md | Records a sentinel entry about referential-integrity validation for ERD deletions. |
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| removeTable(name: string): void { | ||
| const table = this.tables.get(name) | ||
| if (!table) { | ||
| throw new Error(`Table '${name}' does not exist.`) | ||
| } |
| // Cannot remove if referenced by another table | ||
| for (const t of this.tables.values()) { | ||
| for (const fk of t.foreignKeys) { | ||
| if (fk.referenceTable === name) { | ||
| throw new Error(`Cannot remove table '${name}' because it is referenced by '${t.name}'.`) | ||
| } | ||
| } | ||
| } |
| removeColumn(tableName: string, columnName: string): void { | ||
| const table = this.tables.get(tableName) | ||
| if (!table) { | ||
| throw new Error(`Table '${tableName}' does not exist.`) | ||
| } |
| removeForeignKey(tableName: string, columnName: string, referenceTable: string, referenceColumn: string): void { | ||
| const table = this.tables.get(tableName) | ||
| if (!table) { | ||
| throw new Error(`Table '${tableName}' does not exist.`) | ||
| } |
| // Add relationships | ||
| for (const table of this.tables.values()) { | ||
| for (const fk of table.foreignKeys) { | ||
| mermaid += ` ${table.name} ||--o{ ${fk.referenceTable} : "${fk.columnName} references ${fk.referenceColumn}"\n` |
| SERIAL id PK | ||
| INTEGER user_id FK | ||
| } | ||
| posts ||--o{ users : "user_id references id"` |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Comments suppressed due to low confidence (3)
packages/web/src/lib/erd.ts:96
removeTableis intended to block deletion when another table references the target, but the current scan also includes the table being removed. This makes it impossible to remove a table that has a self-referential foreign key (e.g., hierarchical tables), even though deleting the table would remove those FKs as well.
// Cannot remove if referenced by another table
for (const t of this.tables.values()) {
for (const fk of t.foreignKeys) {
if (fk.referenceTable === name) {
throw new Error(`Cannot remove table '${name}' because it is referenced by '${t.name}'.`)
}
packages/web/src/lib/erd.ts:164
generateMermaidcurrently emits relationships as${table.name} ||--o{ ${fk.referenceTable}, butgenerateDDLdefines the FK asFOREIGN KEY (...) REFERENCES referenceTable(...)(i.e., the referenceTable is the parent / "one" side). The Mermaid relationship direction is reversed relative to the FK semantics.
// Add relationships
for (const table of this.tables.values()) {
for (const fk of table.foreignKeys) {
mermaid += ` ${table.name} ||--o{ ${fk.referenceTable} : "${fk.columnName} references ${fk.referenceColumn}"\n`
}
packages/web/src/lib/erd.test.ts:285
- The Mermaid relationship assertion expects
posts ||--o{ users, but the FK semantics in this test areposts.user_idreferencingusers.id, so the||--o{one-to-many direction should beusers ||--o{ posts(users has many posts). Update the expected string to match the corrected Mermaid output.
const mermaid = model.generateMermaid()
const expected = `erDiagram
users {
SERIAL id PK
VARCHAR(255) name
}
posts {
SERIAL id PK
INTEGER user_id FK
}
posts ||--o{ users : "user_id references id"`
expect(mermaid).toBe(expected)
| "hono": "4.12.27", | ||
| "js-yaml": "4.3.0", | ||
| "@hono/node-server": "^2.0.5", | ||
| "body-parser": "^2.3.0", | ||
| "brace-expansion": "^2.0.1", | ||
| "fast-uri": "^3.1.3" |
| "@hono/node-server": "^2.0.5", | ||
| "body-parser": "^2.3.0", | ||
| "brace-expansion": "^2.0.1", | ||
| "fast-uri": "^3.1.3" |
๐จ ์ฌ๊ฐ๋: ํฅ์
๐ก ์ทจ์ฝ์ ๋ฐ ๊ฐ์ ์ฌํญ:
๊ธฐ์กด ERD ๋๊ตฌ์๋ ํ ์ด๋ธ, ์ปฌ๋ผ, ์ธ๋ ํค๋ฅผ ์ ๊ฑฐํ๋ ๊ธฐ๋ฅ์ด ์์์ผ๋ฉฐ, ์๊ฐํ๋ฅผ ์ํ Mermaid ํํ์ ์ถ๋ ฅ ๊ธฐ๋ฅ๋ ๋ถ์ฌํ์ต๋๋ค. ํนํ ์ ๊ฑฐ ๊ธฐ๋ฅ ๋ถ์ฌ ์ ๋ชจ๋ธ์ ์ฌ์์ฑํด์ผ ํ๋ ๋ถํธํจ๊ณผ ํจ๊ป, ์ฐธ์กฐ ์ค์ธ ์ํฐํฐ๊ฐ ๋ถ์์ ํ ์ํ๋ก ์ญ์ ๋๋ '์ฐธ์กฐ ๋ฌด๊ฒฐ์ฑ ์๋ฐ' ์ํ๊ฐ ๋ฐ์ํ ๊ฐ๋ฅ์ฑ์ด ์์์ต๋๋ค.
๐ฏ ์ํฅ:
์ฐธ์กฐ ๋ฌด๊ฒฐ์ฑ์ด ํ๋ณด๋์ง ์์ผ๋ฉด ๋๋ฉ์ธ ์ค๊ณ ์ ๋ฐ์ดํฐ ๋ถ์ผ์น๊ฐ ๋ฐ์ํ ์ ์์ผ๋ฉฐ, ์ด๋ ํ์ DDL ์คํฌ๋ฆฝํธ ์คํ ์ ๋ฐํ์ ์๋ฌ๋ ์์์น ๋ชปํ ๋ณด์์ ์ ์ฉ ๊ฐ๋ฅํ ์ฃ์ง ์ผ์ด์ค๋ฅผ ์ ๋ฐํ ์ ์์ต๋๋ค.
๐ง ํด๊ฒฐ ๋ฐฉ์:
removeTable,removeColumn,removeForeignKey๋ฉ์๋ ์ถ๊ฐgenerateMermaid๋ฉ์๋๋ฅผ ํตํด ์๊ฐํ ๊ธฐ๋ฅ ์ง์โ ๊ฒ์ฆ ๋ฐฉ๋ฒ:
pnpm coverage:erd)PR created automatically by Jules for task 17449793604625455777 started by @seonghobae