rake-db 2.14.5 → 2.15.0
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 +80 -50
- package/dist/index.js +1029 -554
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1031 -560
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter,
|
|
3
|
-
import { EmptyObject, RawSQLBase, ColumnSchemaConfig, MaybeArray, ColumnTypeBase } from 'orchid-core';
|
|
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';
|
|
3
|
+
import { EmptyObject, RawSQLBase, ColumnSchemaConfig, MaybeArray, ColumnTypeBase, RecordString } from 'orchid-core';
|
|
4
4
|
|
|
5
5
|
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
6
6
|
table: Db$1<Table, Shape>;
|
|
@@ -68,6 +68,26 @@ type SilentQueries = {
|
|
|
68
68
|
silentQuery: Adapter['query'];
|
|
69
69
|
silentArrays: Adapter['arrays'];
|
|
70
70
|
};
|
|
71
|
+
interface RakeDbColumnTypes {
|
|
72
|
+
index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): EmptyObject;
|
|
73
|
+
foreignKey(columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: ForeignKeyOptions): EmptyObject;
|
|
74
|
+
primaryKey(columns: string[], options?: {
|
|
75
|
+
name?: string;
|
|
76
|
+
}): EmptyObject;
|
|
77
|
+
check(check: RawSQLBase): EmptyObject;
|
|
78
|
+
constraint(arg: ConstraintArg): EmptyObject;
|
|
79
|
+
}
|
|
80
|
+
interface ConstraintArg {
|
|
81
|
+
name?: string;
|
|
82
|
+
references?: [
|
|
83
|
+
columns: [string, ...string[]],
|
|
84
|
+
table: string,
|
|
85
|
+
foreignColumn: [string, ...string[]],
|
|
86
|
+
options: Omit<ForeignKeyOptions, 'name' | 'dropMode'>
|
|
87
|
+
];
|
|
88
|
+
check?: RawSQLBase;
|
|
89
|
+
dropMode?: DropMode;
|
|
90
|
+
}
|
|
71
91
|
type DbMigration<CT extends RakeDbColumnTypes> = DbResult<CT> & Migration<CT> & {
|
|
72
92
|
adapter: SilentQueries;
|
|
73
93
|
};
|
|
@@ -936,48 +956,13 @@ declare namespace RakeDbAst {
|
|
|
936
956
|
}
|
|
937
957
|
}
|
|
938
958
|
|
|
939
|
-
interface RakeDbColumnTypes {
|
|
940
|
-
index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): EmptyObject;
|
|
941
|
-
foreignKey(columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: ForeignKeyOptions): EmptyObject;
|
|
942
|
-
primaryKey(columns: string[], options?: {
|
|
943
|
-
name?: string;
|
|
944
|
-
}): EmptyObject;
|
|
945
|
-
check(check: RawSQLBase): EmptyObject;
|
|
946
|
-
constraint(arg: ConstraintArg): EmptyObject;
|
|
947
|
-
}
|
|
948
|
-
interface ConstraintArg {
|
|
949
|
-
name?: string;
|
|
950
|
-
references?: [
|
|
951
|
-
columns: [string, ...string[]],
|
|
952
|
-
table: string,
|
|
953
|
-
foreignColumn: [string, ...string[]],
|
|
954
|
-
options: Omit<ForeignKeyOptions, 'name' | 'dropMode'>
|
|
955
|
-
];
|
|
956
|
-
check?: RawSQLBase;
|
|
957
|
-
dropMode?: DropMode;
|
|
958
|
-
}
|
|
959
|
-
type Db = DbResult<RakeDbColumnTypes>;
|
|
960
|
-
interface BaseTable<CT> {
|
|
961
|
-
exportAs: string;
|
|
962
|
-
getFilePath(): string;
|
|
963
|
-
nowSQL?: string;
|
|
964
|
-
new (): {
|
|
965
|
-
types: CT;
|
|
966
|
-
snakeCase?: boolean;
|
|
967
|
-
language?: string;
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
type InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> = Partial<Omit<RakeDbConfig<SchemaConfig, CT>, 'columnTypes'>> & ({
|
|
971
|
-
columnTypes?: CT | ((t: DefaultColumnTypes<ColumnSchemaConfig>) => CT);
|
|
972
|
-
} | {
|
|
973
|
-
baseTable?: BaseTable<CT>;
|
|
974
|
-
});
|
|
975
959
|
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<ColumnSchemaConfig>> extends QueryLogOptions {
|
|
976
960
|
schemaConfig: SchemaConfig;
|
|
977
961
|
columnTypes: CT;
|
|
978
962
|
basePath: string;
|
|
979
963
|
dbScript: string;
|
|
980
964
|
migrationsPath: string;
|
|
965
|
+
migrationId: RakeDbMigrationId;
|
|
981
966
|
migrations?: ModuleExportsRecord;
|
|
982
967
|
recurrentPath: string;
|
|
983
968
|
migrationsTable: string;
|
|
@@ -985,7 +970,7 @@ interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColu
|
|
|
985
970
|
language?: string;
|
|
986
971
|
commands: Record<string, (options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT>, args: string[]) => void | Promise<void>>;
|
|
987
972
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
988
|
-
baseTable?:
|
|
973
|
+
baseTable?: RakeDbBaseTable<CT>;
|
|
989
974
|
appCodeUpdater?: AppCodeUpdater;
|
|
990
975
|
useCodeUpdater?: boolean;
|
|
991
976
|
forceDefaultExports?: boolean;
|
|
@@ -995,9 +980,27 @@ interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColu
|
|
|
995
980
|
beforeRollback?(db: Db): Promise<void>;
|
|
996
981
|
afterRollback?(db: Db): Promise<void>;
|
|
997
982
|
}
|
|
983
|
+
type InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> = Partial<Omit<RakeDbConfig<SchemaConfig, CT>, 'columnTypes'>> & ({
|
|
984
|
+
columnTypes?: CT | ((t: DefaultColumnTypes<ColumnSchemaConfig>) => CT);
|
|
985
|
+
} | {
|
|
986
|
+
baseTable?: RakeDbBaseTable<CT>;
|
|
987
|
+
});
|
|
988
|
+
type AnyRakeDbConfig = RakeDbConfig<any, any>;
|
|
989
|
+
type Db = DbResult<RakeDbColumnTypes>;
|
|
990
|
+
interface RakeDbBaseTable<CT> {
|
|
991
|
+
exportAs: string;
|
|
992
|
+
getFilePath(): string;
|
|
993
|
+
nowSQL?: string;
|
|
994
|
+
new (): {
|
|
995
|
+
types: CT;
|
|
996
|
+
snakeCase?: boolean;
|
|
997
|
+
language?: string;
|
|
998
|
+
};
|
|
999
|
+
}
|
|
998
1000
|
interface ModuleExportsRecord {
|
|
999
1001
|
[K: string]: () => Promise<unknown>;
|
|
1000
1002
|
}
|
|
1003
|
+
type RakeDbMigrationId = 'serial' | 'timestamp';
|
|
1001
1004
|
interface AppCodeUpdaterParams {
|
|
1002
1005
|
options: AdapterOptions;
|
|
1003
1006
|
basePath: string;
|
|
@@ -1015,6 +1018,28 @@ interface AppCodeUpdater {
|
|
|
1015
1018
|
}): Promise<void>;
|
|
1016
1019
|
afterAll(params: AppCodeUpdaterParams): Promise<void>;
|
|
1017
1020
|
}
|
|
1021
|
+
declare const migrationConfigDefaults: {
|
|
1022
|
+
schemaConfig: pqb.DefaultSchemaConfig;
|
|
1023
|
+
migrationsPath: string;
|
|
1024
|
+
migrationId: "serial";
|
|
1025
|
+
migrationsTable: string;
|
|
1026
|
+
snakeCase: false;
|
|
1027
|
+
commands: {};
|
|
1028
|
+
import: (path: string) => Promise<any>;
|
|
1029
|
+
log: true;
|
|
1030
|
+
logger: Console;
|
|
1031
|
+
useCodeUpdater: true;
|
|
1032
|
+
};
|
|
1033
|
+
declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig, CT>(config: InputRakeDbConfig<SchemaConfig, CT>) => RakeDbConfig<SchemaConfig, CT>;
|
|
1034
|
+
declare const getDatabaseAndUserFromOptions: (options: AdapterOptions) => {
|
|
1035
|
+
database: string;
|
|
1036
|
+
user: string;
|
|
1037
|
+
};
|
|
1038
|
+
|
|
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>;
|
|
1042
|
+
|
|
1018
1043
|
interface MigrationItem {
|
|
1019
1044
|
path: string;
|
|
1020
1045
|
version: string;
|
|
@@ -1025,19 +1050,24 @@ interface MigrationItem {
|
|
|
1025
1050
|
*/
|
|
1026
1051
|
load(): Promise<unknown>;
|
|
1027
1052
|
}
|
|
1053
|
+
interface MigrationsSet {
|
|
1054
|
+
renameTo?: RakeDbMigrationId;
|
|
1055
|
+
migrations: MigrationItem[];
|
|
1056
|
+
}
|
|
1028
1057
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1058
|
+
interface RakeDbCtx {
|
|
1059
|
+
migrationsPromise?: Promise<MigrationsSet>;
|
|
1060
|
+
}
|
|
1032
1061
|
|
|
1033
1062
|
declare const writeMigrationFile: <SchemaConfig extends ColumnSchemaConfig, CT>(config: RakeDbConfig<SchemaConfig, CT>, version: string, name: string, content: (importPath: string, name: string) => string) => Promise<void>;
|
|
1034
|
-
declare const generate:
|
|
1035
|
-
declare const
|
|
1063
|
+
declare const generate: (config: AnyRakeDbConfig, [name]: string[]) => Promise<void>;
|
|
1064
|
+
declare const makeFileVersion: (ctx: RakeDbCtx, config: AnyRakeDbConfig) => Promise<string>;
|
|
1065
|
+
declare const generateTimeStamp: () => string;
|
|
1036
1066
|
|
|
1037
1067
|
type ChangeCallback<CT extends RakeDbColumnTypes> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1038
1068
|
|
|
1039
1069
|
declare const RAKE_DB_LOCK_KEY = "8582141715823621641";
|
|
1040
|
-
type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(options: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<void>;
|
|
1070
|
+
type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(ctx: RakeDbCtx, options: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<void>;
|
|
1041
1071
|
/**
|
|
1042
1072
|
* Will run all pending yet migrations, sequentially in order,
|
|
1043
1073
|
* will apply `change` functions top-to-bottom.
|
|
@@ -1060,7 +1090,7 @@ declare const rollback: MigrateFn;
|
|
|
1060
1090
|
* Takes the same options as {@link migrate}.
|
|
1061
1091
|
*/
|
|
1062
1092
|
declare const redo: MigrateFn;
|
|
1063
|
-
declare const migrateOrRollback: (trx: TransactionAdapter, config: RakeDbConfig<ColumnSchemaConfig, RakeDbColumnTypes>,
|
|
1093
|
+
declare const migrateOrRollback: (ctx: RakeDbCtx, trx: TransactionAdapter, config: RakeDbConfig<ColumnSchemaConfig, RakeDbColumnTypes>, set: MigrationsSet, count: number, asts: RakeDbAst[], up: boolean, skipLock?: boolean) => Promise<void>;
|
|
1064
1094
|
declare const changeCache: Record<string, ChangeCallback<RakeDbColumnTypes>[] | undefined>;
|
|
1065
1095
|
|
|
1066
1096
|
/**
|
|
@@ -1101,10 +1131,10 @@ type RakeDbChangeFn<CT extends RakeDbColumnTypes> = (fn: ChangeCallback<CT>) =>
|
|
|
1101
1131
|
*/
|
|
1102
1132
|
declare const rakeDb: RakeDbFn;
|
|
1103
1133
|
|
|
1104
|
-
declare const saveMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1105
|
-
declare const removeMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1134
|
+
declare const saveMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1135
|
+
declare const removeMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1106
1136
|
declare class NoMigrationsTableError extends Error {
|
|
1107
1137
|
}
|
|
1108
|
-
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig, CT>(adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>) => Promise<
|
|
1138
|
+
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig, CT>(ctx: RakeDbCtx, adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>) => Promise<RecordString>;
|
|
1109
1139
|
|
|
1110
|
-
export { AppCodeUpdater, AppCodeUpdaterParams, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DbMigration, DropMode, Migration, MigrationColumnTypes, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAst, RakeDbConfig, SilentQueries, TableOptions, changeCache, createDb, createMigrationInterface, dropDb, generate, getMigratedVersionsMap,
|
|
1140
|
+
export { AnyRakeDbConfig, AppCodeUpdater, AppCodeUpdaterParams, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, ConstraintArg, DbMigration, DropMode, InputRakeDbConfig, Migration, MigrationColumnTypes, ModuleExportsRecord, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAst, RakeDbBaseTable, RakeDbColumnTypes, RakeDbConfig, RakeDbMigrationId, SilentQueries, TableOptions, changeCache, createDb, createMigrationInterface, dropDb, generate, generateTimeStamp, getDatabaseAndUserFromOptions, getMigratedVersionsMap, makeFileVersion, migrate, migrateOrRollback, migrationConfigDefaults, processRakeDbConfig, rakeDb, redo, removeMigratedVersion, resetDb, rollback, saveMigratedVersion, writeMigrationFile };
|