rake-db 2.3.24 → 2.3.26
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/.env.local +2 -2
- package/.turbo/turbo-test:ci.log +7 -7
- package/CHANGELOG.md +15 -0
- package/dist/index.d.ts +34 -28
- package/dist/index.js +30 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/ast.ts +18 -2
- package/src/commands/generate.test.ts +8 -5
- package/src/migration/changeTable.test.ts +6 -0
- package/src/migration/createTable.test.ts +2 -0
- package/src/migration/migration.test.ts +48 -2
- package/src/migration/migration.ts +70 -16
package/.env.local
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
DATABASE_URL=postgres://romeerez:e2Y6ovIJruas@ep-autumn-tooth-279704.eu-central-1.aws.neon.tech/neondb?ssl=true
|
|
1
|
+
DATABASE_URL=postgres://postgres:@localhost:5432/porm
|
|
2
|
+
#DATABASE_URL=postgres://romeerez:e2Y6ovIJruas@ep-autumn-tooth-279704.eu-central-1.aws.neon.tech/neondb?ssl=true
|
package/.turbo/turbo-test:ci.log
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
> rake-db@2.3.24 test:ci /home/romeo/dev/my/orchid-orm/packages/rake-db
|
|
3
3
|
> jest --coverage --coverageReporters json-summary
|
|
4
4
|
|
|
5
|
-
PASS src/migration/changeTable.test.ts
|
|
6
|
-
PASS src/migration/createTable.test.ts
|
|
7
5
|
PASS src/commands/createOrDrop.test.ts
|
|
8
|
-
PASS src/pull/structureToAst.test.ts
|
|
9
6
|
PASS src/common.test.ts
|
|
10
|
-
PASS src/migration/
|
|
7
|
+
PASS src/migration/changeTable.test.ts
|
|
8
|
+
PASS src/pull/structureToAst.test.ts
|
|
11
9
|
PASS src/commands/migrateOrRollback.test.ts
|
|
10
|
+
PASS src/migration/migration.test.ts
|
|
11
|
+
PASS src/migration/createTable.test.ts
|
|
12
|
+
PASS src/pull/astToMigration.test.ts
|
|
12
13
|
PASS src/commands/generate.test.ts
|
|
13
|
-
PASS src/rakeDb.test.ts
|
|
14
14
|
PASS src/pull/pull.test.ts
|
|
15
|
+
PASS src/rakeDb.test.ts
|
|
15
16
|
PASS src/pull/dbStructure.test.ts
|
|
16
|
-
PASS src/pull/astToMigration.test.ts
|
|
17
17
|
|
|
18
18
|
Test Suites: 12 passed, 12 total
|
|
19
19
|
Tests: 184 passed, 184 total
|
|
20
20
|
Snapshots: 0 total
|
|
21
|
-
Time:
|
|
21
|
+
Time: 6.736 s
|
|
22
22
|
Ran all test suites.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# rake-db
|
|
2
2
|
|
|
3
|
+
## 2.3.26
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add createEnum and dropEnum to rake-db
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- pqb@0.9.15
|
|
10
|
+
|
|
11
|
+
## 2.3.25
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- pqb@0.9.14
|
|
17
|
+
|
|
3
18
|
## 2.3.24
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { EmptyObject, RawExpression, ColumnType, ColumnTypes, raw, ColumnsShape, DbResult, DefaultColumnTypes, TransactionAdapter, AdapterOptions, TextColumn, MaybeArray, IndexColumnOptions, IndexOptions, ForeignKeyOptions, QueryLogObject, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, QueryLogOptions } from 'pqb';
|
|
2
|
+
import { EmptyObject, RawExpression, ColumnType, ColumnTypes, EnumColumn, raw, ColumnsShape, DbResult, DefaultColumnTypes, TransactionAdapter, AdapterOptions, TextColumn, MaybeArray, IndexColumnOptions, IndexOptions, ForeignKeyOptions, QueryLogObject, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, QueryLogOptions } from 'pqb';
|
|
3
3
|
|
|
4
4
|
declare function add(item: ColumnType, options?: {
|
|
5
5
|
dropMode?: DropMode;
|
|
@@ -15,7 +15,7 @@ declare type ChangeOptions = {
|
|
|
15
15
|
};
|
|
16
16
|
declare type TableChangeMethods = typeof tableChangeMethods;
|
|
17
17
|
declare const tableChangeMethods: {
|
|
18
|
-
raw: (sql: string, values?: false | Record<string, unknown> | undefined) => RawExpression<ColumnType<unknown, pqb.
|
|
18
|
+
raw: (sql: string, values?: false | Record<string, unknown> | undefined) => RawExpression<ColumnType<unknown, pqb.BaseOperators, unknown>>;
|
|
19
19
|
add: typeof add;
|
|
20
20
|
drop: typeof add;
|
|
21
21
|
change(from: ColumnType | Change, to: ColumnType | Change, options?: ChangeOptions): Change;
|
|
@@ -35,9 +35,10 @@ declare type TableOptions = {
|
|
|
35
35
|
noPrimaryKey?: boolean;
|
|
36
36
|
};
|
|
37
37
|
declare type TextColumnCreator = () => TextColumn;
|
|
38
|
-
declare type MigrationColumnTypes = Omit<ColumnTypes, 'text' | 'string'> & {
|
|
38
|
+
declare type MigrationColumnTypes = Omit<ColumnTypes, 'text' | 'string' | 'enum'> & {
|
|
39
39
|
text: TextColumnCreator;
|
|
40
40
|
string: TextColumnCreator;
|
|
41
|
+
enum: (name: string) => EnumColumn;
|
|
41
42
|
};
|
|
42
43
|
declare type ColumnsShapeCallback = (t: MigrationColumnTypes & {
|
|
43
44
|
raw: typeof raw;
|
|
@@ -55,11 +56,6 @@ declare type JoinTableOptions = {
|
|
|
55
56
|
comment?: string;
|
|
56
57
|
dropMode?: DropMode;
|
|
57
58
|
};
|
|
58
|
-
declare type ExtensionOptions = {
|
|
59
|
-
schema?: string;
|
|
60
|
-
version?: string;
|
|
61
|
-
cascade?: boolean;
|
|
62
|
-
};
|
|
63
59
|
declare type Migration = DbResult<DefaultColumnTypes> & MigrationBase;
|
|
64
60
|
declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, options: RakeDbConfig, adapterOptions: AdapterOptions, appCodeUpdaterCache: object) => pqb.Db<string, Record<string, never>, pqb.RelationsBase, {
|
|
65
61
|
smallint: () => pqb.SmallIntColumn;
|
|
@@ -85,7 +81,7 @@ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, op
|
|
|
85
81
|
timeWithTimeZone: <Precision_5 extends number | undefined = undefined>(precision?: Precision_5 | undefined) => pqb.TimeWithTimeZoneColumn<Precision_5>;
|
|
86
82
|
interval: <Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(fields?: Fields | undefined, precision?: Precision_6 | undefined) => pqb.IntervalColumn<Fields, Precision_6>;
|
|
87
83
|
boolean: () => pqb.BooleanColumn;
|
|
88
|
-
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) =>
|
|
84
|
+
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) => EnumColumn<U, T>;
|
|
89
85
|
point: () => pqb.PointColumn;
|
|
90
86
|
line: () => pqb.LineColumn;
|
|
91
87
|
lseg: () => pqb.LsegColumn;
|
|
@@ -139,8 +135,8 @@ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, op
|
|
|
139
135
|
record: typeof pqb.record;
|
|
140
136
|
}) => Type)) => pqb.JSONColumn<Type>;
|
|
141
137
|
jsonText: () => pqb.JSONTextColumn;
|
|
142
|
-
array: <Item extends ColumnType<unknown, pqb.
|
|
143
|
-
timestamps: <T_14 extends ColumnType<unknown, pqb.
|
|
138
|
+
array: <Item extends ColumnType<unknown, pqb.BaseOperators, unknown>>(item: Item) => pqb.ArrayColumn<Item>;
|
|
139
|
+
timestamps: <T_14 extends ColumnType<unknown, pqb.BaseOperators, unknown>>(this: {
|
|
144
140
|
timestamp(): T_14;
|
|
145
141
|
}) => {
|
|
146
142
|
createdAt: T_14 & {
|
|
@@ -184,7 +180,7 @@ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, op
|
|
|
184
180
|
timeWithTimeZone: <Precision_5 extends number | undefined = undefined>(precision?: Precision_5 | undefined) => pqb.TimeWithTimeZoneColumn<Precision_5>;
|
|
185
181
|
interval: <Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(fields?: Fields | undefined, precision?: Precision_6 | undefined) => pqb.IntervalColumn<Fields, Precision_6>;
|
|
186
182
|
boolean: () => pqb.BooleanColumn;
|
|
187
|
-
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) =>
|
|
183
|
+
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) => EnumColumn<U, T>;
|
|
188
184
|
point: () => pqb.PointColumn;
|
|
189
185
|
line: () => pqb.LineColumn;
|
|
190
186
|
lseg: () => pqb.LsegColumn;
|
|
@@ -238,8 +234,8 @@ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, op
|
|
|
238
234
|
record: typeof pqb.record;
|
|
239
235
|
}) => Type)) => pqb.JSONColumn<Type>;
|
|
240
236
|
jsonText: () => pqb.JSONTextColumn;
|
|
241
|
-
array: <Item extends ColumnType<unknown, pqb.
|
|
242
|
-
timestamps: <T_14 extends ColumnType<unknown, pqb.
|
|
237
|
+
array: <Item extends ColumnType<unknown, pqb.BaseOperators, unknown>>(item: Item) => pqb.ArrayColumn<Item>;
|
|
238
|
+
timestamps: <T_14 extends ColumnType<unknown, pqb.BaseOperators, unknown>>(this: {
|
|
243
239
|
timestamp(): T_14;
|
|
244
240
|
}) => {
|
|
245
241
|
createdAt: T_14 & {
|
|
@@ -282,7 +278,7 @@ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, op
|
|
|
282
278
|
timeWithTimeZone: <Precision_5 extends number | undefined = undefined>(precision?: Precision_5 | undefined) => pqb.TimeWithTimeZoneColumn<Precision_5>;
|
|
283
279
|
interval: <Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(fields?: Fields | undefined, precision?: Precision_6 | undefined) => pqb.IntervalColumn<Fields, Precision_6>;
|
|
284
280
|
boolean: () => pqb.BooleanColumn;
|
|
285
|
-
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) =>
|
|
281
|
+
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) => EnumColumn<U, T>;
|
|
286
282
|
point: () => pqb.PointColumn;
|
|
287
283
|
line: () => pqb.LineColumn;
|
|
288
284
|
lseg: () => pqb.LsegColumn;
|
|
@@ -336,8 +332,8 @@ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, op
|
|
|
336
332
|
record: typeof pqb.record;
|
|
337
333
|
}) => Type)) => pqb.JSONColumn<Type>;
|
|
338
334
|
jsonText: () => pqb.JSONTextColumn;
|
|
339
|
-
array: <Item extends ColumnType<unknown, pqb.
|
|
340
|
-
timestamps: <T_14 extends ColumnType<unknown, pqb.
|
|
335
|
+
array: <Item extends ColumnType<unknown, pqb.BaseOperators, unknown>>(item: Item) => pqb.ArrayColumn<Item>;
|
|
336
|
+
timestamps: <T_14 extends ColumnType<unknown, pqb.BaseOperators, unknown>>(this: {
|
|
341
337
|
timestamp(): T_14;
|
|
342
338
|
}) => {
|
|
343
339
|
createdAt: T_14 & {
|
|
@@ -396,20 +392,17 @@ declare class MigrationBase {
|
|
|
396
392
|
renameColumn(tableName: string, from: string, to: string): Promise<void>;
|
|
397
393
|
createSchema(schemaName: string): Promise<void>;
|
|
398
394
|
dropSchema(schemaName: string): Promise<void>;
|
|
399
|
-
createExtension(name: string, options?:
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
ifExists?: boolean;
|
|
404
|
-
cascade?: boolean;
|
|
405
|
-
}): Promise<void>;
|
|
395
|
+
createExtension(name: string, options?: Omit<RakeDbAst.Extension, 'type' | 'action' | 'name'>): Promise<void>;
|
|
396
|
+
dropExtension(name: string, options?: Omit<RakeDbAst.Extension, 'type' | 'action' | 'name' | 'values'>): Promise<void>;
|
|
397
|
+
createEnum(name: string, values: string[], options?: Omit<RakeDbAst.Enum, 'type' | 'action' | 'name' | 'values'>): Promise<void>;
|
|
398
|
+
dropEnum(name: string, values: string[], options?: Omit<RakeDbAst.Enum, 'type' | 'action' | 'name' | 'values'>): Promise<void>;
|
|
406
399
|
tableExists(tableName: string): Promise<boolean>;
|
|
407
400
|
columnExists(tableName: string, columnName: string): Promise<boolean>;
|
|
408
401
|
constraintExists(constraintName: string): Promise<boolean>;
|
|
409
402
|
}
|
|
410
403
|
declare const runCodeUpdater: (migration: MigrationBase, ast: RakeDbAst) => Promise<void> | undefined;
|
|
411
404
|
|
|
412
|
-
declare type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameTable | RakeDbAst.Schema | RakeDbAst.Extension | RakeDbAst.ForeignKey;
|
|
405
|
+
declare type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameTable | RakeDbAst.Schema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.ForeignKey;
|
|
413
406
|
declare namespace RakeDbAst {
|
|
414
407
|
type Table = {
|
|
415
408
|
type: 'table';
|
|
@@ -482,8 +475,21 @@ declare namespace RakeDbAst {
|
|
|
482
475
|
schema?: string;
|
|
483
476
|
version?: string;
|
|
484
477
|
cascade?: boolean;
|
|
485
|
-
|
|
486
|
-
|
|
478
|
+
createIfNotExists?: boolean;
|
|
479
|
+
dropIfExists?: boolean;
|
|
480
|
+
};
|
|
481
|
+
type Enum = {
|
|
482
|
+
type: 'enum';
|
|
483
|
+
action: 'create' | 'drop';
|
|
484
|
+
schema?: string;
|
|
485
|
+
name: string;
|
|
486
|
+
values: string[];
|
|
487
|
+
cascade?: boolean;
|
|
488
|
+
dropIfExists?: boolean;
|
|
489
|
+
};
|
|
490
|
+
type EnumOptions = {
|
|
491
|
+
createIfNotExists?: boolean;
|
|
492
|
+
dropIfExists?: boolean;
|
|
487
493
|
};
|
|
488
494
|
type ForeignKey = {
|
|
489
495
|
type: 'foreignKey';
|
|
@@ -530,4 +536,4 @@ declare const change: (fn: ChangeCallback) => void;
|
|
|
530
536
|
|
|
531
537
|
declare const rakeDb: (options: MaybeArray<AdapterOptions>, partialConfig?: Partial<RakeDbConfig>, args?: string[]) => Promise<void>;
|
|
532
538
|
|
|
533
|
-
export { AppCodeUpdater, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DropMode,
|
|
539
|
+
export { AppCodeUpdater, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DropMode, JoinTableOptions, Migration, MigrationBase, MigrationColumnTypes, RakeDbAst, RakeDbConfig, TableOptions, change, createDb, createMigrationInterface, dropDb, generate, migrate, rakeDb, resetDb, rollback, runCodeUpdater, writeMigrationFile };
|
package/dist/index.js
CHANGED
|
@@ -1077,6 +1077,12 @@ class MigrationBase {
|
|
|
1077
1077
|
dropExtension(name, options = {}) {
|
|
1078
1078
|
return createExtension$1(this, !this.up, name, options);
|
|
1079
1079
|
}
|
|
1080
|
+
createEnum(name, values, options) {
|
|
1081
|
+
return createEnum(this, this.up, name, values, options);
|
|
1082
|
+
}
|
|
1083
|
+
dropEnum(name, values, options) {
|
|
1084
|
+
return createEnum(this, !this.up, name, values, options);
|
|
1085
|
+
}
|
|
1080
1086
|
async tableExists(tableName) {
|
|
1081
1087
|
return queryExists(this, {
|
|
1082
1088
|
text: `SELECT 1 FROM "information_schema"."tables" WHERE "table_name" = $1`,
|
|
@@ -1145,13 +1151,35 @@ const createExtension$1 = async (migration, up, name, options) => {
|
|
|
1145
1151
|
}, options);
|
|
1146
1152
|
let query;
|
|
1147
1153
|
if (ast.action === "drop") {
|
|
1148
|
-
query = `DROP EXTENSION${ast.
|
|
1154
|
+
query = `DROP EXTENSION${ast.dropIfExists ? " IF EXISTS" : ""} "${ast.name}"${ast.cascade ? " CASCADE" : ""}`;
|
|
1149
1155
|
} else {
|
|
1150
|
-
query = `CREATE EXTENSION${ast.
|
|
1156
|
+
query = `CREATE EXTENSION${ast.createIfNotExists ? " IF NOT EXISTS" : ""} "${ast.name}"${ast.schema ? ` SCHEMA "${ast.schema}"` : ""}${ast.version ? ` VERSION '${ast.version}'` : ""}${ast.cascade ? " CASCADE" : ""}`;
|
|
1151
1157
|
}
|
|
1152
1158
|
await migration.adapter.query(query);
|
|
1153
1159
|
await runCodeUpdater(migration, ast);
|
|
1154
1160
|
};
|
|
1161
|
+
const createEnum = async (migration, up, name, values, options = {}) => {
|
|
1162
|
+
const [schema, enumName] = getSchemaAndTableFromName(name);
|
|
1163
|
+
const ast = __spreadValues$2({
|
|
1164
|
+
type: "enum",
|
|
1165
|
+
action: up ? "create" : "drop",
|
|
1166
|
+
schema,
|
|
1167
|
+
name: enumName,
|
|
1168
|
+
values
|
|
1169
|
+
}, options);
|
|
1170
|
+
let text;
|
|
1171
|
+
const quotedName = quoteWithSchema(ast);
|
|
1172
|
+
if (ast.action === "create") {
|
|
1173
|
+
text = `CREATE TYPE ${quotedName} AS ENUM (${values.map((_, i) => `$${i + 1}`).join(", ")})`;
|
|
1174
|
+
} else {
|
|
1175
|
+
text = `DROP TYPE${ast.dropIfExists ? " IF EXISTS" : ""} ${quotedName}${ast.cascade ? " CASCADE" : ""}`;
|
|
1176
|
+
}
|
|
1177
|
+
await migration.adapter.query({
|
|
1178
|
+
text,
|
|
1179
|
+
values
|
|
1180
|
+
});
|
|
1181
|
+
await runCodeUpdater(migration, ast);
|
|
1182
|
+
};
|
|
1155
1183
|
const queryExists = (db, sql) => {
|
|
1156
1184
|
return db.adapter.query(sql).then(({ rowCount }) => rowCount > 0);
|
|
1157
1185
|
};
|