rake-db 2.30.0 → 2.30.1
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 +204 -167
- package/dist/index.js +265 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,190 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { TableData, ColumnsShape, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EnumColumn, EmptyObject,
|
|
2
|
+
import { SearchWeight, RecordOptionalString, AdapterBase, TableData, ColumnsShape, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EnumColumn, EmptyObject, DbResult, DefaultColumnTypes, DefaultSchemaConfig, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, ColumnSchemaConfig, raw, Db, QuerySchema, MaybePromise, QueryLogOptions, QueryLogger, ColumnsByType, DbStructureDomainsMap } from 'pqb';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
declare namespace DbStructure {
|
|
5
|
+
interface TableNameAndSchemaName {
|
|
6
|
+
schemaName: string;
|
|
7
|
+
tableName: string;
|
|
8
|
+
}
|
|
9
|
+
interface Table {
|
|
10
|
+
schemaName: string;
|
|
11
|
+
name: string;
|
|
12
|
+
comment?: string;
|
|
13
|
+
columns: Column[];
|
|
14
|
+
}
|
|
15
|
+
interface View {
|
|
16
|
+
schemaName: string;
|
|
17
|
+
name: string;
|
|
18
|
+
deps: RakeDbAst.View['deps'];
|
|
19
|
+
isRecursive: boolean;
|
|
20
|
+
with?: string[];
|
|
21
|
+
columns: Column[];
|
|
22
|
+
sql: string;
|
|
23
|
+
}
|
|
24
|
+
interface Procedure {
|
|
25
|
+
schemaName: string;
|
|
26
|
+
name: string;
|
|
27
|
+
returnSet: boolean;
|
|
28
|
+
returnType: string;
|
|
29
|
+
kind: string;
|
|
30
|
+
isTrigger: boolean;
|
|
31
|
+
types: string[];
|
|
32
|
+
argTypes: string[];
|
|
33
|
+
argModes: ('i' | 'o')[];
|
|
34
|
+
argNames?: string[];
|
|
35
|
+
}
|
|
36
|
+
interface Column extends TableNameAndSchemaName {
|
|
37
|
+
name: string;
|
|
38
|
+
typeSchema: string;
|
|
39
|
+
type: string;
|
|
40
|
+
arrayDims: number;
|
|
41
|
+
maxChars?: number;
|
|
42
|
+
numericPrecision?: number;
|
|
43
|
+
numericScale?: number;
|
|
44
|
+
dateTimePrecision?: number;
|
|
45
|
+
default?: string;
|
|
46
|
+
isNullable: boolean;
|
|
47
|
+
collate?: string;
|
|
48
|
+
compression?: 'pglz' | 'lz4';
|
|
49
|
+
comment?: string;
|
|
50
|
+
identity?: {
|
|
51
|
+
always: boolean;
|
|
52
|
+
start: number;
|
|
53
|
+
increment: number;
|
|
54
|
+
min?: number;
|
|
55
|
+
max?: number;
|
|
56
|
+
cache: number;
|
|
57
|
+
cycle: boolean;
|
|
58
|
+
};
|
|
59
|
+
extension?: string;
|
|
60
|
+
typmod: number;
|
|
61
|
+
}
|
|
62
|
+
interface Index extends TableNameAndSchemaName {
|
|
63
|
+
name: string;
|
|
64
|
+
using: string;
|
|
65
|
+
unique: boolean;
|
|
66
|
+
columns: (({
|
|
67
|
+
column: string;
|
|
68
|
+
} | {
|
|
69
|
+
expression: string;
|
|
70
|
+
}) & {
|
|
71
|
+
collate?: string;
|
|
72
|
+
opclass?: string;
|
|
73
|
+
order?: string;
|
|
74
|
+
weight?: SearchWeight;
|
|
75
|
+
})[];
|
|
76
|
+
include?: string[];
|
|
77
|
+
nullsNotDistinct?: boolean;
|
|
78
|
+
with?: string;
|
|
79
|
+
tablespace?: string;
|
|
80
|
+
where?: string;
|
|
81
|
+
tsVector?: boolean;
|
|
82
|
+
language?: string;
|
|
83
|
+
languageColumn?: string;
|
|
84
|
+
}
|
|
85
|
+
interface Exclude extends Index {
|
|
86
|
+
exclude: string[];
|
|
87
|
+
}
|
|
88
|
+
type ForeignKeyMatch = 'f' | 'p' | 's';
|
|
89
|
+
type ForeignKeyAction = 'a' | 'r' | 'c' | 'n' | 'd';
|
|
90
|
+
interface Constraint extends TableNameAndSchemaName {
|
|
91
|
+
name: string;
|
|
92
|
+
primaryKey?: string[];
|
|
93
|
+
references?: References;
|
|
94
|
+
check?: Check;
|
|
95
|
+
}
|
|
96
|
+
interface References {
|
|
97
|
+
foreignSchema: string;
|
|
98
|
+
foreignTable: string;
|
|
99
|
+
columns: string[];
|
|
100
|
+
foreignColumns: string[];
|
|
101
|
+
match: ForeignKeyMatch;
|
|
102
|
+
onUpdate: ForeignKeyAction;
|
|
103
|
+
onDelete: ForeignKeyAction;
|
|
104
|
+
}
|
|
105
|
+
interface Check {
|
|
106
|
+
columns?: string[];
|
|
107
|
+
expression: string;
|
|
108
|
+
}
|
|
109
|
+
interface Trigger extends TableNameAndSchemaName {
|
|
110
|
+
triggerSchema: string;
|
|
111
|
+
name: string;
|
|
112
|
+
events: string[];
|
|
113
|
+
activation: string;
|
|
114
|
+
condition?: string;
|
|
115
|
+
definition: string;
|
|
116
|
+
}
|
|
117
|
+
interface Extension {
|
|
118
|
+
schemaName: string;
|
|
119
|
+
name: string;
|
|
120
|
+
version?: string;
|
|
121
|
+
}
|
|
122
|
+
interface Enum {
|
|
123
|
+
schemaName: string;
|
|
124
|
+
name: string;
|
|
125
|
+
values: [string, ...string[]];
|
|
126
|
+
}
|
|
127
|
+
interface Domain {
|
|
128
|
+
schemaName: string;
|
|
129
|
+
name: string;
|
|
130
|
+
type: string;
|
|
131
|
+
typeSchema: string;
|
|
132
|
+
arrayDims: number;
|
|
133
|
+
isNullable: boolean;
|
|
134
|
+
maxChars?: number;
|
|
135
|
+
numericPrecision?: number;
|
|
136
|
+
numericScale?: number;
|
|
137
|
+
dateTimePrecision?: number;
|
|
138
|
+
collate?: string;
|
|
139
|
+
default?: string;
|
|
140
|
+
checks?: string[];
|
|
141
|
+
}
|
|
142
|
+
interface Collation {
|
|
143
|
+
schemaName: string;
|
|
144
|
+
name: string;
|
|
145
|
+
provider: string;
|
|
146
|
+
deterministic: boolean;
|
|
147
|
+
lcCollate?: string;
|
|
148
|
+
lcCType?: string;
|
|
149
|
+
locale?: string;
|
|
150
|
+
version?: string;
|
|
151
|
+
}
|
|
152
|
+
interface Role {
|
|
153
|
+
name: string;
|
|
154
|
+
super: boolean;
|
|
155
|
+
inherit: boolean;
|
|
156
|
+
createRole: boolean;
|
|
157
|
+
createDb: boolean;
|
|
158
|
+
canLogin: boolean;
|
|
159
|
+
replication: boolean;
|
|
160
|
+
connLimit: number;
|
|
161
|
+
validUntil?: Date;
|
|
162
|
+
bypassRls: boolean;
|
|
163
|
+
config?: RecordOptionalString;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
interface IntrospectedStructure {
|
|
167
|
+
schemas: string[];
|
|
168
|
+
tables: DbStructure.Table[];
|
|
169
|
+
views: DbStructure.View[];
|
|
170
|
+
indexes: DbStructure.Index[];
|
|
171
|
+
excludes: DbStructure.Exclude[];
|
|
172
|
+
constraints: DbStructure.Constraint[];
|
|
173
|
+
triggers: DbStructure.Trigger[];
|
|
174
|
+
extensions: DbStructure.Extension[];
|
|
175
|
+
enums: DbStructure.Enum[];
|
|
176
|
+
domains: DbStructure.Domain[];
|
|
177
|
+
collations: DbStructure.Collation[];
|
|
178
|
+
roles?: DbStructure.Role[];
|
|
179
|
+
}
|
|
180
|
+
interface IntrospectDbStructureParams {
|
|
181
|
+
roles?: {
|
|
182
|
+
whereSql?: string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
declare function introspectDbSchema(db: AdapterBase, params?: IntrospectDbStructureParams): Promise<IntrospectedStructure>;
|
|
186
|
+
|
|
187
|
+
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 | RakeDbAst.Role | RakeDbAst.ChangeRole;
|
|
5
188
|
declare namespace RakeDbAst {
|
|
6
189
|
interface Table extends TableData {
|
|
7
190
|
type: 'table';
|
|
@@ -192,6 +375,16 @@ declare namespace RakeDbAst {
|
|
|
192
375
|
securityInvoker?: boolean;
|
|
193
376
|
};
|
|
194
377
|
}
|
|
378
|
+
interface Role extends DbStructure.Role {
|
|
379
|
+
type: 'role';
|
|
380
|
+
action: 'create' | 'drop';
|
|
381
|
+
}
|
|
382
|
+
interface ChangeRole {
|
|
383
|
+
type: 'changeRole';
|
|
384
|
+
name: string;
|
|
385
|
+
from: Partial<DbStructure.Role>;
|
|
386
|
+
to: Partial<DbStructure.Role>;
|
|
387
|
+
}
|
|
195
388
|
}
|
|
196
389
|
|
|
197
390
|
declare function add(item: Column, options?: {
|
|
@@ -1210,6 +1403,12 @@ declare class Migration<CT = unknown> {
|
|
|
1210
1403
|
* @param constraintName - name of the constraint
|
|
1211
1404
|
*/
|
|
1212
1405
|
constraintExists(constraintName: string): Promise<boolean>;
|
|
1406
|
+
createRole(name: string, params: Partial<DbStructure.Role>): Promise<void>;
|
|
1407
|
+
dropRole(name: string, params?: Partial<DbStructure.Role>): Promise<void>;
|
|
1408
|
+
changeRole(name: string, params: {
|
|
1409
|
+
from?: Partial<DbStructure.Role>;
|
|
1410
|
+
to: Partial<DbStructure.Role>;
|
|
1411
|
+
}): Promise<void>;
|
|
1213
1412
|
}
|
|
1214
1413
|
interface AddEnumValueOptions {
|
|
1215
1414
|
ifNotExists?: boolean;
|
|
@@ -1542,7 +1741,8 @@ interface MigrateFn {
|
|
|
1542
1741
|
*/
|
|
1543
1742
|
declare const migrate: MigrateFn;
|
|
1544
1743
|
declare const migrateAndClose: MigrateFn;
|
|
1545
|
-
declare
|
|
1744
|
+
declare function runMigration(db: DbParam, migration: () => MaybePromise<unknown>): Promise<void>;
|
|
1745
|
+
declare function runMigration(db: DbParam, config: Pick<RakeDbConfig, 'transactionSearchPath'>, migration: () => MaybePromise<unknown>): Promise<void>;
|
|
1546
1746
|
/**
|
|
1547
1747
|
* Will roll back one latest applied migration,
|
|
1548
1748
|
* will apply `change` functions bottom-to-top.
|
|
@@ -1557,170 +1757,6 @@ declare const rollback: MigrateFn;
|
|
|
1557
1757
|
*/
|
|
1558
1758
|
declare const redo: MigrateFn;
|
|
1559
1759
|
|
|
1560
|
-
declare namespace DbStructure {
|
|
1561
|
-
interface TableNameAndSchemaName {
|
|
1562
|
-
schemaName: string;
|
|
1563
|
-
tableName: string;
|
|
1564
|
-
}
|
|
1565
|
-
interface Table {
|
|
1566
|
-
schemaName: string;
|
|
1567
|
-
name: string;
|
|
1568
|
-
comment?: string;
|
|
1569
|
-
columns: Column[];
|
|
1570
|
-
}
|
|
1571
|
-
interface View {
|
|
1572
|
-
schemaName: string;
|
|
1573
|
-
name: string;
|
|
1574
|
-
deps: RakeDbAst.View['deps'];
|
|
1575
|
-
isRecursive: boolean;
|
|
1576
|
-
with?: string[];
|
|
1577
|
-
columns: Column[];
|
|
1578
|
-
sql: string;
|
|
1579
|
-
}
|
|
1580
|
-
interface Procedure {
|
|
1581
|
-
schemaName: string;
|
|
1582
|
-
name: string;
|
|
1583
|
-
returnSet: boolean;
|
|
1584
|
-
returnType: string;
|
|
1585
|
-
kind: string;
|
|
1586
|
-
isTrigger: boolean;
|
|
1587
|
-
types: string[];
|
|
1588
|
-
argTypes: string[];
|
|
1589
|
-
argModes: ('i' | 'o')[];
|
|
1590
|
-
argNames?: string[];
|
|
1591
|
-
}
|
|
1592
|
-
interface Column extends TableNameAndSchemaName {
|
|
1593
|
-
name: string;
|
|
1594
|
-
typeSchema: string;
|
|
1595
|
-
type: string;
|
|
1596
|
-
arrayDims: number;
|
|
1597
|
-
maxChars?: number;
|
|
1598
|
-
numericPrecision?: number;
|
|
1599
|
-
numericScale?: number;
|
|
1600
|
-
dateTimePrecision?: number;
|
|
1601
|
-
default?: string;
|
|
1602
|
-
isNullable: boolean;
|
|
1603
|
-
collate?: string;
|
|
1604
|
-
compression?: 'pglz' | 'lz4';
|
|
1605
|
-
comment?: string;
|
|
1606
|
-
identity?: {
|
|
1607
|
-
always: boolean;
|
|
1608
|
-
start: number;
|
|
1609
|
-
increment: number;
|
|
1610
|
-
min?: number;
|
|
1611
|
-
max?: number;
|
|
1612
|
-
cache: number;
|
|
1613
|
-
cycle: boolean;
|
|
1614
|
-
};
|
|
1615
|
-
extension?: string;
|
|
1616
|
-
typmod: number;
|
|
1617
|
-
}
|
|
1618
|
-
interface Index extends TableNameAndSchemaName {
|
|
1619
|
-
name: string;
|
|
1620
|
-
using: string;
|
|
1621
|
-
unique: boolean;
|
|
1622
|
-
columns: (({
|
|
1623
|
-
column: string;
|
|
1624
|
-
} | {
|
|
1625
|
-
expression: string;
|
|
1626
|
-
}) & {
|
|
1627
|
-
collate?: string;
|
|
1628
|
-
opclass?: string;
|
|
1629
|
-
order?: string;
|
|
1630
|
-
weight?: SearchWeight;
|
|
1631
|
-
})[];
|
|
1632
|
-
include?: string[];
|
|
1633
|
-
nullsNotDistinct?: boolean;
|
|
1634
|
-
with?: string;
|
|
1635
|
-
tablespace?: string;
|
|
1636
|
-
where?: string;
|
|
1637
|
-
tsVector?: boolean;
|
|
1638
|
-
language?: string;
|
|
1639
|
-
languageColumn?: string;
|
|
1640
|
-
}
|
|
1641
|
-
interface Exclude extends Index {
|
|
1642
|
-
exclude: string[];
|
|
1643
|
-
}
|
|
1644
|
-
type ForeignKeyMatch = 'f' | 'p' | 's';
|
|
1645
|
-
type ForeignKeyAction = 'a' | 'r' | 'c' | 'n' | 'd';
|
|
1646
|
-
interface Constraint extends TableNameAndSchemaName {
|
|
1647
|
-
name: string;
|
|
1648
|
-
primaryKey?: string[];
|
|
1649
|
-
references?: References;
|
|
1650
|
-
check?: Check;
|
|
1651
|
-
}
|
|
1652
|
-
interface References {
|
|
1653
|
-
foreignSchema: string;
|
|
1654
|
-
foreignTable: string;
|
|
1655
|
-
columns: string[];
|
|
1656
|
-
foreignColumns: string[];
|
|
1657
|
-
match: ForeignKeyMatch;
|
|
1658
|
-
onUpdate: ForeignKeyAction;
|
|
1659
|
-
onDelete: ForeignKeyAction;
|
|
1660
|
-
}
|
|
1661
|
-
interface Check {
|
|
1662
|
-
columns?: string[];
|
|
1663
|
-
expression: string;
|
|
1664
|
-
}
|
|
1665
|
-
interface Trigger extends TableNameAndSchemaName {
|
|
1666
|
-
triggerSchema: string;
|
|
1667
|
-
name: string;
|
|
1668
|
-
events: string[];
|
|
1669
|
-
activation: string;
|
|
1670
|
-
condition?: string;
|
|
1671
|
-
definition: string;
|
|
1672
|
-
}
|
|
1673
|
-
interface Extension {
|
|
1674
|
-
schemaName: string;
|
|
1675
|
-
name: string;
|
|
1676
|
-
version?: string;
|
|
1677
|
-
}
|
|
1678
|
-
interface Enum {
|
|
1679
|
-
schemaName: string;
|
|
1680
|
-
name: string;
|
|
1681
|
-
values: [string, ...string[]];
|
|
1682
|
-
}
|
|
1683
|
-
interface Domain {
|
|
1684
|
-
schemaName: string;
|
|
1685
|
-
name: string;
|
|
1686
|
-
type: string;
|
|
1687
|
-
typeSchema: string;
|
|
1688
|
-
arrayDims: number;
|
|
1689
|
-
isNullable: boolean;
|
|
1690
|
-
maxChars?: number;
|
|
1691
|
-
numericPrecision?: number;
|
|
1692
|
-
numericScale?: number;
|
|
1693
|
-
dateTimePrecision?: number;
|
|
1694
|
-
collate?: string;
|
|
1695
|
-
default?: string;
|
|
1696
|
-
checks?: string[];
|
|
1697
|
-
}
|
|
1698
|
-
interface Collation {
|
|
1699
|
-
schemaName: string;
|
|
1700
|
-
name: string;
|
|
1701
|
-
provider: string;
|
|
1702
|
-
deterministic: boolean;
|
|
1703
|
-
lcCollate?: string;
|
|
1704
|
-
lcCType?: string;
|
|
1705
|
-
locale?: string;
|
|
1706
|
-
version?: string;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
interface IntrospectedStructure {
|
|
1710
|
-
schemas: string[];
|
|
1711
|
-
tables: DbStructure.Table[];
|
|
1712
|
-
views: DbStructure.View[];
|
|
1713
|
-
indexes: DbStructure.Index[];
|
|
1714
|
-
excludes: DbStructure.Exclude[];
|
|
1715
|
-
constraints: DbStructure.Constraint[];
|
|
1716
|
-
triggers: DbStructure.Trigger[];
|
|
1717
|
-
extensions: DbStructure.Extension[];
|
|
1718
|
-
enums: DbStructure.Enum[];
|
|
1719
|
-
domains: DbStructure.Domain[];
|
|
1720
|
-
collations: DbStructure.Collation[];
|
|
1721
|
-
}
|
|
1722
|
-
declare function introspectDbSchema(db: AdapterBase): Promise<IntrospectedStructure>;
|
|
1723
|
-
|
|
1724
1760
|
declare const astToMigration: (currentSchema: string, config: RakeDbConfig, asts: RakeDbAst[]) => string | undefined;
|
|
1725
1761
|
|
|
1726
1762
|
interface StructureToAstCtx {
|
|
@@ -1735,6 +1771,7 @@ interface StructureToAstTableData {
|
|
|
1735
1771
|
indexes: DbStructure.Index[];
|
|
1736
1772
|
excludes: DbStructure.Exclude[];
|
|
1737
1773
|
constraints: DbStructure.Constraint[];
|
|
1774
|
+
roles?: DbStructure.Role[];
|
|
1738
1775
|
}
|
|
1739
1776
|
declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, 'snakeCase' | 'schemaConfig'>, currentSchema: string) => StructureToAstCtx;
|
|
1740
1777
|
declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: Pick<RakeDbConfig, 'migrationsTable'>) => Promise<RakeDbAst[]>;
|