rake-db 2.15.4 → 2.15.6
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.d.ts +38 -18
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter, IndexColumnOptions, IndexOptions, ForeignKeyOptions, DbResult, TransactionAdapter, QueryLogObject, TextColumn, TableData, NoPrimaryKeyOption, SingleColumnIndexOptions, DefaultColumnTypes, QueryLogOptions, AdapterOptions } from 'pqb';
|
|
1
|
+
import * as orchid_core from 'orchid-core';
|
|
3
2
|
import { EmptyObject, RawSQLBase, ColumnSchemaConfig, MaybeArray, ColumnTypeBase, RecordOptionalString } from 'orchid-core';
|
|
3
|
+
import * as pqb from 'pqb';
|
|
4
|
+
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter, IndexColumnOptions, IndexOptions, ForeignKeyOptions, DbResult, TransactionAdapter, QueryLogObject, TextColumn, TableData, NoPrimaryKeyOption, SingleColumnIndexOptions, DefaultColumnTypes, DefaultSchemaConfig, QueryLogOptions, AdapterOptions } from 'pqb';
|
|
4
5
|
|
|
5
6
|
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
6
7
|
table: Db$1<Table, Shape>;
|
|
@@ -100,7 +101,7 @@ type DbMigration<CT extends RakeDbColumnTypes> = DbResult<CT> & Migration<CT> &
|
|
|
100
101
|
* @param config - config of `rakeDb`
|
|
101
102
|
* @param asts - array of migration ASTs to collect changes into
|
|
102
103
|
*/
|
|
103
|
-
declare const createMigrationInterface: <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(tx: TransactionAdapter, up: boolean, config: RakeDbConfig<SchemaConfig, CT>, asts: RakeDbAst[]) => DbMigration<CT>;
|
|
104
|
+
declare const createMigrationInterface: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT extends RakeDbColumnTypes>(tx: TransactionAdapter, up: boolean, config: RakeDbConfig<SchemaConfig, CT>, asts: RakeDbAst[]) => DbMigration<CT>;
|
|
104
105
|
declare class Migration<CT extends RakeDbColumnTypes> {
|
|
105
106
|
adapter: TransactionAdapter;
|
|
106
107
|
log?: QueryLogObject;
|
|
@@ -956,7 +957,7 @@ declare namespace RakeDbAst {
|
|
|
956
957
|
}
|
|
957
958
|
}
|
|
958
959
|
|
|
959
|
-
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<
|
|
960
|
+
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends QueryLogOptions {
|
|
960
961
|
schemaConfig: SchemaConfig;
|
|
961
962
|
columnTypes: CT;
|
|
962
963
|
basePath: string;
|
|
@@ -980,11 +981,30 @@ interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColu
|
|
|
980
981
|
beforeRollback?(db: Db): Promise<void>;
|
|
981
982
|
afterRollback?(db: Db): Promise<void>;
|
|
982
983
|
}
|
|
983
|
-
|
|
984
|
-
columnTypes?: CT | ((t: DefaultColumnTypes<
|
|
985
|
-
} | {
|
|
984
|
+
interface InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> extends QueryLogOptions {
|
|
985
|
+
columnTypes?: CT | ((t: DefaultColumnTypes<DefaultSchemaConfig>) => CT);
|
|
986
986
|
baseTable?: RakeDbBaseTable<CT>;
|
|
987
|
-
|
|
987
|
+
schemaConfig?: SchemaConfig;
|
|
988
|
+
basePath?: string;
|
|
989
|
+
dbScript?: string;
|
|
990
|
+
migrationsPath?: string;
|
|
991
|
+
migrationId?: RakeDbMigrationId;
|
|
992
|
+
migrations?: ModuleExportsRecord;
|
|
993
|
+
recurrentPath?: string;
|
|
994
|
+
migrationsTable?: string;
|
|
995
|
+
snakeCase?: boolean;
|
|
996
|
+
language?: string;
|
|
997
|
+
commands?: Record<string, (options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT extends undefined ? DefaultColumnTypes<DefaultSchemaConfig> : CT>, args: string[]) => void | Promise<void>>;
|
|
998
|
+
noPrimaryKey?: NoPrimaryKeyOption;
|
|
999
|
+
appCodeUpdater?: AppCodeUpdater;
|
|
1000
|
+
useCodeUpdater?: boolean;
|
|
1001
|
+
forceDefaultExports?: boolean;
|
|
1002
|
+
import?(path: string): Promise<unknown>;
|
|
1003
|
+
beforeMigrate?(db: Db): Promise<void>;
|
|
1004
|
+
afterMigrate?(db: Db): Promise<void>;
|
|
1005
|
+
beforeRollback?(db: Db): Promise<void>;
|
|
1006
|
+
afterRollback?(db: Db): Promise<void>;
|
|
1007
|
+
}
|
|
988
1008
|
type AnyRakeDbConfig = RakeDbConfig<any, any>;
|
|
989
1009
|
type Db = DbResult<RakeDbColumnTypes>;
|
|
990
1010
|
interface RakeDbBaseTable<CT> {
|
|
@@ -1019,7 +1039,7 @@ interface AppCodeUpdater {
|
|
|
1019
1039
|
afterAll(params: AppCodeUpdaterParams): Promise<void>;
|
|
1020
1040
|
}
|
|
1021
1041
|
declare const migrationConfigDefaults: {
|
|
1022
|
-
schemaConfig:
|
|
1042
|
+
schemaConfig: DefaultSchemaConfig;
|
|
1023
1043
|
migrationsPath: string;
|
|
1024
1044
|
migrationId: "serial";
|
|
1025
1045
|
migrationsTable: string;
|
|
@@ -1030,15 +1050,15 @@ declare const migrationConfigDefaults: {
|
|
|
1030
1050
|
logger: Console;
|
|
1031
1051
|
useCodeUpdater: true;
|
|
1032
1052
|
};
|
|
1033
|
-
declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig, CT>(config: InputRakeDbConfig<SchemaConfig, CT>) => RakeDbConfig<SchemaConfig, CT>;
|
|
1053
|
+
declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(config: InputRakeDbConfig<SchemaConfig, CT>) => RakeDbConfig<SchemaConfig, CT>;
|
|
1034
1054
|
declare const getDatabaseAndUserFromOptions: (options: AdapterOptions) => {
|
|
1035
1055
|
database: string;
|
|
1036
1056
|
user: string;
|
|
1037
1057
|
};
|
|
1038
1058
|
|
|
1039
|
-
declare const createDb: <SchemaConfig extends ColumnSchemaConfig, CT>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1040
|
-
declare const dropDb: <SchemaConfig extends ColumnSchemaConfig, CT>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1041
|
-
declare const resetDb: <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1059
|
+
declare const createDb: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1060
|
+
declare const dropDb: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1061
|
+
declare const resetDb: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT extends RakeDbColumnTypes>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1042
1062
|
|
|
1043
1063
|
interface MigrationItem {
|
|
1044
1064
|
path: string;
|
|
@@ -1059,22 +1079,22 @@ interface RakeDbCtx {
|
|
|
1059
1079
|
migrationsPromise?: Promise<MigrationsSet>;
|
|
1060
1080
|
}
|
|
1061
1081
|
|
|
1062
|
-
declare const writeMigrationFile: <SchemaConfig extends ColumnSchemaConfig, CT>(config: RakeDbConfig<SchemaConfig, CT>, version: string, name: string, content: (importPath: string, name: string) => string) => Promise<void>;
|
|
1082
|
+
declare const writeMigrationFile: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(config: RakeDbConfig<SchemaConfig, CT>, version: string, name: string, content: (importPath: string, name: string) => string) => Promise<void>;
|
|
1063
1083
|
declare const generate: (config: AnyRakeDbConfig, [name]: string[]) => Promise<void>;
|
|
1064
1084
|
declare const makeFileVersion: (ctx: RakeDbCtx, config: AnyRakeDbConfig) => Promise<string>;
|
|
1065
1085
|
declare const generateTimeStamp: () => string;
|
|
1066
1086
|
|
|
1067
1087
|
type ChangeCallback<CT extends RakeDbColumnTypes> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1068
1088
|
|
|
1069
|
-
declare const saveMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1070
|
-
declare const deleteMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1089
|
+
declare const saveMigratedVersion: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1090
|
+
declare const deleteMigratedVersion: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1071
1091
|
declare class NoMigrationsTableError extends Error {
|
|
1072
1092
|
}
|
|
1073
1093
|
type RakeDbAppliedVersions = {
|
|
1074
1094
|
map: RecordOptionalString;
|
|
1075
1095
|
sequence: number[];
|
|
1076
1096
|
};
|
|
1077
|
-
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig, CT>(ctx: RakeDbCtx, adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>, renameTo?: RakeDbMigrationId) => Promise<RakeDbAppliedVersions>;
|
|
1097
|
+
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.BaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(ctx: RakeDbCtx, adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>, renameTo?: RakeDbMigrationId) => Promise<RakeDbAppliedVersions>;
|
|
1078
1098
|
|
|
1079
1099
|
declare const RAKE_DB_LOCK_KEY = "8582141715823621641";
|
|
1080
1100
|
type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(ctx: RakeDbCtx, options: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<void>;
|
|
@@ -1106,7 +1126,7 @@ declare const changeCache: Record<string, ChangeCallback<RakeDbColumnTypes>[] |
|
|
|
1106
1126
|
/**
|
|
1107
1127
|
* Type of {@link rakeDb} function
|
|
1108
1128
|
*/
|
|
1109
|
-
type RakeDbFn = (<SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(options: MaybeArray<AdapterOptions>, partialConfig?: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbChangeFn<CT> & {
|
|
1129
|
+
type RakeDbFn = (<SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes | undefined = undefined>(options: MaybeArray<AdapterOptions>, partialConfig?: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbChangeFn<CT extends undefined ? DefaultColumnTypes<DefaultSchemaConfig> : CT> & {
|
|
1110
1130
|
promise: Promise<void>;
|
|
1111
1131
|
}) & {
|
|
1112
1132
|
/**
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@ var __spreadValues$a = (a, b) => {
|
|
|
105
105
|
return a;
|
|
106
106
|
};
|
|
107
107
|
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
108
|
+
const versionToString = (config, version) => config.migrationId === "serial" ? `${version}`.padStart(4, "0") : `${version}`;
|
|
108
109
|
const columnTypeToSql = (item) => {
|
|
109
110
|
return item.data.isOfCustomType ? `"${item.toSQL()}"` : item.toSQL();
|
|
110
111
|
};
|
|
@@ -2512,7 +2513,7 @@ const migrateOrRollback = async (trx, config, set, versions, count, asts, up, fo
|
|
|
2512
2513
|
var _a, _b, _c;
|
|
2513
2514
|
const { sequence, map: versionsMap } = versions;
|
|
2514
2515
|
if (up) {
|
|
2515
|
-
const rollbackTo = checkMigrationOrder(set, versions, force);
|
|
2516
|
+
const rollbackTo = checkMigrationOrder(config, set, versions, force);
|
|
2516
2517
|
if (rollbackTo) {
|
|
2517
2518
|
let i = sequence.length - 1;
|
|
2518
2519
|
for (; i >= 0; i--) {
|
|
@@ -2561,18 +2562,18 @@ const migrateOrRollback = async (trx, config, set, versions, count, asts, up, fo
|
|
|
2561
2562
|
}
|
|
2562
2563
|
await ((_c = config[up ? "afterMigrate" : "afterRollback"]) == null ? void 0 : _c.call(config, db != null ? db : db = getDb(trx)));
|
|
2563
2564
|
};
|
|
2564
|
-
const checkMigrationOrder = (set, { sequence, map }, force) => {
|
|
2565
|
+
const checkMigrationOrder = (config, set, { sequence, map }, force) => {
|
|
2565
2566
|
const last = sequence[sequence.length - 1];
|
|
2566
2567
|
if (last) {
|
|
2567
2568
|
for (const file of set.migrations) {
|
|
2568
2569
|
const version = +file.version;
|
|
2569
|
-
if (version > last || map[version])
|
|
2570
|
+
if (version > last || map[file.version])
|
|
2570
2571
|
continue;
|
|
2571
2572
|
if (!force) {
|
|
2572
2573
|
throw new Error(
|
|
2573
2574
|
`Cannot migrate ${path.basename(
|
|
2574
2575
|
file.path
|
|
2575
|
-
)} because the higher position ${map[last]} was already migrated.
|
|
2576
|
+
)} because the higher position ${map[versionToString(config, last)]} was already migrated.
|
|
2576
2577
|
Run \`**db command** up force\` to rollback the above migrations and migrate all`
|
|
2577
2578
|
);
|
|
2578
2579
|
}
|