rake-db 2.17.7 → 2.18.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 +610 -243
- package/dist/index.js +2118 -1173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2069 -1175
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,227 @@
|
|
|
1
1
|
import * as orchid_core from 'orchid-core';
|
|
2
|
-
import {
|
|
2
|
+
import { MaybeArray, RawSQLBase, ColumnDataCheckBase, RecordString, EmptyObject, ColumnSchemaConfig, RecordOptionalString, ColumnTypeBase, ForeignKeyTable, Sql, MaybePromise } from 'orchid-core';
|
|
3
3
|
import * as pqb from 'pqb';
|
|
4
|
-
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter, IndexColumnOptions, IndexOptions,
|
|
4
|
+
import { QueryArraysResult, ColumnsShape, Db as Db$1, TableData, NoPrimaryKeyOption, ColumnType, ForeignKeyOptions, SingleColumnIndexOptions, EnumColumn, raw, Adapter, IndexColumnOptions, IndexOptions, DbResult, TransactionAdapter, QueryLogObject, DbDomainArg, TextColumn, AdapterOptions, DefaultColumnTypes, DefaultSchemaConfig, QueryLogOptions, SearchWeight, ColumnsByType, ArrayColumn } from 'pqb';
|
|
5
5
|
|
|
6
|
+
interface TableQuery {
|
|
7
|
+
text: string;
|
|
8
|
+
values?: unknown[];
|
|
9
|
+
then?(result: QueryArraysResult): void;
|
|
10
|
+
}
|
|
6
11
|
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
7
12
|
table: Db$1<Table, Shape>;
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameType | RakeDbAst.Schema | RakeDbAst.RenameSchema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.EnumValues | RakeDbAst.RenameEnumValues | RakeDbAst.ChangeEnumValues | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.RenameTableItem | RakeDbAst.View;
|
|
16
|
+
declare namespace RakeDbAst {
|
|
17
|
+
interface Table extends TableData {
|
|
18
|
+
type: 'table';
|
|
19
|
+
action: 'create' | 'drop';
|
|
20
|
+
schema?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
shape: ColumnsShape;
|
|
23
|
+
noPrimaryKey: NoPrimaryKeyOption;
|
|
24
|
+
createIfNotExists?: boolean;
|
|
25
|
+
dropIfExists?: boolean;
|
|
26
|
+
dropMode?: DropMode;
|
|
27
|
+
comment?: string;
|
|
28
|
+
}
|
|
29
|
+
interface ChangeTable {
|
|
30
|
+
type: 'changeTable';
|
|
31
|
+
schema?: string;
|
|
32
|
+
name: string;
|
|
33
|
+
comment?: string | [string, string] | null;
|
|
34
|
+
shape: ChangeTableShape;
|
|
35
|
+
add: TableData;
|
|
36
|
+
drop: TableData;
|
|
37
|
+
}
|
|
38
|
+
type ChangeTableShape = Record<string, MaybeArray<ChangeTableItem>>;
|
|
39
|
+
type ChangeTableItem = ChangeTableItem.Column | ChangeTableItem.Change | ChangeTableItem.Rename;
|
|
40
|
+
namespace ChangeTableItem {
|
|
41
|
+
interface Column {
|
|
42
|
+
type: 'add' | 'drop';
|
|
43
|
+
item: ColumnType;
|
|
44
|
+
dropMode?: DropMode;
|
|
45
|
+
}
|
|
46
|
+
interface Change {
|
|
47
|
+
type: 'change';
|
|
48
|
+
name?: string;
|
|
49
|
+
from: ColumnChange;
|
|
50
|
+
to: ColumnChange;
|
|
51
|
+
using?: ChangeUsing;
|
|
52
|
+
}
|
|
53
|
+
interface ChangeUsing {
|
|
54
|
+
usingUp?: RawSQLBase;
|
|
55
|
+
usingDown?: RawSQLBase;
|
|
56
|
+
}
|
|
57
|
+
interface Rename {
|
|
58
|
+
type: 'rename';
|
|
59
|
+
name: string;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
interface ColumnChange {
|
|
63
|
+
column?: ColumnType;
|
|
64
|
+
type?: string;
|
|
65
|
+
collate?: string;
|
|
66
|
+
default?: unknown | RawSQLBase;
|
|
67
|
+
nullable?: boolean;
|
|
68
|
+
comment?: string | null;
|
|
69
|
+
compression?: string;
|
|
70
|
+
primaryKey?: boolean;
|
|
71
|
+
check?: ColumnDataCheckBase;
|
|
72
|
+
foreignKeys?: ({
|
|
73
|
+
table: string;
|
|
74
|
+
columns: string[];
|
|
75
|
+
} & ForeignKeyOptions)[];
|
|
76
|
+
indexes?: Omit<SingleColumnIndexOptions, 'column' | 'expression'>[];
|
|
77
|
+
identity?: TableData.Identity;
|
|
78
|
+
}
|
|
79
|
+
interface RenameType {
|
|
80
|
+
type: 'renameType';
|
|
81
|
+
kind: 'TABLE' | 'TYPE' | 'DOMAIN';
|
|
82
|
+
fromSchema?: string;
|
|
83
|
+
from: string;
|
|
84
|
+
toSchema?: string;
|
|
85
|
+
to: string;
|
|
86
|
+
}
|
|
87
|
+
interface Schema {
|
|
88
|
+
type: 'schema';
|
|
89
|
+
action: 'create' | 'drop';
|
|
90
|
+
name: string;
|
|
91
|
+
}
|
|
92
|
+
interface RenameSchema {
|
|
93
|
+
type: 'renameSchema';
|
|
94
|
+
from: string;
|
|
95
|
+
to: string;
|
|
96
|
+
}
|
|
97
|
+
interface ExtensionArg {
|
|
98
|
+
version?: string;
|
|
99
|
+
cascade?: boolean;
|
|
100
|
+
createIfNotExists?: boolean;
|
|
101
|
+
dropIfExists?: boolean;
|
|
102
|
+
}
|
|
103
|
+
interface Extension extends ExtensionArg {
|
|
104
|
+
type: 'extension';
|
|
105
|
+
action: 'create' | 'drop';
|
|
106
|
+
schema?: string;
|
|
107
|
+
name: string;
|
|
108
|
+
}
|
|
109
|
+
interface Enum {
|
|
110
|
+
type: 'enum';
|
|
111
|
+
action: 'create' | 'drop';
|
|
112
|
+
schema?: string;
|
|
113
|
+
name: string;
|
|
114
|
+
values: [string, ...string[]];
|
|
115
|
+
cascade?: boolean;
|
|
116
|
+
dropIfExists?: boolean;
|
|
117
|
+
}
|
|
118
|
+
interface EnumValues {
|
|
119
|
+
type: 'enumValues';
|
|
120
|
+
action: 'add' | 'drop';
|
|
121
|
+
schema?: string;
|
|
122
|
+
name: string;
|
|
123
|
+
values: string[];
|
|
124
|
+
place?: 'before' | 'after';
|
|
125
|
+
relativeTo?: string;
|
|
126
|
+
ifNotExists?: boolean;
|
|
127
|
+
}
|
|
128
|
+
interface RenameEnumValues {
|
|
129
|
+
type: 'renameEnumValues';
|
|
130
|
+
schema?: string;
|
|
131
|
+
name: string;
|
|
132
|
+
values: RecordString;
|
|
133
|
+
}
|
|
134
|
+
interface ChangeEnumValues {
|
|
135
|
+
type: 'changeEnumValues';
|
|
136
|
+
schema?: string;
|
|
137
|
+
name: string;
|
|
138
|
+
fromValues: string[];
|
|
139
|
+
toValues: string[];
|
|
140
|
+
}
|
|
141
|
+
interface Domain {
|
|
142
|
+
type: 'domain';
|
|
143
|
+
action: 'create' | 'drop';
|
|
144
|
+
schema?: string;
|
|
145
|
+
name: string;
|
|
146
|
+
baseType: ColumnType;
|
|
147
|
+
}
|
|
148
|
+
interface Collation {
|
|
149
|
+
type: 'collation';
|
|
150
|
+
action: 'create' | 'drop';
|
|
151
|
+
schema?: string;
|
|
152
|
+
name: string;
|
|
153
|
+
locale?: string;
|
|
154
|
+
lcCollate?: string;
|
|
155
|
+
lcCType?: string;
|
|
156
|
+
provider?: string;
|
|
157
|
+
deterministic?: boolean;
|
|
158
|
+
version?: string;
|
|
159
|
+
fromExisting?: string;
|
|
160
|
+
createIfNotExists?: boolean;
|
|
161
|
+
dropIfExists?: boolean;
|
|
162
|
+
cascade?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface EnumOptions {
|
|
165
|
+
createIfNotExists?: boolean;
|
|
166
|
+
dropIfExists?: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface Constraint extends TableData.Constraint {
|
|
169
|
+
type: 'constraint';
|
|
170
|
+
action: 'create' | 'drop';
|
|
171
|
+
tableSchema?: string;
|
|
172
|
+
tableName: string;
|
|
173
|
+
}
|
|
174
|
+
interface RenameTableItem {
|
|
175
|
+
type: 'renameTableItem';
|
|
176
|
+
kind: 'INDEX' | 'CONSTRAINT';
|
|
177
|
+
tableSchema?: string;
|
|
178
|
+
tableName: string;
|
|
179
|
+
from: string;
|
|
180
|
+
to: string;
|
|
181
|
+
}
|
|
182
|
+
interface View {
|
|
183
|
+
type: 'view';
|
|
184
|
+
action: 'create' | 'drop';
|
|
185
|
+
schema?: string;
|
|
186
|
+
name: string;
|
|
187
|
+
shape: ColumnsShape;
|
|
188
|
+
sql: RawSQLBase;
|
|
189
|
+
options: ViewOptions;
|
|
190
|
+
deps: {
|
|
191
|
+
schemaName: string;
|
|
192
|
+
name: string;
|
|
193
|
+
}[];
|
|
194
|
+
}
|
|
195
|
+
interface ViewOptions {
|
|
196
|
+
createOrReplace?: boolean;
|
|
197
|
+
dropIfExists?: boolean;
|
|
198
|
+
dropMode?: DropMode;
|
|
199
|
+
temporary?: boolean;
|
|
200
|
+
recursive?: boolean;
|
|
201
|
+
columns?: string[];
|
|
202
|
+
with?: {
|
|
203
|
+
checkOption?: 'LOCAL' | 'CASCADED';
|
|
204
|
+
securityBarrier?: boolean;
|
|
205
|
+
securityInvoker?: boolean;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
10
210
|
declare function add(item: ColumnType, options?: {
|
|
11
211
|
dropMode?: DropMode;
|
|
12
|
-
}):
|
|
212
|
+
}): number;
|
|
13
213
|
declare function add(emptyObject: EmptyObject): EmptyObject;
|
|
14
214
|
declare function add(items: Record<string, ColumnType>, options?: {
|
|
15
215
|
dropMode?: DropMode;
|
|
16
216
|
}): Record<string, RakeDbAst.ChangeTableItem.Column>;
|
|
17
217
|
type Change = RakeDbAst.ChangeTableItem.Change & ChangeOptions;
|
|
18
|
-
type ChangeOptions =
|
|
19
|
-
usingUp?: RawSQLBase;
|
|
20
|
-
usingDown?: RawSQLBase;
|
|
21
|
-
};
|
|
218
|
+
type ChangeOptions = RakeDbAst.ChangeTableItem.ChangeUsing;
|
|
22
219
|
type TableChangeMethods = typeof tableChangeMethods;
|
|
23
220
|
declare const tableChangeMethods: {
|
|
24
221
|
name(this: RakeDbColumnTypes, name: string): any;
|
|
25
222
|
add: typeof add;
|
|
26
223
|
drop: typeof add;
|
|
27
|
-
change(from: ColumnType | Change, to: ColumnType | Change,
|
|
224
|
+
change(from: ColumnType | Change, to: ColumnType | Change, using?: ChangeOptions): Change;
|
|
28
225
|
default(value: unknown | RawSQLBase): Change;
|
|
29
226
|
nullable(): Change;
|
|
30
227
|
nonNullable(): Change;
|
|
@@ -46,9 +243,8 @@ type TableOptions = {
|
|
|
46
243
|
language?: string;
|
|
47
244
|
};
|
|
48
245
|
type TextColumnCreator = (min?: number, max?: number) => TextColumn<ColumnSchemaConfig>;
|
|
49
|
-
type MigrationColumnTypes<CT> = Omit<CT, 'text' | '
|
|
246
|
+
type MigrationColumnTypes<CT> = Omit<CT, 'text' | 'citext' | 'enum'> & {
|
|
50
247
|
text: TextColumnCreator;
|
|
51
|
-
string: TextColumnCreator;
|
|
52
248
|
citext: TextColumnCreator;
|
|
53
249
|
enum: (name: string) => EnumColumn<ColumnSchemaConfig, unknown>;
|
|
54
250
|
};
|
|
@@ -99,9 +295,8 @@ type DbMigration<CT extends RakeDbColumnTypes> = DbResult<CT> & Migration<CT> &
|
|
|
99
295
|
* @param tx - database adapter that executes inside a transaction
|
|
100
296
|
* @param up - migrate or rollback
|
|
101
297
|
* @param config - config of `rakeDb`
|
|
102
|
-
* @param asts - array of migration ASTs to collect changes into
|
|
103
298
|
*/
|
|
104
|
-
declare const createMigrationInterface: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT extends RakeDbColumnTypes>(tx: TransactionAdapter, up: boolean, config: RakeDbConfig<SchemaConfig, CT
|
|
299
|
+
declare const createMigrationInterface: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT extends RakeDbColumnTypes>(tx: TransactionAdapter, up: boolean, config: RakeDbConfig<SchemaConfig, CT>) => DbMigration<CT>;
|
|
105
300
|
interface MigrationAdapter extends TransactionAdapter {
|
|
106
301
|
schema: string;
|
|
107
302
|
}
|
|
@@ -110,7 +305,6 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
110
305
|
log?: QueryLogObject;
|
|
111
306
|
up: boolean;
|
|
112
307
|
options: RakeDbConfig<ColumnSchemaConfig>;
|
|
113
|
-
migratedAsts: RakeDbAst[];
|
|
114
308
|
columnTypes: CT;
|
|
115
309
|
/**
|
|
116
310
|
* `createTable` accepts a string for a table name, optional options, and a callback to specify columns.
|
|
@@ -348,6 +542,23 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
348
542
|
* @param options - index options
|
|
349
543
|
*/
|
|
350
544
|
dropIndex(tableName: string, columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): Promise<void>;
|
|
545
|
+
/**
|
|
546
|
+
* Rename index:
|
|
547
|
+
*
|
|
548
|
+
* ```ts
|
|
549
|
+
* import { change } from '../dbScript';
|
|
550
|
+
*
|
|
551
|
+
* change(async (db) => {
|
|
552
|
+
* // tableName can be prefixed with a schema
|
|
553
|
+
* await db.renameIndex('tableName', 'oldIndexName', 'newIndexName');
|
|
554
|
+
* });
|
|
555
|
+
* ```
|
|
556
|
+
*
|
|
557
|
+
* @param tableName - table which this index belongs to
|
|
558
|
+
* @param from - rename the index from
|
|
559
|
+
* @param to - rename the index to
|
|
560
|
+
*/
|
|
561
|
+
renameIndex(tableName: string, from: string, to: string): Promise<void>;
|
|
351
562
|
/**
|
|
352
563
|
* Add a foreign key to a table on migrating, and remove it on rollback.
|
|
353
564
|
*
|
|
@@ -487,6 +698,26 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
487
698
|
* @param constraint - constraint config object
|
|
488
699
|
*/
|
|
489
700
|
dropConstraint(tableName: string, constraint: ConstraintArg): Promise<void>;
|
|
701
|
+
/**
|
|
702
|
+
* Rename a table constraint, such as primary key, or check.
|
|
703
|
+
*
|
|
704
|
+
* ```ts
|
|
705
|
+
* import { change } from '../dbScript';
|
|
706
|
+
*
|
|
707
|
+
* change(async (db) => {
|
|
708
|
+
* await db.renameConstraint(
|
|
709
|
+
* 'tableName', // may include schema: 'schema.table'
|
|
710
|
+
* 'oldConstraintName',
|
|
711
|
+
* 'newConstraintName',
|
|
712
|
+
* );
|
|
713
|
+
* });
|
|
714
|
+
* ```
|
|
715
|
+
*
|
|
716
|
+
* @param tableName - name of the table containing the constraint, may include schema name, may include schema name
|
|
717
|
+
* @param from - current name of the constraint
|
|
718
|
+
* @param to - desired name
|
|
719
|
+
*/
|
|
720
|
+
renameConstraint(tableName: string, from: string, to: string): Promise<void>;
|
|
490
721
|
/**
|
|
491
722
|
* Rename a column:
|
|
492
723
|
*
|
|
@@ -519,6 +750,21 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
519
750
|
* @param schemaName - name of the schema
|
|
520
751
|
*/
|
|
521
752
|
createSchema(schemaName: string): Promise<void>;
|
|
753
|
+
/**
|
|
754
|
+
* Renames a database schema, renames it backwards on roll back.
|
|
755
|
+
*
|
|
756
|
+
* ```ts
|
|
757
|
+
* import { change } from '../dbScript';
|
|
758
|
+
*
|
|
759
|
+
* change(async (db) => {
|
|
760
|
+
* await db.renameSchema('from', 'to');
|
|
761
|
+
* });
|
|
762
|
+
* ```
|
|
763
|
+
*
|
|
764
|
+
* @param from - existing schema to rename
|
|
765
|
+
* @param to - desired schema name
|
|
766
|
+
*/
|
|
767
|
+
renameSchema(from: string, to: string): Promise<void>;
|
|
522
768
|
/**
|
|
523
769
|
* Drop the schema, create it on rollback. See {@link createSchema}.
|
|
524
770
|
*
|
|
@@ -541,14 +787,14 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
541
787
|
* @param name - name of the extension
|
|
542
788
|
* @param options - extension options
|
|
543
789
|
*/
|
|
544
|
-
createExtension(name: string, options?:
|
|
790
|
+
createExtension(name: string, options?: RakeDbAst.ExtensionArg): Promise<void>;
|
|
545
791
|
/**
|
|
546
792
|
* Drop the extension, create it on rollback. See {@link createExtension}.
|
|
547
793
|
*
|
|
548
794
|
* @param name - name of the extension
|
|
549
795
|
* @param options - extension options
|
|
550
796
|
*/
|
|
551
|
-
dropExtension(name: string, options?:
|
|
797
|
+
dropExtension(name: string, options?: RakeDbAst.ExtensionArg): Promise<void>;
|
|
552
798
|
/**
|
|
553
799
|
* `createEnum` creates an enum on migrate, drops it on rollback.
|
|
554
800
|
*
|
|
@@ -720,45 +966,62 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
720
966
|
*/
|
|
721
967
|
changeTypeSchema(name: string, from: string, to: string): Promise<void>;
|
|
722
968
|
/**
|
|
723
|
-
* Domain is a custom database type that
|
|
969
|
+
* Domain is a custom database type that is based on other type and can include `NOT NULL` and a `CHECK` (see [postgres tutorial](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-user-defined-data-types/)).
|
|
970
|
+
*
|
|
971
|
+
* Construct a column type in the function as the second argument.
|
|
724
972
|
*
|
|
725
|
-
*
|
|
973
|
+
* Specifiers [nullable](/guide/common-column-methods.html#nullable), [default](/guide/common-column-methods.html#default), [check](/guide/migration-column-methods.html#check), [collate](/guide/migration-column-methods.html#collate)
|
|
974
|
+
* will be saved to the domain type on database level.
|
|
726
975
|
*
|
|
727
976
|
* ```ts
|
|
728
977
|
* import { change } from '../dbScript';
|
|
729
978
|
*
|
|
730
979
|
* change(async (db) => {
|
|
731
|
-
* await db.createDomain('domainName', (t) =>
|
|
732
|
-
* check
|
|
733
|
-
*
|
|
980
|
+
* await db.createDomain('domainName', (t) =>
|
|
981
|
+
* t.integer().check(db.sql`value = 42`),
|
|
982
|
+
* );
|
|
734
983
|
*
|
|
735
984
|
* // use `schemaName.domainName` format to specify a schema
|
|
736
|
-
* await db.createDomain('schemaName.domainName', (t) =>
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
* cascade: true,
|
|
745
|
-
* });
|
|
985
|
+
* await db.createDomain('schemaName.domainName', (t) =>
|
|
986
|
+
* t
|
|
987
|
+
* .text()
|
|
988
|
+
* .nullable()
|
|
989
|
+
* .collate('C')
|
|
990
|
+
* .default('default text')
|
|
991
|
+
* .check(db.sql`length(value) > 10`),
|
|
992
|
+
* );
|
|
746
993
|
* });
|
|
747
994
|
* ```
|
|
748
995
|
*
|
|
749
996
|
* @param name - name of the domain
|
|
750
|
-
* @param fn - function returning a column type
|
|
751
|
-
* @param options - domain options
|
|
997
|
+
* @param fn - function returning a column type. Options `nullable`, `collate`, `default`, `check` will be applied to domain
|
|
752
998
|
*/
|
|
753
|
-
createDomain(name: string, fn:
|
|
999
|
+
createDomain(name: string, fn: DbDomainArg<CT>): Promise<void>;
|
|
754
1000
|
/**
|
|
755
1001
|
* Drop the domain, create it on rollback. See {@link dropDomain}.
|
|
756
1002
|
*
|
|
757
1003
|
* @param name - name of the domain
|
|
758
|
-
* @param fn - function returning a column type
|
|
759
|
-
|
|
1004
|
+
* @param fn - function returning a column type. Options `nullable`, `collate`, `default`, `check` will be applied to domain
|
|
1005
|
+
*/
|
|
1006
|
+
dropDomain(name: string, fn: DbDomainArg<CT>): Promise<void>;
|
|
1007
|
+
/**
|
|
1008
|
+
* To rename a domain:
|
|
1009
|
+
*
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* import { change } from '../dbScript';
|
|
1012
|
+
*
|
|
1013
|
+
* change(async (db) => {
|
|
1014
|
+
* await db.renameDomain('oldName', 'newName');
|
|
1015
|
+
*
|
|
1016
|
+
* // to move domain to a different schema
|
|
1017
|
+
* await db.renameDomain('oldSchema.domain', 'newSchema.domain');
|
|
1018
|
+
* });
|
|
1019
|
+
* ```
|
|
1020
|
+
*
|
|
1021
|
+
* @param from - old domain name (can include schema)
|
|
1022
|
+
* @param to - new domain name (can include schema)
|
|
760
1023
|
*/
|
|
761
|
-
|
|
1024
|
+
renameDomain(from: string, to: string): Promise<void>;
|
|
762
1025
|
/**
|
|
763
1026
|
* Create and drop a database collation, (see [Postgres docs](https://www.postgresql.org/docs/current/sql-createcollation.html)).
|
|
764
1027
|
*
|
|
@@ -968,7 +1231,7 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
968
1231
|
*/
|
|
969
1232
|
constraintExists(constraintName: string): Promise<boolean>;
|
|
970
1233
|
}
|
|
971
|
-
declare const renameType: (migration: Migration<RakeDbColumnTypes>, from: string, to: string,
|
|
1234
|
+
declare const renameType: (migration: Migration<RakeDbColumnTypes>, from: string, to: string, kind: RakeDbAst.RenameType['kind']) => Promise<void>;
|
|
972
1235
|
interface AddEnumValueOptions {
|
|
973
1236
|
ifNotExists?: boolean;
|
|
974
1237
|
before?: string;
|
|
@@ -977,185 +1240,39 @@ interface AddEnumValueOptions {
|
|
|
977
1240
|
declare const addOrDropEnumValues: (migration: Migration<RakeDbColumnTypes>, up: boolean, enumName: string, values: string[], options?: AddEnumValueOptions) => Promise<void>;
|
|
978
1241
|
declare const changeEnumValues: (migration: Migration<RakeDbColumnTypes>, enumName: string, fromValues: string[], toValues: string[]) => Promise<void>;
|
|
979
1242
|
|
|
980
|
-
type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameType | RakeDbAst.Schema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.EnumValues | RakeDbAst.RenameEnumValues | RakeDbAst.ChangeEnumValues | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.View;
|
|
981
|
-
declare namespace RakeDbAst {
|
|
982
|
-
interface Table extends TableData {
|
|
983
|
-
type: 'table';
|
|
984
|
-
action: 'create' | 'drop';
|
|
985
|
-
schema?: string;
|
|
986
|
-
name: string;
|
|
987
|
-
shape: ColumnsShape;
|
|
988
|
-
noPrimaryKey: NoPrimaryKeyOption;
|
|
989
|
-
createIfNotExists?: boolean;
|
|
990
|
-
dropIfExists?: boolean;
|
|
991
|
-
dropMode?: DropMode;
|
|
992
|
-
comment?: string;
|
|
993
|
-
}
|
|
994
|
-
interface ChangeTable {
|
|
995
|
-
type: 'changeTable';
|
|
996
|
-
schema?: string;
|
|
997
|
-
name: string;
|
|
998
|
-
comment?: string | null;
|
|
999
|
-
shape: Record<string, ChangeTableItem>;
|
|
1000
|
-
add: TableData;
|
|
1001
|
-
drop: TableData;
|
|
1002
|
-
}
|
|
1003
|
-
type ChangeTableItem = ChangeTableItem.Column | ChangeTableItem.Change | ChangeTableItem.Rename;
|
|
1004
|
-
namespace ChangeTableItem {
|
|
1005
|
-
interface Column {
|
|
1006
|
-
type: 'add' | 'drop';
|
|
1007
|
-
item: ColumnType;
|
|
1008
|
-
dropMode?: DropMode;
|
|
1009
|
-
}
|
|
1010
|
-
interface Change {
|
|
1011
|
-
type: 'change';
|
|
1012
|
-
name?: string;
|
|
1013
|
-
from: ColumnChange;
|
|
1014
|
-
to: ColumnChange;
|
|
1015
|
-
using?: RawSQLBase;
|
|
1016
|
-
}
|
|
1017
|
-
interface Rename {
|
|
1018
|
-
type: 'rename';
|
|
1019
|
-
name: string;
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
interface ColumnChange {
|
|
1023
|
-
column?: ColumnType;
|
|
1024
|
-
type?: string;
|
|
1025
|
-
collate?: string;
|
|
1026
|
-
default?: unknown | RawSQLBase;
|
|
1027
|
-
nullable?: boolean;
|
|
1028
|
-
comment?: string | null;
|
|
1029
|
-
compression?: string;
|
|
1030
|
-
primaryKey?: boolean;
|
|
1031
|
-
check?: RawSQLBase;
|
|
1032
|
-
foreignKeys?: ({
|
|
1033
|
-
table: string;
|
|
1034
|
-
columns: string[];
|
|
1035
|
-
} & ForeignKeyOptions)[];
|
|
1036
|
-
indexes?: Omit<SingleColumnIndexOptions, 'column' | 'expression'>[];
|
|
1037
|
-
identity?: TableData.Identity;
|
|
1038
|
-
}
|
|
1039
|
-
interface RenameType {
|
|
1040
|
-
type: 'renameType';
|
|
1041
|
-
table: boolean;
|
|
1042
|
-
fromSchema?: string;
|
|
1043
|
-
from: string;
|
|
1044
|
-
toSchema?: string;
|
|
1045
|
-
to: string;
|
|
1046
|
-
}
|
|
1047
|
-
interface Schema {
|
|
1048
|
-
type: 'schema';
|
|
1049
|
-
action: 'create' | 'drop';
|
|
1050
|
-
name: string;
|
|
1051
|
-
}
|
|
1052
|
-
interface Extension {
|
|
1053
|
-
type: 'extension';
|
|
1054
|
-
action: 'create' | 'drop';
|
|
1055
|
-
name: string;
|
|
1056
|
-
schema?: string;
|
|
1057
|
-
version?: string;
|
|
1058
|
-
cascade?: boolean;
|
|
1059
|
-
createIfNotExists?: boolean;
|
|
1060
|
-
dropIfExists?: boolean;
|
|
1061
|
-
}
|
|
1062
|
-
interface Enum {
|
|
1063
|
-
type: 'enum';
|
|
1064
|
-
action: 'create' | 'drop';
|
|
1065
|
-
schema?: string;
|
|
1066
|
-
name: string;
|
|
1067
|
-
values: [string, ...string[]];
|
|
1068
|
-
cascade?: boolean;
|
|
1069
|
-
dropIfExists?: boolean;
|
|
1070
|
-
}
|
|
1071
|
-
interface EnumValues {
|
|
1072
|
-
type: 'enumValues';
|
|
1073
|
-
action: 'add' | 'drop';
|
|
1074
|
-
schema?: string;
|
|
1075
|
-
name: string;
|
|
1076
|
-
values: string[];
|
|
1077
|
-
place?: 'before' | 'after';
|
|
1078
|
-
relativeTo?: string;
|
|
1079
|
-
ifNotExists?: boolean;
|
|
1080
|
-
}
|
|
1081
|
-
interface RenameEnumValues {
|
|
1082
|
-
type: 'renameEnumValues';
|
|
1083
|
-
schema?: string;
|
|
1084
|
-
name: string;
|
|
1085
|
-
values: RecordString;
|
|
1086
|
-
}
|
|
1087
|
-
interface ChangeEnumValues {
|
|
1088
|
-
type: 'changeEnumValues';
|
|
1089
|
-
schema?: string;
|
|
1090
|
-
name: string;
|
|
1091
|
-
fromValues: string[];
|
|
1092
|
-
toValues: string[];
|
|
1093
|
-
}
|
|
1094
|
-
interface Domain {
|
|
1095
|
-
type: 'domain';
|
|
1096
|
-
action: 'create' | 'drop';
|
|
1097
|
-
schema?: string;
|
|
1098
|
-
name: string;
|
|
1099
|
-
baseType: ColumnTypeBase;
|
|
1100
|
-
notNull?: boolean;
|
|
1101
|
-
collation?: string;
|
|
1102
|
-
default?: RawSQLBase;
|
|
1103
|
-
check?: RawSQLBase;
|
|
1104
|
-
cascade?: boolean;
|
|
1105
|
-
}
|
|
1106
|
-
interface Collation {
|
|
1107
|
-
type: 'collation';
|
|
1108
|
-
action: 'create' | 'drop';
|
|
1109
|
-
schema?: string;
|
|
1110
|
-
name: string;
|
|
1111
|
-
locale?: string;
|
|
1112
|
-
lcCollate?: string;
|
|
1113
|
-
lcCType?: string;
|
|
1114
|
-
provider?: string;
|
|
1115
|
-
deterministic?: boolean;
|
|
1116
|
-
version?: string;
|
|
1117
|
-
fromExisting?: string;
|
|
1118
|
-
createIfNotExists?: boolean;
|
|
1119
|
-
dropIfExists?: boolean;
|
|
1120
|
-
cascade?: boolean;
|
|
1121
|
-
}
|
|
1122
|
-
interface EnumOptions {
|
|
1123
|
-
createIfNotExists?: boolean;
|
|
1124
|
-
dropIfExists?: boolean;
|
|
1125
|
-
}
|
|
1126
|
-
interface Constraint extends TableData.Constraint {
|
|
1127
|
-
type: 'constraint';
|
|
1128
|
-
action: 'create';
|
|
1129
|
-
tableSchema?: string;
|
|
1130
|
-
tableName: string;
|
|
1131
|
-
}
|
|
1132
|
-
interface View {
|
|
1133
|
-
type: 'view';
|
|
1134
|
-
action: 'create' | 'drop';
|
|
1135
|
-
schema?: string;
|
|
1136
|
-
name: string;
|
|
1137
|
-
shape: ColumnsShape;
|
|
1138
|
-
sql: RawSQLBase;
|
|
1139
|
-
options: ViewOptions;
|
|
1140
|
-
}
|
|
1141
|
-
interface ViewOptions {
|
|
1142
|
-
createOrReplace?: boolean;
|
|
1143
|
-
dropIfExists?: boolean;
|
|
1144
|
-
dropMode?: DropMode;
|
|
1145
|
-
temporary?: boolean;
|
|
1146
|
-
recursive?: boolean;
|
|
1147
|
-
columns?: string[];
|
|
1148
|
-
with?: {
|
|
1149
|
-
checkOption?: 'LOCAL' | 'CASCADED';
|
|
1150
|
-
securityBarrier?: boolean;
|
|
1151
|
-
securityInvoker?: boolean;
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
1243
|
interface RakeDbCtx {
|
|
1157
1244
|
migrationsPromise?: Promise<MigrationsSet>;
|
|
1158
1245
|
}
|
|
1246
|
+
declare const getFirstWordAndRest: (input: string) => [
|
|
1247
|
+
string
|
|
1248
|
+
] | [
|
|
1249
|
+
string,
|
|
1250
|
+
string
|
|
1251
|
+
];
|
|
1252
|
+
declare const getTextAfterTo: (input: string) => string | undefined;
|
|
1253
|
+
declare const getTextAfterFrom: (input: string) => string | undefined;
|
|
1254
|
+
declare const joinWords: (...words: string[]) => string;
|
|
1255
|
+
declare const joinColumns: (columns: string[]) => string;
|
|
1256
|
+
declare const quoteWithSchema: ({ schema, name, }: {
|
|
1257
|
+
schema?: string;
|
|
1258
|
+
name: string;
|
|
1259
|
+
}) => string;
|
|
1260
|
+
declare const quoteTable: (schema: string | undefined, table: string) => string;
|
|
1261
|
+
declare const getSchemaAndTableFromName: (name: string) => [string | undefined, string];
|
|
1262
|
+
declare const quoteNameFromString: (string: string) => string;
|
|
1263
|
+
declare const quoteSchemaTable: (arg: {
|
|
1264
|
+
schema?: string;
|
|
1265
|
+
name: string;
|
|
1266
|
+
}) => string;
|
|
1267
|
+
declare const concatSchemaAndName: ({ schema, name, }: {
|
|
1268
|
+
schema?: string;
|
|
1269
|
+
name: string;
|
|
1270
|
+
}) => string;
|
|
1271
|
+
declare const makePopulateEnumQuery: (item: EnumColumn<ColumnSchemaConfig, unknown>) => TableQuery;
|
|
1272
|
+
declare const transaction: <T>(adapter: Adapter, fn: (trx: TransactionAdapter) => Promise<T>) => Promise<T>;
|
|
1273
|
+
declare const queryLock: (trx: TransactionAdapter) => Promise<pqb.QueryResult<any>>;
|
|
1274
|
+
declare const exhaustive: (_: never) => never;
|
|
1275
|
+
declare const pluralize: (w: string, count: number, append?: string) => string;
|
|
1159
1276
|
|
|
1160
1277
|
interface MigrationItem {
|
|
1161
1278
|
path: string;
|
|
@@ -1172,6 +1289,7 @@ interface MigrationsSet {
|
|
|
1172
1289
|
migrations: MigrationItem[];
|
|
1173
1290
|
}
|
|
1174
1291
|
|
|
1292
|
+
type CommandFn<SchemaConfig extends ColumnSchemaConfig, CT> = (options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT>, args: string[]) => void | Promise<void>;
|
|
1175
1293
|
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends QueryLogOptions {
|
|
1176
1294
|
schemaConfig: SchemaConfig;
|
|
1177
1295
|
columnTypes: CT;
|
|
@@ -1184,11 +1302,9 @@ interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColu
|
|
|
1184
1302
|
migrationsTable: string;
|
|
1185
1303
|
snakeCase: boolean;
|
|
1186
1304
|
language?: string;
|
|
1187
|
-
commands: Record<string,
|
|
1305
|
+
commands: Record<string, CommandFn<SchemaConfig, CT>>;
|
|
1188
1306
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
1189
1307
|
baseTable?: RakeDbBaseTable<CT>;
|
|
1190
|
-
appCodeUpdater?: AppCodeUpdater;
|
|
1191
|
-
useCodeUpdater?: boolean;
|
|
1192
1308
|
forceDefaultExports?: boolean;
|
|
1193
1309
|
import(path: string): Promise<unknown>;
|
|
1194
1310
|
beforeChange?: ChangeCallback$1;
|
|
@@ -1214,8 +1330,6 @@ interface InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> extends
|
|
|
1214
1330
|
language?: string;
|
|
1215
1331
|
commands?: Record<string, (options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT extends undefined ? DefaultColumnTypes<DefaultSchemaConfig> : CT>, args: string[]) => void | Promise<void>>;
|
|
1216
1332
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
1217
|
-
appCodeUpdater?: AppCodeUpdater;
|
|
1218
|
-
useCodeUpdater?: boolean;
|
|
1219
1333
|
forceDefaultExports?: boolean;
|
|
1220
1334
|
import?(path: string): Promise<unknown>;
|
|
1221
1335
|
/**
|
|
@@ -1307,23 +1421,6 @@ interface ModuleExportsRecord {
|
|
|
1307
1421
|
[K: string]: () => Promise<unknown>;
|
|
1308
1422
|
}
|
|
1309
1423
|
type RakeDbMigrationId = 'serial' | 'timestamp';
|
|
1310
|
-
interface AppCodeUpdaterParams {
|
|
1311
|
-
options: AdapterOptions;
|
|
1312
|
-
basePath: string;
|
|
1313
|
-
cache: object;
|
|
1314
|
-
logger: QueryLogOptions['logger'];
|
|
1315
|
-
baseTable: {
|
|
1316
|
-
getFilePath(): string;
|
|
1317
|
-
exportAs: string;
|
|
1318
|
-
};
|
|
1319
|
-
import(path: string): Promise<unknown>;
|
|
1320
|
-
}
|
|
1321
|
-
interface AppCodeUpdater {
|
|
1322
|
-
process(params: AppCodeUpdaterParams & {
|
|
1323
|
-
ast: RakeDbAst;
|
|
1324
|
-
}): Promise<void>;
|
|
1325
|
-
afterAll(params: AppCodeUpdaterParams): Promise<void>;
|
|
1326
|
-
}
|
|
1327
1424
|
declare const migrationConfigDefaults: {
|
|
1328
1425
|
schemaConfig: DefaultSchemaConfig;
|
|
1329
1426
|
migrationsPath: string;
|
|
@@ -1334,7 +1431,6 @@ declare const migrationConfigDefaults: {
|
|
|
1334
1431
|
import: (path: string) => Promise<any>;
|
|
1335
1432
|
log: true;
|
|
1336
1433
|
logger: Console;
|
|
1337
|
-
useCodeUpdater: true;
|
|
1338
1434
|
};
|
|
1339
1435
|
declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(config: InputRakeDbConfig<SchemaConfig, CT>) => RakeDbConfig<SchemaConfig, CT>;
|
|
1340
1436
|
declare const getDatabaseAndUserFromOptions: (options: AdapterOptions) => {
|
|
@@ -1346,12 +1442,15 @@ declare const createDb: <SchemaConfig extends ColumnSchemaConfig<orchid_core.Col
|
|
|
1346
1442
|
declare const dropDb: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1347
1443
|
declare const resetDb: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT extends RakeDbColumnTypes>(options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1348
1444
|
|
|
1349
|
-
declare const writeMigrationFile:
|
|
1350
|
-
declare const
|
|
1445
|
+
declare const writeMigrationFile: (config: AnyRakeDbConfig, version: string, name: string, migrationCode: string) => Promise<void>;
|
|
1446
|
+
declare const newMigration: (config: AnyRakeDbConfig, [name]: string[]) => Promise<void>;
|
|
1351
1447
|
declare const makeFileVersion: (ctx: RakeDbCtx, config: AnyRakeDbConfig) => Promise<string>;
|
|
1352
1448
|
declare const generateTimeStamp: () => string;
|
|
1353
1449
|
|
|
1354
1450
|
type ChangeCallback<CT extends RakeDbColumnTypes> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1451
|
+
declare const clearChanges: () => void;
|
|
1452
|
+
declare const getCurrentChanges: () => ChangeCallback<RakeDbColumnTypes>[];
|
|
1453
|
+
declare const pushChange: (fn: ChangeCallback<RakeDbColumnTypes>) => number;
|
|
1355
1454
|
|
|
1356
1455
|
declare const saveMigratedVersion: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1357
1456
|
declare const deleteMigratedVersion: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
@@ -1364,14 +1463,14 @@ type RakeDbAppliedVersions = {
|
|
|
1364
1463
|
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(ctx: RakeDbCtx, adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>, renameTo?: RakeDbMigrationId) => Promise<RakeDbAppliedVersions>;
|
|
1365
1464
|
|
|
1366
1465
|
declare const RAKE_DB_LOCK_KEY = "8582141715823621641";
|
|
1367
|
-
type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(ctx: RakeDbCtx, options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<
|
|
1466
|
+
type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(ctx: RakeDbCtx, options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT>, args?: string[], adapters?: Adapter[], dontClose?: boolean) => Promise<Adapter[]>;
|
|
1368
1467
|
/**
|
|
1369
1468
|
* Will run all pending yet migrations, sequentially in order,
|
|
1370
1469
|
* will apply `change` functions top-to-bottom.
|
|
1371
1470
|
*
|
|
1372
1471
|
* @param options - options to construct db adapter with
|
|
1373
|
-
* @param config - specifies how to load migrations,
|
|
1374
|
-
* @param args - pass none or `all` to run all migrations, pass int for how many to migrate
|
|
1472
|
+
* @param config - specifies how to load migrations, callbacks, and logger
|
|
1473
|
+
* @param args - pass none or `all` to run all migrations, pass int for how many to migrate
|
|
1375
1474
|
*/
|
|
1376
1475
|
declare const migrate: MigrateFn;
|
|
1377
1476
|
/**
|
|
@@ -1387,9 +1486,238 @@ declare const rollback: MigrateFn;
|
|
|
1387
1486
|
* Takes the same options as {@link migrate}.
|
|
1388
1487
|
*/
|
|
1389
1488
|
declare const redo: MigrateFn;
|
|
1390
|
-
declare const migrateOrRollback: (trx: TransactionAdapter, config: RakeDbConfig<ColumnSchemaConfig, RakeDbColumnTypes>, set: MigrationsSet, versions: RakeDbAppliedVersions, count: number,
|
|
1489
|
+
declare const migrateOrRollback: (trx: TransactionAdapter, config: RakeDbConfig<ColumnSchemaConfig, RakeDbColumnTypes>, set: MigrationsSet, versions: RakeDbAppliedVersions, count: number, up: boolean, redo: boolean, force?: boolean, skipLock?: boolean) => Promise<void>;
|
|
1391
1490
|
declare const changeCache: Record<string, ChangeCallback<RakeDbColumnTypes>[] | undefined>;
|
|
1392
1491
|
|
|
1492
|
+
declare namespace DbStructure {
|
|
1493
|
+
interface Table {
|
|
1494
|
+
schemaName: string;
|
|
1495
|
+
name: string;
|
|
1496
|
+
comment?: string;
|
|
1497
|
+
columns: Column[];
|
|
1498
|
+
}
|
|
1499
|
+
interface View {
|
|
1500
|
+
schemaName: string;
|
|
1501
|
+
name: string;
|
|
1502
|
+
deps: RakeDbAst.View['deps'];
|
|
1503
|
+
isRecursive: boolean;
|
|
1504
|
+
with?: string[];
|
|
1505
|
+
columns: Column[];
|
|
1506
|
+
sql: string;
|
|
1507
|
+
}
|
|
1508
|
+
interface Procedure {
|
|
1509
|
+
schemaName: string;
|
|
1510
|
+
name: string;
|
|
1511
|
+
returnSet: boolean;
|
|
1512
|
+
returnType: string;
|
|
1513
|
+
kind: string;
|
|
1514
|
+
isTrigger: boolean;
|
|
1515
|
+
types: string[];
|
|
1516
|
+
argTypes: string[];
|
|
1517
|
+
argModes: ('i' | 'o')[];
|
|
1518
|
+
argNames?: string[];
|
|
1519
|
+
}
|
|
1520
|
+
interface Column {
|
|
1521
|
+
schemaName: string;
|
|
1522
|
+
tableName: string;
|
|
1523
|
+
name: string;
|
|
1524
|
+
typeSchema: string;
|
|
1525
|
+
type: string;
|
|
1526
|
+
isArray: boolean;
|
|
1527
|
+
maxChars?: number;
|
|
1528
|
+
numericPrecision?: number;
|
|
1529
|
+
numericScale?: number;
|
|
1530
|
+
dateTimePrecision?: number;
|
|
1531
|
+
default?: string;
|
|
1532
|
+
isNullable: boolean;
|
|
1533
|
+
collate?: string;
|
|
1534
|
+
compression?: 'pglz' | 'lz4';
|
|
1535
|
+
comment?: string;
|
|
1536
|
+
identity?: {
|
|
1537
|
+
always: boolean;
|
|
1538
|
+
start: number;
|
|
1539
|
+
increment: number;
|
|
1540
|
+
min?: number;
|
|
1541
|
+
max?: number;
|
|
1542
|
+
cache: number;
|
|
1543
|
+
cycle: boolean;
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
interface Index {
|
|
1547
|
+
schemaName: string;
|
|
1548
|
+
tableName: string;
|
|
1549
|
+
name: string;
|
|
1550
|
+
using: string;
|
|
1551
|
+
unique: boolean;
|
|
1552
|
+
columns: (({
|
|
1553
|
+
column: string;
|
|
1554
|
+
} | {
|
|
1555
|
+
expression: string;
|
|
1556
|
+
}) & {
|
|
1557
|
+
collate?: string;
|
|
1558
|
+
opclass?: string;
|
|
1559
|
+
order?: string;
|
|
1560
|
+
weight?: SearchWeight;
|
|
1561
|
+
})[];
|
|
1562
|
+
include?: string[];
|
|
1563
|
+
nullsNotDistinct?: boolean;
|
|
1564
|
+
with?: string;
|
|
1565
|
+
tablespace?: string;
|
|
1566
|
+
where?: string;
|
|
1567
|
+
tsVector?: boolean;
|
|
1568
|
+
language?: string;
|
|
1569
|
+
languageColumn?: string;
|
|
1570
|
+
}
|
|
1571
|
+
type ForeignKeyMatch = 'f' | 'p' | 's';
|
|
1572
|
+
type ForeignKeyAction = 'a' | 'r' | 'c' | 'n' | 'd';
|
|
1573
|
+
interface Constraint {
|
|
1574
|
+
schemaName: string;
|
|
1575
|
+
tableName: string;
|
|
1576
|
+
name: string;
|
|
1577
|
+
primaryKey?: string[];
|
|
1578
|
+
references?: References;
|
|
1579
|
+
check?: Check;
|
|
1580
|
+
}
|
|
1581
|
+
interface References {
|
|
1582
|
+
foreignSchema: string;
|
|
1583
|
+
foreignTable: string;
|
|
1584
|
+
columns: string[];
|
|
1585
|
+
foreignColumns: string[];
|
|
1586
|
+
match: ForeignKeyMatch;
|
|
1587
|
+
onUpdate: ForeignKeyAction;
|
|
1588
|
+
onDelete: ForeignKeyAction;
|
|
1589
|
+
}
|
|
1590
|
+
interface Check {
|
|
1591
|
+
columns?: string[];
|
|
1592
|
+
expression: string;
|
|
1593
|
+
}
|
|
1594
|
+
interface Trigger {
|
|
1595
|
+
schemaName: string;
|
|
1596
|
+
tableName: string;
|
|
1597
|
+
triggerSchema: string;
|
|
1598
|
+
name: string;
|
|
1599
|
+
events: string[];
|
|
1600
|
+
activation: string;
|
|
1601
|
+
condition?: string;
|
|
1602
|
+
definition: string;
|
|
1603
|
+
}
|
|
1604
|
+
interface Extension {
|
|
1605
|
+
schemaName: string;
|
|
1606
|
+
name: string;
|
|
1607
|
+
version?: string;
|
|
1608
|
+
}
|
|
1609
|
+
interface Enum {
|
|
1610
|
+
schemaName: string;
|
|
1611
|
+
name: string;
|
|
1612
|
+
values: [string, ...string[]];
|
|
1613
|
+
}
|
|
1614
|
+
interface Domain {
|
|
1615
|
+
schemaName: string;
|
|
1616
|
+
name: string;
|
|
1617
|
+
type: string;
|
|
1618
|
+
typeSchema: string;
|
|
1619
|
+
isArray: boolean;
|
|
1620
|
+
isNullable: boolean;
|
|
1621
|
+
maxChars?: number;
|
|
1622
|
+
numericPrecision?: number;
|
|
1623
|
+
numericScale?: number;
|
|
1624
|
+
dateTimePrecision?: number;
|
|
1625
|
+
collate?: string;
|
|
1626
|
+
default?: string;
|
|
1627
|
+
check?: string;
|
|
1628
|
+
}
|
|
1629
|
+
interface Collation {
|
|
1630
|
+
schemaName: string;
|
|
1631
|
+
name: string;
|
|
1632
|
+
provider: string;
|
|
1633
|
+
deterministic: boolean;
|
|
1634
|
+
lcCollate?: string;
|
|
1635
|
+
lcCType?: string;
|
|
1636
|
+
locale?: string;
|
|
1637
|
+
version?: string;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
interface IntrospectedStructure {
|
|
1641
|
+
schemas: string[];
|
|
1642
|
+
tables: DbStructure.Table[];
|
|
1643
|
+
views: DbStructure.View[];
|
|
1644
|
+
indexes: DbStructure.Index[];
|
|
1645
|
+
constraints: DbStructure.Constraint[];
|
|
1646
|
+
triggers: DbStructure.Trigger[];
|
|
1647
|
+
extensions: DbStructure.Extension[];
|
|
1648
|
+
enums: DbStructure.Enum[];
|
|
1649
|
+
domains: DbStructure.Domain[];
|
|
1650
|
+
collations: DbStructure.Collation[];
|
|
1651
|
+
}
|
|
1652
|
+
declare function introspectDbSchema(db: Adapter): Promise<IntrospectedStructure>;
|
|
1653
|
+
|
|
1654
|
+
interface DbStructureDomainsMap {
|
|
1655
|
+
[K: string]: ColumnType;
|
|
1656
|
+
}
|
|
1657
|
+
interface StructureToAstCtx {
|
|
1658
|
+
snakeCase?: boolean;
|
|
1659
|
+
unsupportedTypes: Record<string, string[]>;
|
|
1660
|
+
currentSchema: string;
|
|
1661
|
+
columnSchemaConfig: ColumnSchemaConfig;
|
|
1662
|
+
columnsByType: ColumnsByType;
|
|
1663
|
+
}
|
|
1664
|
+
interface StructureToAstTableData {
|
|
1665
|
+
primaryKey?: TableData.PrimaryKey;
|
|
1666
|
+
indexes: DbStructure.Index[];
|
|
1667
|
+
constraints: DbStructure.Constraint[];
|
|
1668
|
+
}
|
|
1669
|
+
declare const makeStructureToAstCtx: (config: AnyRakeDbConfig, currentSchema: string) => StructureToAstCtx;
|
|
1670
|
+
declare const structureToAst: (ctx: StructureToAstCtx, adapter: Adapter) => Promise<RakeDbAst[]>;
|
|
1671
|
+
declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
|
|
1672
|
+
declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => ColumnType<orchid_core.ColumnTypeSchemaArg, unknown, any, pqb.BaseOperators, unknown, unknown, any, unknown, any> | ArrayColumn<ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, ColumnType<orchid_core.ColumnTypeSchemaArg, unknown, any, pqb.BaseOperators, unknown, unknown, any, unknown, any>, unknown, unknown, unknown>;
|
|
1673
|
+
declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: 'create' | 'drop', domains: DbStructureDomainsMap) => RakeDbAst.Table;
|
|
1674
|
+
declare const getDbStructureTableData: (data: IntrospectedStructure, { name, schemaName }: DbStructure.Table) => StructureToAstTableData;
|
|
1675
|
+
declare const makeDbStructureColumnsShape: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, table: DbStructure.Table | DbStructure.View, tableData?: StructureToAstTableData) => ColumnsShape;
|
|
1676
|
+
declare const getDbTableColumnsChecks: (tableData: StructureToAstTableData) => RecordString;
|
|
1677
|
+
declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, tableName: string, item: DbStructure.Column, table?: DbStructure.Table, tableData?: StructureToAstTableData, checks?: RecordString) => [key: string, column: ColumnType];
|
|
1678
|
+
|
|
1679
|
+
declare const astToMigration: (currentSchema: string, config: AnyRakeDbConfig, asts: RakeDbAst[]) => string | undefined;
|
|
1680
|
+
|
|
1681
|
+
declare const versionToString: (config: AnyRakeDbConfig, version: number) => string;
|
|
1682
|
+
declare const columnTypeToSql: (item: ColumnTypeBase) => string;
|
|
1683
|
+
declare const getColumnName: (item: {
|
|
1684
|
+
data: {
|
|
1685
|
+
name?: string;
|
|
1686
|
+
};
|
|
1687
|
+
}, key: string, snakeCase: boolean | undefined) => string;
|
|
1688
|
+
declare const columnToSql: (name: string, item: ColumnType, values: unknown[], hasMultiplePrimaryKeys: boolean, snakeCase: boolean | undefined) => string;
|
|
1689
|
+
declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: ColumnTypeBase) => string | null;
|
|
1690
|
+
declare const identityToSql: (identity: TableData.Identity) => string;
|
|
1691
|
+
declare const addColumnIndex: (indexes: TableData.Index[], name: string, item: ColumnType) => void;
|
|
1692
|
+
declare const addColumnComment: (comments: ColumnComment[], name: string, item: ColumnType) => void;
|
|
1693
|
+
declare const getForeignKeyTable: (fnOrTable: (() => ForeignKeyTable) | string) => [string | undefined, string];
|
|
1694
|
+
declare const getConstraintName: (table: string, constraint: {
|
|
1695
|
+
references?: {
|
|
1696
|
+
columns: string[];
|
|
1697
|
+
};
|
|
1698
|
+
check?: unknown;
|
|
1699
|
+
identity?: unknown;
|
|
1700
|
+
}) => string;
|
|
1701
|
+
declare const constraintToSql: ({ name }: {
|
|
1702
|
+
schema?: string;
|
|
1703
|
+
name: string;
|
|
1704
|
+
}, up: boolean, constraint: TableData.Constraint, values: unknown[], snakeCase: boolean | undefined) => string;
|
|
1705
|
+
declare const referencesToSql: (references: TableData.References, snakeCase: boolean | undefined) => string;
|
|
1706
|
+
declare const getIndexName: (table: string, columns: ({
|
|
1707
|
+
column?: string;
|
|
1708
|
+
} | {
|
|
1709
|
+
expression: string;
|
|
1710
|
+
})[]) => string;
|
|
1711
|
+
declare const indexesToQuery: (up: boolean, { schema, name }: {
|
|
1712
|
+
schema?: string;
|
|
1713
|
+
name: string;
|
|
1714
|
+
}, indexes: TableData.Index[], language?: string) => Sql[];
|
|
1715
|
+
declare const commentsToQuery: (schemaTable: {
|
|
1716
|
+
schema?: string;
|
|
1717
|
+
name: string;
|
|
1718
|
+
}, comments: ColumnComment[]) => Sql[];
|
|
1719
|
+
declare const primaryKeyToSql: (primaryKey: Exclude<TableData['primaryKey'], undefined>) => string;
|
|
1720
|
+
|
|
1393
1721
|
/**
|
|
1394
1722
|
* Type of {@link rakeDb} function
|
|
1395
1723
|
*/
|
|
@@ -1434,5 +1762,44 @@ type RakeDbChangeFn<CT extends RakeDbColumnTypes> = (fn: ChangeCallback<CT>) =>
|
|
|
1434
1762
|
*/
|
|
1435
1763
|
declare const rakeDb: RakeDbFn;
|
|
1436
1764
|
declare const rakeDbAliases: RecordOptionalString;
|
|
1765
|
+
interface RakeDbCommand {
|
|
1766
|
+
run(options: AdapterOptions[], config: AnyRakeDbConfig, args: string[]): MaybePromise<unknown>;
|
|
1767
|
+
help: string;
|
|
1768
|
+
helpArguments?: RecordString;
|
|
1769
|
+
helpAfter?: string;
|
|
1770
|
+
}
|
|
1771
|
+
interface RakeDbCommands {
|
|
1772
|
+
[K: string]: RakeDbCommand;
|
|
1773
|
+
}
|
|
1774
|
+
declare const rakeDbCommands: RakeDbCommands;
|
|
1775
|
+
|
|
1776
|
+
declare const colors: {
|
|
1777
|
+
yellow: (s: string) => string;
|
|
1778
|
+
green: (s: string) => string;
|
|
1779
|
+
red: (s: string) => string;
|
|
1780
|
+
blue: (s: string) => string;
|
|
1781
|
+
bright: (s: string) => string;
|
|
1782
|
+
blueBold: (s: string) => string;
|
|
1783
|
+
yellowBold: (s: string) => string;
|
|
1784
|
+
greenBold: (s: string) => string;
|
|
1785
|
+
pale: (s: string) => string;
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
declare const promptSelect: ({ message, options, active, inactive, }: {
|
|
1789
|
+
message: string;
|
|
1790
|
+
options: string[];
|
|
1791
|
+
active?: (s: string) => string;
|
|
1792
|
+
inactive?: (s: string) => string;
|
|
1793
|
+
}) => Promise<number>;
|
|
1794
|
+
declare const promptConfirm: ({ message, }: {
|
|
1795
|
+
message: string;
|
|
1796
|
+
password?: boolean;
|
|
1797
|
+
}) => Promise<boolean>;
|
|
1798
|
+
declare const promptText: ({ message, default: def, password, min, }: {
|
|
1799
|
+
message: string;
|
|
1800
|
+
default?: string;
|
|
1801
|
+
password?: boolean;
|
|
1802
|
+
min?: number;
|
|
1803
|
+
}) => Promise<string>;
|
|
1437
1804
|
|
|
1438
|
-
export { AnyRakeDbConfig,
|
|
1805
|
+
export { AnyRakeDbConfig, ChangeCallback, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, CommandFn, ConstraintArg, DbMigration, DbStructure, DbStructureDomainsMap, DropMode, InputRakeDbConfig, IntrospectedStructure, Migration, MigrationAdapter, MigrationColumnTypes, ModuleExportsRecord, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAppliedVersions, RakeDbAst, RakeDbBaseTable, RakeDbChangeFn, RakeDbColumnTypes, RakeDbConfig, RakeDbCtx, RakeDbFn, RakeDbFnReturns, RakeDbLazyFn, RakeDbMigrationId, RakeDbResult, SilentQueries, StructureToAstCtx, StructureToAstTableData, TableOptions, addColumnComment, addColumnIndex, addOrDropEnumValues, astToMigration, changeCache, changeEnumValues, clearChanges, colors, columnToSql, columnTypeToSql, commentsToQuery, concatSchemaAndName, constraintToSql, createDb, createMigrationInterface, dbColumnToAst, deleteMigratedVersion, dropDb, encodeColumnDefault, exhaustive, generateTimeStamp, getColumnName, getConstraintName, getCurrentChanges, getDatabaseAndUserFromOptions, getDbStructureTableData, getDbTableColumnsChecks, getFirstWordAndRest, getForeignKeyTable, getIndexName, getMigratedVersionsMap, getSchemaAndTableFromName, getTextAfterFrom, getTextAfterTo, identityToSql, indexesToQuery, instantiateDbColumn, introspectDbSchema, joinColumns, joinWords, makeDbStructureColumnsShape, makeDomainsMap, makeFileVersion, makePopulateEnumQuery, makeStructureToAstCtx, migrate, migrateOrRollback, migrationConfigDefaults, newMigration, pluralize, primaryKeyToSql, processRakeDbConfig, promptConfirm, promptSelect, promptText, pushChange, queryLock, quoteNameFromString, quoteSchemaTable, quoteTable, quoteWithSchema, rakeDb, rakeDbAliases, rakeDbCommands, redo, referencesToSql, renameType, resetDb, rollback, saveMigratedVersion, structureToAst, tableToAst, transaction, versionToString, writeMigrationFile };
|