Fix bugs, improve schema gen

This commit is contained in:
2026-10-14 01:47:55 +01:00
parent 2ddf450b9f
commit 155263a79f
25 changed files with 571 additions and 172 deletions
+28 -2
View File
@@ -307,15 +307,41 @@ type BUN_MARIADB_FieldSchemaType = {
### Foreign Key
```ts
type BUN_MARIADB_ForeignKeyRule =
| "CASCADE"
| "SET NULL"
| "RESTRICT"
| "NO ACTION";
interface BUN_MARIADB_ForeignKeyType {
foreignKeyName?: string;
destinationTableName?: string;
destinationTableColumnName?: string;
cascadeDelete?: boolean;
cascadeUpdate?: boolean;
cascadeDelete?: boolean; // shorthand for onDelete: "CASCADE"
cascadeUpdate?: boolean; // shorthand for onUpdate: "CASCADE"
onDelete?: BUN_MARIADB_ForeignKeyRule; // default RESTRICT
onUpdate?: BUN_MARIADB_ForeignKeyRule; // default RESTRICT
}
```
```ts
{
fieldName: "author_id",
dataType: "BIGINT",
foreignKey: {
foreignKeyName: "post_author_fk",
destinationTableName: "users",
destinationTableColumnName: "id",
onDelete: "SET NULL", // column must be nullable
},
}
```
- `onDelete` / `onUpdate` take precedence over the `cascadeDelete` / `cascadeUpdate` shorthands. The deprecated field-level `onDeleteLiteral` / `onDelete` are still honored as the FK's ON DELETE action when `foreignKey.onDelete` is not set.
- `SET NULL` on a `notNullValue` or primary key column is rejected when the schema syncs.
- Changing a rule on an existing FK drops and recreates the constraint. `NO ACTION` and `RESTRICT` are treated as the same rule, so switching between them causes no churn.
- Foreign keys are created after every table exists. Self references (e.g. `comments.parent_comment_id`), forward references and cycles between tables are all supported.
### Index
```ts