arkormx 2.10.0 → 2.10.2

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.
package/dist/cli.mjs CHANGED
@@ -455,6 +455,15 @@ var EnumBuilder = class {
455
455
  this.tableBuilder.map(name, this.columnName);
456
456
  return this;
457
457
  }
458
+ /**
459
+ * Marks the enum column as an in-place change to an existing column.
460
+ *
461
+ * @returns
462
+ */
463
+ change() {
464
+ this.tableBuilder.change(this.columnName);
465
+ return this;
466
+ }
458
467
  };
459
468
  /**
460
469
  * The TableBuilder class provides a fluent interface for defining
@@ -467,6 +476,7 @@ var TableBuilder = class {
467
476
  constructor() {
468
477
  this.columns = [];
469
478
  this.dropColumnNames = [];
479
+ this.changeColumnNames = /* @__PURE__ */ new Set();
470
480
  this.indexes = [];
471
481
  this.foreignKeys = [];
472
482
  this.compositeUniqueConstraints = [];
@@ -780,6 +790,24 @@ var TableBuilder = class {
780
790
  return this;
781
791
  }
782
792
  /**
793
+ * Marks a (re)defined column as a change to an existing column rather than an
794
+ * addition. Use it at the end of a normal column chain inside `alterTable` to
795
+ * redefine the column's type, nullability, default, or enum values in place:
796
+ *
797
+ * ```ts
798
+ * table.string('status').default('active').change()
799
+ * table.enum('role', ['admin', 'user', 'guest']).change()
800
+ * ```
801
+ *
802
+ * @param columnName Optional explicit column name. When omitted, applies to the latest defined column.
803
+ * @returns The current TableBuilder instance for chaining.
804
+ */
805
+ change(columnName) {
806
+ const column = this.resolveColumn(columnName);
807
+ this.changeColumnNames.add(column.name);
808
+ return this;
809
+ }
810
+ /**
783
811
  * Marks a column as nullable.
784
812
  *
785
813
  * @param columnName Optional explicit column name. When omitted, applies to the latest defined column.
@@ -888,7 +916,18 @@ var TableBuilder = class {
888
916
  * @returns
889
917
  */
