uql-orm 0.45.0 → 0.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -142,8 +142,7 @@ export class SqlSchemaGenerator {
142
142
  // Add new columns
143
143
  if (diff.columnsToAdd?.length) {
144
144
  for (const column of diff.columnsToAdd) {
145
- const colDef = this.generateColumnDefinitionFromSchema(column);
146
- statements.push(`ALTER TABLE ${tableName} ADD COLUMN ${colDef};`);
145
+ statements.push(`ALTER TABLE ${tableName} ADD COLUMN ${this.generateColumnDefinitionFromSchema(column)};`);
147
146
  }
148
147
  }
149
148
  // Alter existing columns
@@ -392,8 +391,17 @@ export class SqlSchemaGenerator {
392
391
  const columnDiffs = tableDiff?.columnDiffs ?? [];
393
392
  const columnsToAdd = columnDiffs.flatMap((it) => (it.type === 'add' ? [this.columnNodeToSchema(it.expected)] : []));
394
393
  const columnsToDrop = columnDiffs.flatMap((it) => (it.type === 'drop' ? [it.column] : []));
394
+ // Without its values: an alter restates the whole column, and MySQL answers a restated `CHECK` by
395
+ // adding a *second* constraint rather than replacing the first, so the column would accumulate one
396
+ // per alter. An enum's values reach the database with the column and are never restated - which is
397
+ // also why changing them is a hand-written migration. See architecture/roadmap.md.
395
398
  const columnsToAlter = columnDiffs.flatMap((it) => it.type === 'alter'
396
- ? [{ from: this.columnNodeToSchema(it.actual), to: this.columnNodeToSchema(it.expected) }]
399
+ ? [
400
+ {
401
+ from: this.columnNodeToSchema(it.actual),
402
+ to: { ...this.columnNodeToSchema(it.expected), enum: undefined },
403
+ },
404
+ ]
397
405
  : []);
398
406
  const primaryKey = tableDiff?.primaryKeyDiff && {
399
407
  from: tableDiff.primaryKeyDiff.actual,
@@ -472,6 +480,7 @@ export class SqlSchemaGenerator {
472
480
  isAutoIncrement: col.isAutoIncrement,
473
481
  isUnique: col.isUnique,
474
482
  comment: col.comment,
483
+ enum: col.enum,
475
484
  };
476
485
  }
477
486
  /**
@@ -2,7 +2,7 @@ import type { VectorCast } from '../dialect/vectorCast.js';
2
2
  import type { FullColumnDefinition, TableDefinition } from '../migrate/builder/types.js';
3
3
  import type { IndexFacet } from '../schema/indexDifferences.js';
4
4
  import type { SchemaAST } from '../schema/schemaAST.js';
5
- import type { ForeignKeyAction, IndexNode, IndexType, TableNode } from '../schema/types.js';
5
+ import type { EnumValues, ForeignKeyAction, IndexNode, IndexType, TableNode } from '../schema/types.js';
6
6
  import type { EntityMeta, FieldOptions, IndexColumnSchema, LoggingOptions, SqlQuerier, Type, VectorIndexOptions } from './index.js';
7
7
  /**
8
8
  * Defines a migration using a simple object literal
@@ -116,6 +116,13 @@ export interface ColumnSchema {
116
116
  readonly precision?: number;
117
117
  readonly scale?: number;
118
118
  readonly comment?: string;
119
+ /**
120
+ * The values the column accepts, rendered as an inline `CHECK`. Carried only so a column *added* to
121
+ * an existing table is constrained the way one created with its table is; an alter drops it, since
122
+ * MySQL adds a second check rather than replacing the first. Introspection never sets it: a database
123
+ * reports a check as a constraint, not as a property of the column.
124
+ */
125
+ readonly enum?: EnumValues;
119
126
  }
120
127
  /**
121
128
  * Represents a database table schema
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://uql-orm.dev",
4
4
  "description": "The JSON-native TypeScript ORM for Bun, Browsers, Edge, Deno, Node, Workers. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
5
5
  "license": "MIT",
6
- "version": "0.45.0",
6
+ "version": "0.45.1",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=24"