rake-db 2.12.7 → 2.13.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 +52 -50
- package/dist/index.js +6 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter, DbResult, TransactionAdapter, QueryLogObject, IndexColumnOptions, IndexOptions, ForeignKeyOptions, TextColumn,
|
|
2
|
+
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter, DbResult, TransactionAdapter, QueryLogObject, IndexColumnOptions, IndexOptions, ForeignKeyOptions, TextColumn, TableData, NoPrimaryKeyOption, SingleColumnIndexOptions, DefaultColumnTypes, QueryLogOptions, AdapterOptions } from 'pqb';
|
|
3
3
|
import { EmptyObject, RawSQLBase, ColumnSchemaConfig, MaybeArray, ColumnTypeBase } from 'orchid-core';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
6
6
|
table: Db$1<Table, Shape>;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
declare function add(item: ColumnType, options?: {
|
|
10
10
|
dropMode?: DropMode;
|
|
@@ -786,7 +786,7 @@ declare class Migration<CT extends RakeDbColumnTypes> {
|
|
|
786
786
|
|
|
787
787
|
type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameTable | RakeDbAst.Schema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.View;
|
|
788
788
|
declare namespace RakeDbAst {
|
|
789
|
-
|
|
789
|
+
interface Table extends TableData {
|
|
790
790
|
type: 'table';
|
|
791
791
|
action: 'create' | 'drop';
|
|
792
792
|
schema?: string;
|
|
@@ -797,8 +797,8 @@ declare namespace RakeDbAst {
|
|
|
797
797
|
dropIfExists?: boolean;
|
|
798
798
|
dropMode?: DropMode;
|
|
799
799
|
comment?: string;
|
|
800
|
-
}
|
|
801
|
-
|
|
800
|
+
}
|
|
801
|
+
interface ChangeTable {
|
|
802
802
|
type: 'changeTable';
|
|
803
803
|
schema?: string;
|
|
804
804
|
name: string;
|
|
@@ -806,27 +806,27 @@ declare namespace RakeDbAst {
|
|
|
806
806
|
shape: Record<string, ChangeTableItem>;
|
|
807
807
|
add: TableData;
|
|
808
808
|
drop: TableData;
|
|
809
|
-
}
|
|
809
|
+
}
|
|
810
810
|
type ChangeTableItem = ChangeTableItem.Column | ChangeTableItem.Change | ChangeTableItem.Rename;
|
|
811
811
|
namespace ChangeTableItem {
|
|
812
|
-
|
|
812
|
+
interface Column {
|
|
813
813
|
type: 'add' | 'drop';
|
|
814
814
|
item: ColumnType;
|
|
815
815
|
dropMode?: DropMode;
|
|
816
|
-
}
|
|
817
|
-
|
|
816
|
+
}
|
|
817
|
+
interface Change {
|
|
818
818
|
type: 'change';
|
|
819
819
|
name?: string;
|
|
820
820
|
from: ColumnChange;
|
|
821
821
|
to: ColumnChange;
|
|
822
822
|
using?: RawSQLBase;
|
|
823
|
-
}
|
|
824
|
-
|
|
823
|
+
}
|
|
824
|
+
interface Rename {
|
|
825
825
|
type: 'rename';
|
|
826
826
|
name: string;
|
|
827
|
-
}
|
|
827
|
+
}
|
|
828
828
|
}
|
|
829
|
-
|
|
829
|
+
interface ColumnChange {
|
|
830
830
|
column?: ColumnType;
|
|
831
831
|
type?: string;
|
|
832
832
|
collate?: string;
|
|
@@ -842,20 +842,20 @@ declare namespace RakeDbAst {
|
|
|
842
842
|
} & ForeignKeyOptions)[];
|
|
843
843
|
indexes?: Omit<SingleColumnIndexOptions, 'column' | 'expression'>[];
|
|
844
844
|
identity?: TableData.Identity;
|
|
845
|
-
}
|
|
846
|
-
|
|
845
|
+
}
|
|
846
|
+
interface RenameTable {
|
|
847
847
|
type: 'renameTable';
|
|
848
848
|
fromSchema?: string;
|
|
849
849
|
from: string;
|
|
850
850
|
toSchema?: string;
|
|
851
851
|
to: string;
|
|
852
|
-
}
|
|
853
|
-
|
|
852
|
+
}
|
|
853
|
+
interface Schema {
|
|
854
854
|
type: 'schema';
|
|
855
855
|
action: 'create' | 'drop';
|
|
856
856
|
name: string;
|
|
857
|
-
}
|
|
858
|
-
|
|
857
|
+
}
|
|
858
|
+
interface Extension {
|
|
859
859
|
type: 'extension';
|
|
860
860
|
action: 'create' | 'drop';
|
|
861
861
|
name: string;
|
|
@@ -864,8 +864,8 @@ declare namespace RakeDbAst {
|
|
|
864
864
|
cascade?: boolean;
|
|
865
865
|
createIfNotExists?: boolean;
|
|
866
866
|
dropIfExists?: boolean;
|
|
867
|
-
}
|
|
868
|
-
|
|
867
|
+
}
|
|
868
|
+
interface Enum {
|
|
869
869
|
type: 'enum';
|
|
870
870
|
action: 'create' | 'drop';
|
|
871
871
|
schema?: string;
|
|
@@ -873,8 +873,8 @@ declare namespace RakeDbAst {
|
|
|
873
873
|
values: [string, ...string[]];
|
|
874
874
|
cascade?: boolean;
|
|
875
875
|
dropIfExists?: boolean;
|
|
876
|
-
}
|
|
877
|
-
|
|
876
|
+
}
|
|
877
|
+
interface Domain {
|
|
878
878
|
type: 'domain';
|
|
879
879
|
action: 'create' | 'drop';
|
|
880
880
|
schema?: string;
|
|
@@ -885,8 +885,8 @@ declare namespace RakeDbAst {
|
|
|
885
885
|
default?: RawSQLBase;
|
|
886
886
|
check?: RawSQLBase;
|
|
887
887
|
cascade?: boolean;
|
|
888
|
-
}
|
|
889
|
-
|
|
888
|
+
}
|
|
889
|
+
interface Collation {
|
|
890
890
|
type: 'collation';
|
|
891
891
|
action: 'create' | 'drop';
|
|
892
892
|
schema?: string;
|
|
@@ -901,18 +901,18 @@ declare namespace RakeDbAst {
|
|
|
901
901
|
createIfNotExists?: boolean;
|
|
902
902
|
dropIfExists?: boolean;
|
|
903
903
|
cascade?: boolean;
|
|
904
|
-
}
|
|
905
|
-
|
|
904
|
+
}
|
|
905
|
+
interface EnumOptions {
|
|
906
906
|
createIfNotExists?: boolean;
|
|
907
907
|
dropIfExists?: boolean;
|
|
908
|
-
}
|
|
909
|
-
|
|
908
|
+
}
|
|
909
|
+
interface Constraint extends TableData.Constraint {
|
|
910
910
|
type: 'constraint';
|
|
911
911
|
action: 'create';
|
|
912
912
|
tableSchema?: string;
|
|
913
913
|
tableName: string;
|
|
914
|
-
}
|
|
915
|
-
|
|
914
|
+
}
|
|
915
|
+
interface View {
|
|
916
916
|
type: 'view';
|
|
917
917
|
action: 'create' | 'drop';
|
|
918
918
|
schema?: string;
|
|
@@ -920,8 +920,8 @@ declare namespace RakeDbAst {
|
|
|
920
920
|
shape: ColumnsShape;
|
|
921
921
|
sql: RawSQLBase;
|
|
922
922
|
options: ViewOptions;
|
|
923
|
-
}
|
|
924
|
-
|
|
923
|
+
}
|
|
924
|
+
interface ViewOptions {
|
|
925
925
|
createOrReplace?: boolean;
|
|
926
926
|
dropIfExists?: boolean;
|
|
927
927
|
dropMode?: DropMode;
|
|
@@ -933,10 +933,10 @@ declare namespace RakeDbAst {
|
|
|
933
933
|
securityBarrier?: boolean;
|
|
934
934
|
securityInvoker?: boolean;
|
|
935
935
|
};
|
|
936
|
-
}
|
|
936
|
+
}
|
|
937
937
|
}
|
|
938
938
|
|
|
939
|
-
|
|
939
|
+
interface RakeDbColumnTypes {
|
|
940
940
|
index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): EmptyObject;
|
|
941
941
|
foreignKey(columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: ForeignKeyOptions): EmptyObject;
|
|
942
942
|
primaryKey(columns: string[], options?: {
|
|
@@ -944,8 +944,8 @@ type RakeDbColumnTypes = {
|
|
|
944
944
|
}): EmptyObject;
|
|
945
945
|
check(check: RawSQLBase): EmptyObject;
|
|
946
946
|
constraint(arg: ConstraintArg): EmptyObject;
|
|
947
|
-
}
|
|
948
|
-
|
|
947
|
+
}
|
|
948
|
+
interface ConstraintArg {
|
|
949
949
|
name?: string;
|
|
950
950
|
references?: [
|
|
951
951
|
columns: [string, ...string[]],
|
|
@@ -955,9 +955,9 @@ type ConstraintArg = {
|
|
|
955
955
|
];
|
|
956
956
|
check?: RawSQLBase;
|
|
957
957
|
dropMode?: DropMode;
|
|
958
|
-
}
|
|
958
|
+
}
|
|
959
959
|
type Db = DbResult<RakeDbColumnTypes>;
|
|
960
|
-
|
|
960
|
+
interface BaseTable<CT> {
|
|
961
961
|
exportAs: string;
|
|
962
962
|
getFilePath(): string;
|
|
963
963
|
nowSQL?: string;
|
|
@@ -966,13 +966,13 @@ type BaseTable<CT> = {
|
|
|
966
966
|
snakeCase?: boolean;
|
|
967
967
|
language?: string;
|
|
968
968
|
};
|
|
969
|
-
}
|
|
969
|
+
}
|
|
970
970
|
type InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> = Partial<Omit<RakeDbConfig<SchemaConfig, CT>, 'columnTypes'>> & ({
|
|
971
971
|
columnTypes?: CT | ((t: DefaultColumnTypes<ColumnSchemaConfig>) => CT);
|
|
972
972
|
} | {
|
|
973
973
|
baseTable?: BaseTable<CT>;
|
|
974
974
|
});
|
|
975
|
-
|
|
975
|
+
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<ColumnSchemaConfig>> extends QueryLogOptions {
|
|
976
976
|
schemaConfig: SchemaConfig;
|
|
977
977
|
columnTypes: CT;
|
|
978
978
|
basePath: string;
|
|
@@ -994,9 +994,11 @@ type RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTyp
|
|
|
994
994
|
afterMigrate?(db: Db): Promise<void>;
|
|
995
995
|
beforeRollback?(db: Db): Promise<void>;
|
|
996
996
|
afterRollback?(db: Db): Promise<void>;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
|
|
997
|
+
}
|
|
998
|
+
interface ModuleExportsRecord {
|
|
999
|
+
[K: string]: () => Promise<unknown>;
|
|
1000
|
+
}
|
|
1001
|
+
interface AppCodeUpdaterParams {
|
|
1000
1002
|
options: AdapterOptions;
|
|
1001
1003
|
basePath: string;
|
|
1002
1004
|
cache: object;
|
|
@@ -1006,14 +1008,14 @@ type AppCodeUpdaterParams = {
|
|
|
1006
1008
|
exportAs: string;
|
|
1007
1009
|
};
|
|
1008
1010
|
import(path: string): Promise<unknown>;
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
+
}
|
|
1012
|
+
interface AppCodeUpdater {
|
|
1011
1013
|
process(params: AppCodeUpdaterParams & {
|
|
1012
1014
|
ast: RakeDbAst;
|
|
1013
1015
|
}): Promise<void>;
|
|
1014
1016
|
afterAll(params: AppCodeUpdaterParams): Promise<void>;
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
+
}
|
|
1018
|
+
interface MigrationItem {
|
|
1017
1019
|
path: string;
|
|
1018
1020
|
version: string;
|
|
1019
1021
|
/**
|
|
@@ -1022,7 +1024,7 @@ type MigrationItem = {
|
|
|
1022
1024
|
* Promise can return `{ default: x }` where `x` is a return of `change` or an array of such returns.
|
|
1023
1025
|
*/
|
|
1024
1026
|
load(): Promise<unknown>;
|
|
1025
|
-
}
|
|
1027
|
+
}
|
|
1026
1028
|
|
|
1027
1029
|
declare const createDb: <SchemaConfig extends ColumnSchemaConfig, CT>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1028
1030
|
declare const dropDb: <SchemaConfig extends ColumnSchemaConfig, CT>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -3249,15 +3249,12 @@ const pushTableAst = (ctx, ast, data, domains, table, pendingTables, innerConstr
|
|
|
3249
3249
|
},
|
|
3250
3250
|
[]
|
|
3251
3251
|
);
|
|
3252
|
-
const columnChecks = innerConstraints.reduce(
|
|
3253
|
-
(
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
},
|
|
3259
|
-
{}
|
|
3260
|
-
);
|
|
3252
|
+
const columnChecks = innerConstraints.reduce((acc, item) => {
|
|
3253
|
+
if (belongsToTable(item) && isColumnCheck(item)) {
|
|
3254
|
+
acc[item.check.columns[0]] = item.check.expression;
|
|
3255
|
+
}
|
|
3256
|
+
return acc;
|
|
3257
|
+
}, {});
|
|
3261
3258
|
const shape = makeColumnsShape(
|
|
3262
3259
|
ctx,
|
|
3263
3260
|
data,
|