Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/web/src/lib/erd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ describe("ERDModel", () => {
).toThrowError("Column 'created__at' must be snake_case.");
});

it("should reject identifiers exceeding length limit", () => {
model.addTable("users");
const longName = "a".repeat(65);
expect(() =>
model.addColumn("users", { name: longName, type: "integer" }),
).toThrowError("Invalid length for Column identifier.");
});

it("should reject invalid SQL default values", () => {
model.addTable("users");
expect(() =>
Expand Down
5 changes: 5 additions & 0 deletions packages/web/src/lib/erd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ function assertSafeSqlDefaultValue(value: string): void {
}
}

const MAX_IDENTIFIER_LENGTH = 64;

function assertSnakeCaseIdentifier(kind: string, name: string): void {
if (name.length === 0 || name.length > MAX_IDENTIFIER_LENGTH) {
throw new Error(`Invalid length for ${kind} identifier.`);
}
if (!SNAKE_CASE_IDENTIFIER.test(name)) {
throw new Error(`${kind} '${name}' must be snake_case.`);
}
Expand Down
Loading