890
918
  getColumns() {
891
- return this.columns.map((column) => ({
919
+ return this.columns.filter((column) => !this.changeColumnNames.has(column.name)).map((column) => ({
920
+ ...column,
921
+ enumValues: column.enumValues ? [...column.enumValues] : void 0
922
+ }));
923
+ }
924
+ /**
925
+ * Returns a deep copy of the columns flagged for in-place change via `change()`.
926
+ *
927
+ * @returns
928
+ */
929
+ getChangeColumns() {
930
+ return this.columns.filter((column) => this.changeColumnNames.has(column.name)).map((column) => ({
892
931
  ...column,
893
932
  enumValues: column.enumValues ? [...column.enumValues] : void 0
894
933
  }));
@@ -1110,6 +1149,7 @@ var SchemaBuilder = class SchemaBuilder {
1110
1149
  type: "alterTable",
1111
1150
  table,
1112
1151
  addColumns: builder.getColumns(),
1152
+ changeColumns: builder.getChangeColumns(),
1113
1153
  dropColumns: builder.getDropColumns(),
1114
1154
  addIndexes: builder.getIndexes(),
1115
1155
  addForeignKeys: builder.getForeignKeys(),
@@ -1164,6 +1204,10 @@ var SchemaBuilder = class SchemaBuilder {
1164
1204
  ...column,
1165
1205
  enumValues: column.enumValues ? [...column.enumValues] : void 0
1166
1206
  })),
1207
+ changeColumns: operation.changeColumns?.map((column) => ({
1208
+ ...column,
1209
+ enumValues: column.enumValues ? [...column.enumValues] : void 0
1210
+ })),
1167
1211
  dropColumns: [...operation.dropColumns],
1168
1212
  addIndexes: operation.addIndexes.map((index) => ({
1169
1213
  ...index,
@@ -1667,11 +1711,18 @@ const applyCreateTableOperation = (schema, operation) => {
1667
1711
  const applyAlterTableOperation = (schema, operation) => {
1668
1712
  const model = findModelBlock(schema, operation.table);
1669
1713
  if (!model) throw new ArkormException(`Prisma model for table [${operation.table}] was not found.`);
1670
- const schemaWithEnums = ensureEnumBlocks(schema, operation.addColumns);
1714
+ const schemaWithEnums = ensureEnumBlocks(schema, [...operation.addColumns, ...operation.changeColumns ?? []]);
1671
1715
  const refreshedModel = findModelBlock(schemaWithEnums, operation.table);
1672
1716
  if (!refreshedModel) throw new ArkormException(`Prisma model for table [${operation.table}] was not found.`);
1673
1717
  let block = refreshedModel.block;
1674
1718
  const bodyLines = block.split("\n");
1719
+ (operation.changeColumns ?? []).forEach((column) => {
1720
+ const fieldLine = buildFieldLine(column);
1721
+ const columnRegex = new RegExp(`^\\s*${escapeRegex(column.name)}\\s+`);
1722
+ const index = bodyLines.findIndex((line) => columnRegex.test(line));
1723
+ if (index >= 0) bodyLines.splice(index, 1, fieldLine);
1724
+ else bodyLines.splice(Math.max(1, bodyLines.length - 1), 0, fieldLine);
1725
+ });
1675
1726
  operation.dropColumns.forEach((column) => {
1676
1727
  const columnRegex = new RegExp(`^\\s*${escapeRegex(column)}\\s+`);
1677
1728
  for (let index = 0; index < bodyLines.length; index += 1) if (columnRegex.test(bodyLines[index])) {
@@ -1896,14 +1947,18 @@ const stripPrismaSchemaModelsAndEnums = (schema) => {
1896
1947
  };
1897
1948
  const applyMigrationToDatabase = async (adapter, migration) => {
1898
1949
  if (!supportsDatabaseMigrationExecution(adapter)) throw new ArkormException("The configured adapter does not support database-backed migration execution.");
1899
- const operations = await getMigrationPlan(migration, "up");
1950
+ const instance = typeof migration === "function" ? new migration() : migration;
1951
+ const operations = await getMigrationPlan(instance, "up");
1900
1952
  await adapter.executeSchemaOperations(operations);
1953
+ await instance.done?.("up");
1901
1954
  return { operations };
1902
1955
  };
1903
1956
  const applyMigrationRollbackToDatabase = async (adapter, migration) => {
1904
1957
  if (!supportsDatabaseMigrationExecution(adapter)) throw new ArkormException("The configured adapter does not support database-backed migration execution.");
1905
- const operations = await getMigrationPlan(migration, "down");
1958
+ const instance = typeof migration === "function" ? new migration() : migration;
1959
+ const operations = await getMigrationPlan(instance, "down");
1906
1960
  await adapter.executeSchemaOperations(operations);
1961
+ await instance.done?.("down");
1907
1962
  return { operations };
1908
1963
  };
1909
1964
  /**
@@ -4173,6 +4228,14 @@ var Migration = class {
4173
4228
  static {
4174
4229
  this[MIGRATION_BRAND] = true;
4175
4230
  }
4231
+ /**
4232
+ * Optional lifecycle hook invoked after the migration's schema operations
4233
+ * have been applied to the database, for either direction. Override it to run
4234
+ * extra logic such as seeding or data backfills once the schema is in place.
4235
+ *
4236
+ * @param direction The direction that just ran (`'up'` or `'down'`).
4237
+ */
4238
+ done(_direction) {}
4176
4239
  };
4177
4240
 
4178
4241
  //#endregion
@@ -1,7 +1,7 @@
1
- import { Collection } from "@h3ravel/collect.js";
2
1
  import { Kysely, Transaction } from "kysely";
3
- import { Command } from "@h3ravel/musket";
4
2
  import { PrismaClient } from "@prisma/client";
3
+ import { Collection } from "@h3ravel/collect.js";
4
+ import { Command } from "@h3ravel/musket";
5
5
 
6
6
  //#region src/types/migrations.d.ts
7
7
  type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'decimal' | 'boolean' | 'json' | 'date' | 'dateTime' | 'timestamp';
@@ -70,6 +70,8 @@ interface SchemaTableAlterOperation {
70
70
  type: 'alterTable';
71
71
  table: string;
72
72
  addColumns: SchemaColumn[];
73
+ /** Columns whose definition (type, nullability, default, enum values) is being redefined in place. */
74
+ changeColumns?: SchemaColumn[];
73
75
  dropColumns: string[];
74
76
  addIndexes: SchemaIndex[];
75
77
  addForeignKeys: SchemaForeignKey[];
@@ -106,6 +108,7 @@ interface PrismaMigrationWorkflowOptions extends PrismaSchemaSyncOptions {
106
108
  type MigrationInstanceLike = {
107
109
  up: (...args: any[]) => Promise<void> | void;
108
110
  down: (...args: any[]) => Promise<void> | void;
111
+ done?: (direction: 'up' | 'down') => Promise<void> | void;
109
112
  };
110
113
  interface AppliedMigrationEntry {
111
114
  id: string;
@@ -2632,6 +2635,17 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2632
2635
  */
2633
2636
  fill(attributes: Partial<TAttributes>): this;
2634
2637
  fill(attributes: Record<string, unknown>): this;
2638
+ /**
2639
+ * Merge already-stored (database representation) attribute values into the
2640
+ * model without running set mutators or casts. Used to refresh the instance
2641
+ * from a row returned by a write, where the values are already in storage
2642
+ * form and must not be re-cast (re-applying a non-idempotent set-cast such as
2643
+ * a money or array cast would corrupt the value).
2644
+ *
2645
+ * @param attributes
2646
+ * @returns
2647
+ */
2648
+ protected fillRawAttributes(attributes: Record<string, unknown>): this;
2635
2649
  /**
2636
2650
  * Update the model's state in the database using data from a plain object.
2637
2651
  * If the model has no identifier (id), the process will be skipped and the
@@ -4450,34 +4464,26 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
4450
4464
  */
4451
4465
  upsert(values: Array<Record<string, unknown>>, uniqueBy: string | string[], update?: string[] | null): Promise<number>;
4452
4466
  /**
4453
- * Deletes the first record matching the current query constraints and returns
4454
- * it as a hydrated model instance. Returns null when no record matches.
4467
+ * Deletes every record matching the current query constraints and returns the
4468
+ * number of rows deleted (Laravel parity: `int delete()`). A where clause is
4469
+ * required — guarding against an accidental full-table delete.
4455
4470
  *
4456
- * @returns
4471
+ * @returns the count of deleted rows (0 when nothing matched)
4457
4472
  */
4458
- delete(): Promise<TModel | null>;
4473
+ delete(): Promise<number>;
4459
4474
  /**
4460
- * Hydrate a row that was just deleted, marking the resulting model as no
4461
- * longer existing in the database.
4475
+ * Deletes every record matching the current query constraints and throws when
4476
+ * none matched.
4462
4477
  *
4463
- * @param attributes
4464
- * @returns
4478
+ * @returns the count of deleted rows (always >= 1)
4465
4479
  */
4466
- private hydrateDeleted;
4467
- /**
4468
- * Deletes the first record matching the current query constraints and throws
4469
- * when no record matches.
4470
- *
4471
- * @returns
4472
- */
4473
- deleteOrFail(): Promise<TModel>;
4480
+ deleteOrFail(): Promise<number>;
4474
4481
  private tryBuildInsertSpec;
4475
4482
  private tryBuildInsertManySpec;
4476
4483
  private tryBuildUpsertSpec;
4477
4484
  private tryBuildInsertOrIgnoreManySpec;
4478
4485
  private tryBuildUpdateSpec;
4479
4486
  private tryBuildUpdateManySpec;
4480
- private tryBuildDeleteSpec;
4481
4487
  /**
4482
4488
  * Counts the number of records matching the current query constraints.
4483
4489
  *
@@ -4640,7 +4646,7 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
4640
4646
  private executeUpsertRows;
4641
4647
  private executeUpdateRow;
4642
4648
  private executeUpdateManyRows;
4643
- private executeDeleteRow;
4649
+ private executeDeleteManyRows;
4644
4650
  /**
4645
4651
  * Builds the where clause for the query, taking into account soft delete
4646
4652
  * settings if applicable.
@@ -5486,6 +5492,17 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
5486
5492
  private ensureEnumTypes;
5487
5493
  private executeCreateTableOperation;
5488
5494
  private executeAlterTableOperation;
5495
+ private enumTypeExists;
5496
+ /**
5497
+ * Redefine an existing column in place using ALTER COLUMN statements: the
5498
+ * column type (recreating the enum type when enum values change), nullability,
5499
+ * default, and a conventionally-named unique constraint.
5500
+ *
5501
+ * @param table
5502
+ * @param column
5503
+ * @param executor
5504
+ */
5505
+ private executeChangeColumn;
5489
5506
  private executeDropTableOperation;
5490
5507
  private ensureMigrationStateTables;
5491
5508
  private writeAppliedMigrationsStateInternal;
@@ -6701,6 +6718,12 @@ declare class EnumBuilder {
6701
6718
  * @returns
6702
6719
  */
6703
6720
  map(name: string): this;
6721
+ /**
6722
+ * Marks the enum column as an in-place change to an existing column.
6723
+ *
6724
+ * @returns
6725
+ */
6726
+ change(): this;
6704
6727
  }
6705
6728
  /**
6706
6729
  * The TableBuilder class provides a fluent interface for defining
@@ -6712,6 +6735,7 @@ declare class EnumBuilder {
6712
6735
  declare class TableBuilder {
6713
6736
  private readonly columns;
6714
6737
  private readonly dropColumnNames;
6738
+ private readonly changeColumnNames;
6715
6739
  private readonly indexes;
6716
6740
  private readonly foreignKeys;
6717
6741
  private readonly compositeUniqueConstraints;
@@ -6928,6 +6952,20 @@ declare class TableBuilder {
6928
6952
  * @returns
6929
6953
  */
6930
6954
  dropColumn(name: string): this;
6955
+ /**
6956
+ * Marks a (re)defined column as a change to an existing column rather than an
6957
+ * addition. Use it at the end of a normal column chain inside `alterTable` to
6958
+ * redefine the column's type, nullability, default, or enum values in place:
6959
+ *
6960
+ * ```ts
6961
+ * table.string('status').default('active').change()
6962
+ * table.enum('role', ['admin', 'user', 'guest']).change()
6963
+ * ```
6964
+ *
6965
+ * @param columnName Optional explicit column name. When omitted, applies to the latest defined column.
6966
+ * @returns The current TableBuilder instance for chaining.
6967
+ */
6968
+ change(columnName?: string): this;
6931
6969
  /**
6932
6970
  * Marks a column as nullable.
6933
6971
  *
@@ -6996,6 +7034,12 @@ declare class TableBuilder {
6996
7034
  * @returns
6997
7035
  */
6998
7036
  getColumns(): SchemaColumn[];
7037
+ /**
7038
+ * Returns a deep copy of the columns flagged for in-place change via `change()`.
7039
+ *
7040
+ * @returns
7041
+ */
7042
+ getChangeColumns(): SchemaColumn[];
6999
7043
  /**
7000
7044
  * Returns a copy of the defined column names to be dropped from the table.
7001
7045
  *
@@ -7149,6 +7193,14 @@ declare abstract class Migration {
7149
7193
  * @param schema A SchemaBuilder instance.
7150
7194
  */
7151
7195
  abstract down(schema: SchemaBuilder): Promise<void> | void;
7196
+ /**
7197
+ * Optional lifecycle hook invoked after the migration's schema operations
7198
+ * have been applied to the database, for either direction. Override it to run
7199
+ * extra logic such as seeding or data backfills once the schema is in place.
7200
+ *
7201
+ * @param direction The direction that just ran (`'up'` or `'down'`).
7202
+ */
7203
+ done(_direction: 'up' | 'down'): Promise<void> | void;
7152
7204
  }
7153
7205
  //#endregion
7154
7206
  //#region src/DB.d.ts
@@ -7598,15 +7650,15 @@ declare const generateMigrationFile: (name: string, options?: GenerateMigrationO
7598
7650
  * @param direction The direction of the migration to plan for ('up' or 'down').
7599
7651
  * @returns A promise that resolves to an array of schema operations that would be performed.
7600
7652
  */
7601
- declare const getMigrationPlan: (migration: Migration | (new () => Migration), direction?: "up" | "down") => Promise<SchemaOperation[]>;
7653
+ declare const getMigrationPlan: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), direction?: "up" | "down") => Promise<SchemaOperation[]>;
7602
7654
  declare const supportsDatabaseMigrationExecution: (adapter?: DatabaseAdapter) => adapter is DatabaseAdapter & Required<Pick<DatabaseAdapter, "executeSchemaOperations">>;
7603
7655
  declare const supportsDatabaseCreation: (adapter?: DatabaseAdapter) => adapter is DatabaseAdapter & Required<Pick<DatabaseAdapter, "createDatabaseFromError">>;
7604
7656
  declare const supportsDatabaseReset: (adapter?: DatabaseAdapter) => adapter is DatabaseAdapter & Required<Pick<DatabaseAdapter, "resetDatabase">>;
7605
7657
  declare const stripPrismaSchemaModelsAndEnums: (schema: string) => string;
7606
- declare const applyMigrationToDatabase: (adapter: DatabaseAdapter, migration: Migration | (new () => Migration)) => Promise<{
7658
+ declare const applyMigrationToDatabase: (adapter: DatabaseAdapter, migration: MigrationInstanceLike | (new () => MigrationInstanceLike)) => Promise<{
7607
7659
  operations: SchemaOperation[];
7608
7660
  }>;
7609
- declare const applyMigrationRollbackToDatabase: (adapter: DatabaseAdapter, migration: Migration | (new () => Migration)) => Promise<{
7661
+ declare const applyMigrationRollbackToDatabase: (adapter: DatabaseAdapter, migration: MigrationInstanceLike | (new () => MigrationInstanceLike)) => Promise<{
7610
7662
  operations: SchemaOperation[];
7611
7663
  }>;
7612
7664
  /**
@@ -7618,7 +7670,7 @@ declare const applyMigrationRollbackToDatabase: (adapter: DatabaseAdapter, migra
7618
7670
  * @param options Options for applying the migration, including schema path and write flag.
7619
7671
  * @returns A promise that resolves to an object containing the updated schema, schema path, and list of operations applied.
7620
7672
  */
7621
- declare const applyMigrationToPrismaSchema: (migration: Migration | (new () => Migration), options?: PrismaSchemaSyncOptions) => Promise<{
7673
+ declare const applyMigrationToPrismaSchema: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), options?: PrismaSchemaSyncOptions) => Promise<{
7622
7674
  schema: string;
7623
7675
  schemaPath: string;
7624
7676
  operations: SchemaOperation[];
@@ -7630,7 +7682,7 @@ declare const applyMigrationToPrismaSchema: (migration: Migration | (new () => M
7630
7682
  * @param options Options for applying the rollback, including schema path and write flag.
7631
7683
  * @returns A promise that resolves to an object containing the updated schema, schema path, and rollback operations applied.
7632
7684
  */
7633
- declare const applyMigrationRollbackToPrismaSchema: (migration: Migration | (new () => Migration), options?: PrismaSchemaSyncOptions) => Promise<{
7685
+ declare const applyMigrationRollbackToPrismaSchema: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), options?: PrismaSchemaSyncOptions) => Promise<{
7634
7686
  schema: string;
7635
7687
  schemaPath: string;
7636
7688
  operations: SchemaOperation[];
@@ -7644,7 +7696,7 @@ declare const applyMigrationRollbackToPrismaSchema: (migration: Migration | (new
7644
7696
  * @param options Options for running the migration, including schema path, write flag, and Prisma commands.
7645
7697
  * @returns A promise that resolves to an object containing the schema path and list of operations applied.
7646
7698
  */
7647
- declare const runMigrationWithPrisma: (migration: Migration | (new () => Migration), options?: PrismaMigrationWorkflowOptions) => Promise<{
7699
+ declare const runMigrationWithPrisma: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), options?: PrismaMigrationWorkflowOptions) => Promise<{
7648
7700
  schemaPath: string;
7649
7701
  operations: SchemaOperation[];
7650
7702
  }>;
@@ -1,7 +1,7 @@
1
- import { Kysely, Transaction } from "kysely";
2
- import { PrismaClient } from "@prisma/client";
3
1
  import { Collection } from "@h3ravel/collect.js";
2
+ import { Kysely, Transaction } from "kysely";
4
3
  import { Command } from "@h3ravel/musket";
4
+ import { PrismaClient } from "@prisma/client";
5
5
 
6
6
  //#region src/types/migrations.d.ts
7
7
  type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'decimal' | 'boolean' | 'json' | 'date' | 'dateTime' | 'timestamp';
@@ -70,6 +70,8 @@ interface SchemaTableAlterOperation {
70
70
  type: 'alterTable';
71
71
  table: string;
72
72
  addColumns: SchemaColumn[];
73
+ /** Columns whose definition (type, nullability, default, enum values) is being redefined in place. */
74
+ changeColumns?: SchemaColumn[];
73
75
  dropColumns: string[];
74
76
  addIndexes: SchemaIndex[];
75
77
  addForeignKeys: SchemaForeignKey[];
@@ -106,6 +108,7 @@ interface PrismaMigrationWorkflowOptions extends PrismaSchemaSyncOptions {
106
108
  type MigrationInstanceLike = {
107
109
  up: (...args: any[]) => Promise<void> | void;
108
110
  down: (...args: any[]) => Promise<void> | void;
111
+ done?: (direction: 'up' | 'down') => Promise<void> | void;
109
112
  };
110
113
  interface AppliedMigrationEntry {
111
114
  id: string;
@@ -2632,6 +2635,17 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2632
2635
  */
2633
2636
  fill(attributes: Partial<TAttributes>): this;
2634
2637
  fill(attributes: Record<string, unknown>): this;
2638
+ /**
2639
+ * Merge already-stored (database representation) attribute values into the
2640
+ * model without running set mutators or casts. Used to refresh the instance
2641
+ * from a row returned by a write, where the values are already in storage
2642
+ * form and must not be re-cast (re-applying a non-idempotent set-cast such as
2643
+ * a money or array cast would corrupt the value).
2644
+ *
2645
+ * @param attributes
2646
+ * @returns
2647
+ */
2648
+ protected fillRawAttributes(attributes: Record<string, unknown>): this;
2635
2649
  /**
2636
2650
  * Update the model's state in the database using data from a plain object.
2637
2651
  * If the model has no identifier (id), the process will be skipped and the
@@ -4450,34 +4464,26 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
4450
4464
  */
4451
4465
  upsert(values: Array<Record<string, unknown>>, uniqueBy: string | string[], update?: string[] | null): Promise<number>;
4452
4466
  /**
4453
- * Deletes the first record matching the current query constraints and returns
4454
- * it as a hydrated model instance. Returns null when no record matches.
4467
+ * Deletes every record matching the current query constraints and returns the
4468
+ * number of rows deleted (Laravel parity: `int delete()`). A where clause is
4469
+ * required — guarding against an accidental full-table delete.
4455
4470
  *
4456
- * @returns
4471
+ * @returns the count of deleted rows (0 when nothing matched)
4457
4472
  */
4458
- delete(): Promise<TModel | null>;
4473
+ delete(): Promise<number>;
4459
4474
  /**
4460
- * Hydrate a row that was just deleted, marking the resulting model as no
4461
- * longer existing in the database.
4475
+ * Deletes every record matching the current query constraints and throws when
4476
+ * none matched.
4462
4477
  *
4463
- * @param attributes
4464
- * @returns
4478
+ * @returns the count of deleted rows (always >= 1)
4465
4479
  */
4466
- private hydrateDeleted;
4467
- /**
4468
- * Deletes the first record matching the current query constraints and throws
4469
- * when no record matches.
4470
- *
4471
- * @returns
4472
- */
4473
- deleteOrFail(): Promise<TModel>;
4480
+ deleteOrFail(): Promise<number>;
4474
4481
  private tryBuildInsertSpec;
4475
4482
  private tryBuildInsertManySpec;
4476
4483
  private tryBuildUpsertSpec;
4477
4484
  private tryBuildInsertOrIgnoreManySpec;
4478
4485
  private tryBuildUpdateSpec;
4479
4486
  private tryBuildUpdateManySpec;
4480
- private tryBuildDeleteSpec;
4481
4487
  /**
4482
4488
  * Counts the number of records matching the current query constraints.
4483
4489
  *
@@ -4640,7 +4646,7 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
4640
4646
  private executeUpsertRows;
4641
4647
  private executeUpdateRow;
4642
4648
  private executeUpdateManyRows;
4643
- private executeDeleteRow;
4649
+ private executeDeleteManyRows;
4644
4650
  /**
4645
4651
  * Builds the where clause for the query, taking into account soft delete
4646
4652
  * settings if applicable.
@@ -5486,6 +5492,17 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
5486
5492
  private ensureEnumTypes;
5487
5493
  private executeCreateTableOperation;
5488
5494
  private executeAlterTableOperation;
5495
+ private enumTypeExists;
5496
+ /**
5497
+ * Redefine an existing column in place using ALTER COLUMN statements: the
5498
+ * column type (recreating the enum type when enum values change), nullability,
5499
+ * default, and a conventionally-named unique constraint.
5500
+ *
5501
+ * @param table
5502
+ * @param column
5503
+ * @param executor
5504
+ */
5505
+ private executeChangeColumn;
5489
5506
  private executeDropTableOperation;
5490
5507
  private ensureMigrationStateTables;
5491
5508
  private writeAppliedMigrationsStateInternal;
@@ -6701,6 +6718,12 @@ declare class EnumBuilder {
6701
6718
  * @returns
6702
6719
  */
6703
6720
  map(name: string): this;
6721
+ /**
6722
+ * Marks the enum column as an in-place change to an existing column.
6723
+ *
6724
+ * @returns
6725
+ */
6726
+ change(): this;
6704
6727
  }
6705
6728
  /**
6706
6729
  * The TableBuilder class provides a fluent interface for defining
@@ -6712,6 +6735,7 @@ declare class EnumBuilder {
6712
6735
  declare class TableBuilder {
6713
6736
  private readonly columns;
6714
6737
  private readonly dropColumnNames;
6738
+ private readonly changeColumnNames;
6715
6739
  private readonly indexes;
6716
6740
  private readonly foreignKeys;
6717
6741
  private readonly compositeUniqueConstraints;
@@ -6928,6 +6952,20 @@ declare class TableBuilder {
6928
6952
  * @returns
6929
6953
  */
6930
6954
  dropColumn(name: string): this;
6955
+ /**
6956
+ * Marks a (re)defined column as a change to an existing column rather than an
6957
+ * addition. Use it at the end of a normal column chain inside `alterTable` to
6958
+ * redefine the column's type, nullability, default, or enum values in place:
6959
+ *
6960
+ * ```ts
6961
+ * table.string('status').default('active').change()
6962
+ * table.enum('role', ['admin', 'user', 'guest']).change()
6963
+ * ```
6964
+ *
6965
+ * @param columnName Optional explicit column name. When omitted, applies to the latest defined column.
6966
+ * @returns The current TableBuilder instance for chaining.
6967
+ */
6968
+ change(columnName?: string): this;
6931
6969
  /**
6932
6970
  * Marks a column as nullable.
6933
6971
  *
@@ -6996,6 +7034,12 @@ declare class TableBuilder {
6996
7034
  * @returns
6997
7035
  */
6998
7036
  getColumns(): SchemaColumn[];
7037
+ /**
7038
+ * Returns a deep copy of the columns flagged for in-place change via `change()`.
7039
+ *
7040
+ * @returns
7041
+ */
7042
+ getChangeColumns(): SchemaColumn[];
6999
7043
  /**
7000
7044
  * Returns a copy of the defined column names to be dropped from the table.
7001
7045
  *
@@ -7149,6 +7193,14 @@ declare abstract class Migration {
7149
7193
  * @param schema A SchemaBuilder instance.
7150
7194
  */
7151
7195
  abstract down(schema: SchemaBuilder): Promise<void> | void;
7196
+ /**
7197
+ * Optional lifecycle hook invoked after the migration's schema operations
7198
+ * have been applied to the database, for either direction. Override it to run
7199
+ * extra logic such as seeding or data backfills once the schema is in place.
7200
+ *
7201
+ * @param direction The direction that just ran (`'up'` or `'down'`).
7202
+ */
7203
+ done(_direction: 'up' | 'down'): Promise<void> | void;
7152
7204
  }
7153
7205
  //#endregion
7154
7206
  //#region src/DB.d.ts
@@ -7598,15 +7650,15 @@ declare const generateMigrationFile: (name: string, options?: GenerateMigrationO
7598
7650
  * @param direction The direction of the migration to plan for ('up' or 'down').
7599
7651
  * @returns A promise that resolves to an array of schema operations that would be performed.
7600
7652
  */
7601
- declare const getMigrationPlan: (migration: Migration | (new () => Migration), direction?: "up" | "down") => Promise<SchemaOperation[]>;
7653
+ declare const getMigrationPlan: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), direction?: "up" | "down") => Promise<SchemaOperation[]>;
7602
7654
  declare const supportsDatabaseMigrationExecution: (adapter?: DatabaseAdapter) => adapter is DatabaseAdapter & Required<Pick<DatabaseAdapter, "executeSchemaOperations">>;
7603
7655
  declare const supportsDatabaseCreation: (adapter?: DatabaseAdapter) => adapter is DatabaseAdapter & Required<Pick<DatabaseAdapter, "createDatabaseFromError">>;
7604
7656
  declare const supportsDatabaseReset: (adapter?: DatabaseAdapter) => adapter is DatabaseAdapter & Required<Pick<DatabaseAdapter, "resetDatabase">>;
7605
7657
  declare const stripPrismaSchemaModelsAndEnums: (schema: string) => string;
7606
- declare const applyMigrationToDatabase: (adapter: DatabaseAdapter, migration: Migration | (new () => Migration)) => Promise<{
7658
+ declare const applyMigrationToDatabase: (adapter: DatabaseAdapter, migration: MigrationInstanceLike | (new () => MigrationInstanceLike)) => Promise<{
7607
7659
  operations: SchemaOperation[];
7608
7660
  }>;
7609
- declare const applyMigrationRollbackToDatabase: (adapter: DatabaseAdapter, migration: Migration | (new () => Migration)) => Promise<{
7661
+ declare const applyMigrationRollbackToDatabase: (adapter: DatabaseAdapter, migration: MigrationInstanceLike | (new () => MigrationInstanceLike)) => Promise<{
7610
7662
  operations: SchemaOperation[];
7611
7663
  }>;
7612
7664
  /**
@@ -7618,7 +7670,7 @@ declare const applyMigrationRollbackToDatabase: (adapter: DatabaseAdapter, migra
7618
7670
  * @param options Options for applying the migration, including schema path and write flag.
7619
7671
  * @returns A promise that resolves to an object containing the updated schema, schema path, and list of operations applied.
7620
7672
  */
7621
- declare const applyMigrationToPrismaSchema: (migration: Migration | (new () => Migration), options?: PrismaSchemaSyncOptions) => Promise<{
7673
+ declare const applyMigrationToPrismaSchema: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), options?: PrismaSchemaSyncOptions) => Promise<{
7622
7674
  schema: string;
7623
7675
  schemaPath: string;
7624
7676
  operations: SchemaOperation[];
@@ -7630,7 +7682,7 @@ declare const applyMigrationToPrismaSchema: (migration: Migration | (new () => M
7630
7682
  * @param options Options for applying the rollback, including schema path and write flag.
7631
7683
  * @returns A promise that resolves to an object containing the updated schema, schema path, and rollback operations applied.
7632
7684
  */
7633
- declare const applyMigrationRollbackToPrismaSchema: (migration: Migration | (new () => Migration), options?: PrismaSchemaSyncOptions) => Promise<{
7685
+ declare const applyMigrationRollbackToPrismaSchema: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), options?: PrismaSchemaSyncOptions) => Promise<{
7634
7686
  schema: string;
7635
7687
  schemaPath: string;
7636
7688
  operations: SchemaOperation[];
@@ -7644,7 +7696,7 @@ declare const applyMigrationRollbackToPrismaSchema: (migration: Migration | (new
7644
7696
  * @param options Options for running the migration, including schema path, write flag, and Prisma commands.
7645
7697
  * @returns A promise that resolves to an object containing the schema path and list of operations applied.
7646
7698
  */
7647
- declare const runMigrationWithPrisma: (migration: Migration | (new () => Migration), options?: PrismaMigrationWorkflowOptions) => Promise<{
7699
+ declare const runMigrationWithPrisma: (migration: MigrationInstanceLike | (new () => MigrationInstanceLike), options?: PrismaMigrationWorkflowOptions) => Promise<{
7648
7700
  schemaPath: string;
7649
7701
  operations: SchemaOperation[];
7650
7702
  }>;