arkormx 2.0.0-next.14 → 2.0.0-next.16
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/index.cjs +42 -14
- package/dist/index.d.cts +9 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +42 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -149,10 +149,13 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
149
149
|
resolveSchemaForeignKeyName(table, foreignKey) {
|
|
150
150
|
return `${table}_${foreignKey.column}_fkey`;
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
resolveSchemaEnumName(table, column) {
|
|
153
|
+
return column.enumName ?? `${table}_${column.name}_enum`;
|
|
154
|
+
}
|
|
155
|
+
resolveSchemaColumnType(table, column) {
|
|
153
156
|
if (column.type === "id") return "integer";
|
|
154
157
|
if (column.type === "uuid") return "uuid";
|
|
155
|
-
if (column.type === "enum") return this.quoteIdentifier(
|
|
158
|
+
if (column.type === "enum") return this.quoteIdentifier(this.resolveSchemaEnumName(table, column));
|
|
156
159
|
if (column.type === "string") return "varchar(255)";
|
|
157
160
|
if (column.type === "text") return "text";
|
|
158
161
|
if (column.type === "integer") return "integer";
|
|
@@ -175,8 +178,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
175
178
|
if (column.type === "id") return column.default === void 0;
|
|
176
179
|
return column.autoIncrement === true;
|
|
177
180
|
}
|
|
178
|
-
buildSchemaColumnDefinition(column) {
|
|
179
|
-
const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(column)];
|
|
181
|
+
buildSchemaColumnDefinition(table, column) {
|
|
182
|
+
const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(table, column)];
|
|
180
183
|
if (this.shouldUseIdentity(column)) parts.push("generated by default as identity");
|
|
181
184
|
const defaultValue = this.resolveSchemaColumnDefault(column);
|
|
182
185
|
if (defaultValue && !this.shouldUseIdentity(column)) parts.push(`default ${defaultValue}`);
|
|
@@ -195,10 +198,10 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
195
198
|
const mappedColumns = index.columns.map((column) => this.quoteIdentifier(this.resolveSchemaColumnName(column, columns))).join(", ");
|
|
196
199
|
return `create index if not exists ${this.quoteIdentifier(this.resolveSchemaIndexName(table, index))} on ${this.quoteIdentifier(table)} (${mappedColumns})`;
|
|
197
200
|
}
|
|
198
|
-
async ensureEnumTypes(columns, executor = this.db) {
|
|
201
|
+
async ensureEnumTypes(table, columns, executor = this.db) {
|
|
199
202
|
for (const column of columns) {
|
|
200
203
|
if (column.type !== "enum") continue;
|
|
201
|
-
const enumName =
|
|
204
|
+
const enumName = this.resolveSchemaEnumName(table, column);
|
|
202
205
|
if ((await kysely.sql`
|
|
203
206
|
select exists(
|
|
204
207
|
select 1
|
|
@@ -213,8 +216,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
213
216
|
}
|
|
214
217
|
async executeCreateTableOperation(operation, executor) {
|
|
215
218
|
const table = this.resolveMappedTable(operation.table);
|
|
216
|
-
await this.ensureEnumTypes(operation.columns, executor);
|
|
217
|
-
const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(column));
|
|
219
|
+
await this.ensureEnumTypes(table, operation.columns, executor);
|
|
220
|
+
const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(table, column));
|
|
218
221
|
const foreignKeys = (operation.foreignKeys ?? []).map((foreignKey) => this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.columns));
|
|
219
222
|
const definitions = [...columnDefinitions, ...foreignKeys].join(", ");
|
|
220
223
|
await this.executeRawStatement(`create table if not exists ${this.quoteIdentifier(table)} (${definitions})`, executor);
|
|
@@ -222,8 +225,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
222
225
|
}
|
|
223
226
|
async executeAlterTableOperation(operation, executor) {
|
|
224
227
|
const table = this.resolveMappedTable(operation.table);
|
|
225
|
-
await this.ensureEnumTypes(operation.addColumns, executor);
|
|
226
|
-
for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(column)}`, executor);
|
|
228
|
+
await this.ensureEnumTypes(table, operation.addColumns, executor);
|
|
229
|
+
for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(table, column)}`, executor);
|
|
227
230
|
for (const column of operation.dropColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} drop column if exists ${this.quoteIdentifier(column)}`, executor);
|
|
228
231
|
for (const foreignKey of operation.addForeignKeys ?? []) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add ${this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.addColumns)}`, executor);
|
|
229
232
|
for (const index of operation.addIndexes ?? []) await this.executeRawStatement(this.buildSchemaIndexStatement(table, index, operation.addColumns), executor);
|
|
@@ -8365,16 +8368,28 @@ var DB = class DB {
|
|
|
8365
8368
|
}
|
|
8366
8369
|
static createTableModel(table, options, adapter) {
|
|
8367
8370
|
const primaryKey = options.primaryKey ?? "id";
|
|
8368
|
-
const
|
|
8371
|
+
const resolvedAdapter = options.adapter ?? adapter ?? DB.getAdapter();
|
|
8372
|
+
const persistedMetadata = DB.resolvePersistedTableMetadata(table, options, resolvedAdapter);
|
|
8373
|
+
const columns = {
|
|
8374
|
+
...persistedMetadata.columns,
|
|
8375
|
+
...options.columns ?? {}
|
|
8376
|
+
};
|
|
8369
8377
|
const softDelete = options.softDelete ?? defaultSoftDeleteConfig;
|
|
8378
|
+
const primaryKeyGeneration = options.primaryKeyGeneration ? { ...options.primaryKeyGeneration } : persistedMetadata.primaryKeyGeneration?.column === primaryKey ? {
|
|
8379
|
+
strategy: persistedMetadata.primaryKeyGeneration.strategy,
|
|
8380
|
+
prismaDefault: persistedMetadata.primaryKeyGeneration.prismaDefault,
|
|
8381
|
+
databaseDefault: persistedMetadata.primaryKeyGeneration.databaseDefault,
|
|
8382
|
+
runtimeFactory: persistedMetadata.primaryKeyGeneration.runtimeFactory
|
|
8383
|
+
} : void 0;
|
|
8384
|
+
const timestampColumns = options.timestampColumns?.map((column) => ({ ...column })) ?? persistedMetadata.timestampColumns?.map((column) => ({ ...column }));
|
|
8370
8385
|
const buildMetadata = () => {
|
|
8371
8386
|
return {
|
|
8372
8387
|
table,
|
|
8373
8388
|
primaryKey,
|
|
8374
8389
|
columns: { ...columns },
|
|
8375
8390
|
softDelete: { ...softDelete },
|
|
8376
|
-
primaryKeyGeneration
|
|
8377
|
-
timestampColumns
|
|
8391
|
+
primaryKeyGeneration,
|
|
8392
|
+
timestampColumns
|
|
8378
8393
|
};
|
|
8379
8394
|
};
|
|
8380
8395
|
const modelStatic = {
|
|
@@ -8383,7 +8398,7 @@ var DB = class DB {
|
|
|
8383
8398
|
hydrateMany: (attributes) => attributes.map((attribute) => ({ ...attribute })),
|
|
8384
8399
|
hydrateRetrieved: async (attributes) => ({ ...attributes }),
|
|
8385
8400
|
hydrateManyRetrieved: async (attributes) => attributes.map((attribute) => ({ ...attribute })),
|
|
8386
|
-
getAdapter: () =>
|
|
8401
|
+
getAdapter: () => resolvedAdapter,
|
|
8387
8402
|
getColumnMap: () => ({ ...columns }),
|
|
8388
8403
|
getColumnName: (attribute) => columns[attribute] ?? attribute,
|
|
8389
8404
|
getDelegate: () => noopDelegate,
|
|
@@ -8396,6 +8411,19 @@ var DB = class DB {
|
|
|
8396
8411
|
};
|
|
8397
8412
|
return modelStatic;
|
|
8398
8413
|
}
|
|
8414
|
+
static resolvePersistedTableMetadata(table, options, adapter) {
|
|
8415
|
+
if (options.persistedMetadata === false) return {
|
|
8416
|
+
columns: {},
|
|
8417
|
+
enums: {}
|
|
8418
|
+
};
|
|
8419
|
+
const persistedMetadataOptions = typeof options.persistedMetadata === "object" ? options.persistedMetadata : {};
|
|
8420
|
+
return getPersistedTableMetadata(table, {
|
|
8421
|
+
cwd: persistedMetadataOptions.cwd,
|
|
8422
|
+
configuredPath: persistedMetadataOptions.configuredPath,
|
|
8423
|
+
features: resolvePersistedMetadataFeatures(getUserConfig("features")),
|
|
8424
|
+
strict: persistedMetadataOptions.strict ?? (Boolean(adapter) && !(adapter instanceof PrismaDatabaseAdapter))
|
|
8425
|
+
});
|
|
8426
|
+
}
|
|
8399
8427
|
};
|
|
8400
8428
|
|
|
8401
8429
|
//#endregion
|
package/dist/index.d.cts
CHANGED
|
@@ -411,12 +411,18 @@ interface MorphToManyRelationMetadata extends BaseRelationMetadata {
|
|
|
411
411
|
type RelationMetadata = HasOneRelationMetadata | HasManyRelationMetadata | BelongsToRelationMetadata | BelongsToManyRelationMetadata | HasOneThroughRelationMetadata | HasManyThroughRelationMetadata | MorphOneRelationMetadata | MorphManyRelationMetadata | MorphToManyRelationMetadata;
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/types/db.d.ts
|
|
414
|
+
interface DatabaseTablePersistedMetadataOptions {
|
|
415
|
+
cwd?: string;
|
|
416
|
+
configuredPath?: string;
|
|
417
|
+
strict?: boolean;
|
|
418
|
+
}
|
|
414
419
|
interface DatabaseTableOptions {
|
|
415
420
|
adapter?: DatabaseAdapter;
|
|
416
421
|
primaryKey?: string;
|
|
417
422
|
columns?: Record<string, string>;
|
|
418
423
|
softDelete?: SoftDeleteConfig;
|
|
419
424
|
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
425
|
+
persistedMetadata?: boolean | DatabaseTablePersistedMetadataOptions;
|
|
420
426
|
timestampColumns?: TimestampColumnBehavior[];
|
|
421
427
|
}
|
|
422
428
|
//#endregion
|
|
@@ -2843,6 +2849,7 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
|
|
|
2843
2849
|
private resolveSchemaColumnName;
|
|
2844
2850
|
private resolveSchemaIndexName;
|
|
2845
2851
|
private resolveSchemaForeignKeyName;
|
|
2852
|
+
private resolveSchemaEnumName;
|
|
2846
2853
|
private resolveSchemaColumnType;
|
|
2847
2854
|
private resolveSchemaColumnDefault;
|
|
2848
2855
|
private shouldUseIdentity;
|
|
@@ -4130,6 +4137,7 @@ declare class DB {
|
|
|
4130
4137
|
static transaction<TResult>(callback: (db: DB) => TResult | Promise<TResult>, context?: AdapterTransactionContext): Promise<TResult>;
|
|
4131
4138
|
transaction<TResult>(callback: (db: DB) => TResult | Promise<TResult>, context?: AdapterTransactionContext): Promise<TResult>;
|
|
4132
4139
|
private static createTableModel;
|
|
4140
|
+
private static resolvePersistedTableMetadata;
|
|
4133
4141
|
}
|
|
4134
4142
|
//#endregion
|
|
4135
4143
|
//#region src/Exceptions/ArkormException.d.ts
|
|
@@ -4724,4 +4732,4 @@ declare class URLDriver {
|
|
|
4724
4732
|
url(page: number): string;
|
|
4725
4733
|
}
|
|
4726
4734
|
//#endregion
|
|
4727
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
4735
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.d.mts
CHANGED
|
@@ -411,12 +411,18 @@ interface MorphToManyRelationMetadata extends BaseRelationMetadata {
|
|
|
411
411
|
type RelationMetadata = HasOneRelationMetadata | HasManyRelationMetadata | BelongsToRelationMetadata | BelongsToManyRelationMetadata | HasOneThroughRelationMetadata | HasManyThroughRelationMetadata | MorphOneRelationMetadata | MorphManyRelationMetadata | MorphToManyRelationMetadata;
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/types/db.d.ts
|
|
414
|
+
interface DatabaseTablePersistedMetadataOptions {
|
|
415
|
+
cwd?: string;
|
|
416
|
+
configuredPath?: string;
|
|
417
|
+
strict?: boolean;
|
|
418
|
+
}
|
|
414
419
|
interface DatabaseTableOptions {
|
|
415
420
|
adapter?: DatabaseAdapter;
|
|
416
421
|
primaryKey?: string;
|
|
417
422
|
columns?: Record<string, string>;
|
|
418
423
|
softDelete?: SoftDeleteConfig;
|
|
419
424
|
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
425
|
+
persistedMetadata?: boolean | DatabaseTablePersistedMetadataOptions;
|
|
420
426
|
timestampColumns?: TimestampColumnBehavior[];
|
|
421
427
|
}
|
|
422
428
|
//#endregion
|
|
@@ -2843,6 +2849,7 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
|
|
|
2843
2849
|
private resolveSchemaColumnName;
|
|
2844
2850
|
private resolveSchemaIndexName;
|
|
2845
2851
|
private resolveSchemaForeignKeyName;
|
|
2852
|
+
private resolveSchemaEnumName;
|
|
2846
2853
|
private resolveSchemaColumnType;
|
|
2847
2854
|
private resolveSchemaColumnDefault;
|
|
2848
2855
|
private shouldUseIdentity;
|
|
@@ -4130,6 +4137,7 @@ declare class DB {
|
|
|
4130
4137
|
static transaction<TResult>(callback: (db: DB) => TResult | Promise<TResult>, context?: AdapterTransactionContext): Promise<TResult>;
|
|
4131
4138
|
transaction<TResult>(callback: (db: DB) => TResult | Promise<TResult>, context?: AdapterTransactionContext): Promise<TResult>;
|
|
4132
4139
|
private static createTableModel;
|
|
4140
|
+
private static resolvePersistedTableMetadata;
|
|
4133
4141
|
}
|
|
4134
4142
|
//#endregion
|
|
4135
4143
|
//#region src/Exceptions/ArkormException.d.ts
|
|
@@ -4724,4 +4732,4 @@ declare class URLDriver {
|
|
|
4724
4732
|
url(page: number): string;
|
|
4725
4733
|
}
|
|
4726
4734
|
//#endregion
|
|
4727
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
4735
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.mjs
CHANGED
|
@@ -120,10 +120,13 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
120
120
|
resolveSchemaForeignKeyName(table, foreignKey) {
|
|
121
121
|
return `${table}_${foreignKey.column}_fkey`;
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
resolveSchemaEnumName(table, column) {
|
|
124
|
+
return column.enumName ?? `${table}_${column.name}_enum`;
|
|
125
|
+
}
|
|
126
|
+
resolveSchemaColumnType(table, column) {
|
|
124
127
|
if (column.type === "id") return "integer";
|
|
125
128
|
if (column.type === "uuid") return "uuid";
|
|
126
|
-
if (column.type === "enum") return this.quoteIdentifier(
|
|
129
|
+
if (column.type === "enum") return this.quoteIdentifier(this.resolveSchemaEnumName(table, column));
|
|
127
130
|
if (column.type === "string") return "varchar(255)";
|
|
128
131
|
if (column.type === "text") return "text";
|
|
129
132
|
if (column.type === "integer") return "integer";
|
|
@@ -146,8 +149,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
146
149
|
if (column.type === "id") return column.default === void 0;
|
|
147
150
|
return column.autoIncrement === true;
|
|
148
151
|
}
|
|
149
|
-
buildSchemaColumnDefinition(column) {
|
|
150
|
-
const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(column)];
|
|
152
|
+
buildSchemaColumnDefinition(table, column) {
|
|
153
|
+
const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(table, column)];
|
|
151
154
|
if (this.shouldUseIdentity(column)) parts.push("generated by default as identity");
|
|
152
155
|
const defaultValue = this.resolveSchemaColumnDefault(column);
|
|
153
156
|
if (defaultValue && !this.shouldUseIdentity(column)) parts.push(`default ${defaultValue}`);
|
|
@@ -166,10 +169,10 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
166
169
|
const mappedColumns = index.columns.map((column) => this.quoteIdentifier(this.resolveSchemaColumnName(column, columns))).join(", ");
|
|
167
170
|
return `create index if not exists ${this.quoteIdentifier(this.resolveSchemaIndexName(table, index))} on ${this.quoteIdentifier(table)} (${mappedColumns})`;
|
|
168
171
|
}
|
|
169
|
-
async ensureEnumTypes(columns, executor = this.db) {
|
|
172
|
+
async ensureEnumTypes(table, columns, executor = this.db) {
|
|
170
173
|
for (const column of columns) {
|
|
171
174
|
if (column.type !== "enum") continue;
|
|
172
|
-
const enumName =
|
|
175
|
+
const enumName = this.resolveSchemaEnumName(table, column);
|
|
173
176
|
if ((await sql`
|
|
174
177
|
select exists(
|
|
175
178
|
select 1
|
|
@@ -184,8 +187,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
184
187
|
}
|
|
185
188
|
async executeCreateTableOperation(operation, executor) {
|
|
186
189
|
const table = this.resolveMappedTable(operation.table);
|
|
187
|
-
await this.ensureEnumTypes(operation.columns, executor);
|
|
188
|
-
const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(column));
|
|
190
|
+
await this.ensureEnumTypes(table, operation.columns, executor);
|
|
191
|
+
const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(table, column));
|
|
189
192
|
const foreignKeys = (operation.foreignKeys ?? []).map((foreignKey) => this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.columns));
|
|
190
193
|
const definitions = [...columnDefinitions, ...foreignKeys].join(", ");
|
|
191
194
|
await this.executeRawStatement(`create table if not exists ${this.quoteIdentifier(table)} (${definitions})`, executor);
|
|
@@ -193,8 +196,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
193
196
|
}
|
|
194
197
|
async executeAlterTableOperation(operation, executor) {
|
|
195
198
|
const table = this.resolveMappedTable(operation.table);
|
|
196
|
-
await this.ensureEnumTypes(operation.addColumns, executor);
|
|
197
|
-
for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(column)}`, executor);
|
|
199
|
+
await this.ensureEnumTypes(table, operation.addColumns, executor);
|
|
200
|
+
for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(table, column)}`, executor);
|
|
198
201
|
for (const column of operation.dropColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} drop column if exists ${this.quoteIdentifier(column)}`, executor);
|
|
199
202
|
for (const foreignKey of operation.addForeignKeys ?? []) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add ${this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.addColumns)}`, executor);
|
|
200
203
|
for (const index of operation.addIndexes ?? []) await this.executeRawStatement(this.buildSchemaIndexStatement(table, index, operation.addColumns), executor);
|
|
@@ -8336,16 +8339,28 @@ var DB = class DB {
|
|
|
8336
8339
|
}
|
|
8337
8340
|
static createTableModel(table, options, adapter) {
|
|
8338
8341
|
const primaryKey = options.primaryKey ?? "id";
|
|
8339
|
-
const
|
|
8342
|
+
const resolvedAdapter = options.adapter ?? adapter ?? DB.getAdapter();
|
|
8343
|
+
const persistedMetadata = DB.resolvePersistedTableMetadata(table, options, resolvedAdapter);
|
|
8344
|
+
const columns = {
|
|
8345
|
+
...persistedMetadata.columns,
|
|
8346
|
+
...options.columns ?? {}
|
|
8347
|
+
};
|
|
8340
8348
|
const softDelete = options.softDelete ?? defaultSoftDeleteConfig;
|
|
8349
|
+
const primaryKeyGeneration = options.primaryKeyGeneration ? { ...options.primaryKeyGeneration } : persistedMetadata.primaryKeyGeneration?.column === primaryKey ? {
|
|
8350
|
+
strategy: persistedMetadata.primaryKeyGeneration.strategy,
|
|
8351
|
+
prismaDefault: persistedMetadata.primaryKeyGeneration.prismaDefault,
|
|
8352
|
+
databaseDefault: persistedMetadata.primaryKeyGeneration.databaseDefault,
|
|
8353
|
+
runtimeFactory: persistedMetadata.primaryKeyGeneration.runtimeFactory
|
|
8354
|
+
} : void 0;
|
|
8355
|
+
const timestampColumns = options.timestampColumns?.map((column) => ({ ...column })) ?? persistedMetadata.timestampColumns?.map((column) => ({ ...column }));
|
|
8341
8356
|
const buildMetadata = () => {
|
|
8342
8357
|
return {
|
|
8343
8358
|
table,
|
|
8344
8359
|
primaryKey,
|
|
8345
8360
|
columns: { ...columns },
|
|
8346
8361
|
softDelete: { ...softDelete },
|
|
8347
|
-
primaryKeyGeneration
|
|
8348
|
-
timestampColumns
|
|
8362
|
+
primaryKeyGeneration,
|
|
8363
|
+
timestampColumns
|
|
8349
8364
|
};
|
|
8350
8365
|
};
|
|
8351
8366
|
const modelStatic = {
|
|
@@ -8354,7 +8369,7 @@ var DB = class DB {
|
|
|
8354
8369
|
hydrateMany: (attributes) => attributes.map((attribute) => ({ ...attribute })),
|
|
8355
8370
|
hydrateRetrieved: async (attributes) => ({ ...attributes }),
|
|
8356
8371
|
hydrateManyRetrieved: async (attributes) => attributes.map((attribute) => ({ ...attribute })),
|
|
8357
|
-
getAdapter: () =>
|
|
8372
|
+
getAdapter: () => resolvedAdapter,
|
|
8358
8373
|
getColumnMap: () => ({ ...columns }),
|
|
8359
8374
|
getColumnName: (attribute) => columns[attribute] ?? attribute,
|
|
8360
8375
|
getDelegate: () => noopDelegate,
|
|
@@ -8367,6 +8382,19 @@ var DB = class DB {
|
|
|
8367
8382
|
};
|
|
8368
8383
|
return modelStatic;
|
|
8369
8384
|
}
|
|
8385
|
+
static resolvePersistedTableMetadata(table, options, adapter) {
|
|
8386
|
+
if (options.persistedMetadata === false) return {
|
|
8387
|
+
columns: {},
|
|
8388
|
+
enums: {}
|
|
8389
|
+
};
|
|
8390
|
+
const persistedMetadataOptions = typeof options.persistedMetadata === "object" ? options.persistedMetadata : {};
|
|
8391
|
+
return getPersistedTableMetadata(table, {
|
|
8392
|
+
cwd: persistedMetadataOptions.cwd,
|
|
8393
|
+
configuredPath: persistedMetadataOptions.configuredPath,
|
|
8394
|
+
features: resolvePersistedMetadataFeatures(getUserConfig("features")),
|
|
8395
|
+
strict: persistedMetadataOptions.strict ?? (Boolean(adapter) && !(adapter instanceof PrismaDatabaseAdapter))
|
|
8396
|
+
});
|
|
8397
|
+
}
|
|
8370
8398
|
};
|
|
8371
8399
|
|
|
8372
8400
|
//#endregion
|