rake-db 2.22.7 → 2.22.9
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 +2 -2
- package/dist/index.js +63 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1551,7 +1551,7 @@ declare namespace DbStructure {
|
|
|
1551
1551
|
name: string;
|
|
1552
1552
|
typeSchema: string;
|
|
1553
1553
|
type: string;
|
|
1554
|
-
|
|
1554
|
+
arrayDims: number;
|
|
1555
1555
|
maxChars?: number;
|
|
1556
1556
|
numericPrecision?: number;
|
|
1557
1557
|
numericScale?: number;
|
|
@@ -1644,7 +1644,7 @@ declare namespace DbStructure {
|
|
|
1644
1644
|
name: string;
|
|
1645
1645
|
type: string;
|
|
1646
1646
|
typeSchema: string;
|
|
1647
|
-
|
|
1647
|
+
arrayDims: number;
|
|
1648
1648
|
isNullable: boolean;
|
|
1649
1649
|
maxChars?: number;
|
|
1650
1650
|
numericPrecision?: number;
|
package/dist/index.js
CHANGED
|
@@ -1212,7 +1212,7 @@ const handleTableItemChange = (key, item, ast, alterTable, renameItems, values,
|
|
|
1212
1212
|
for (let i = 0; i < indexesLen; i++) {
|
|
1213
1213
|
const fromIndex = (_v = from.indexes) == null ? void 0 : _v[i];
|
|
1214
1214
|
const toIndex = (_w = to.indexes) == null ? void 0 : _w[i];
|
|
1215
|
-
if ((fromIndex || toIndex) && (!fromIndex || !toIndex ||
|
|
1215
|
+
if ((fromIndex || toIndex) && (!fromIndex || !toIndex || !orchidCore.deepCompare(fromIndex, toIndex))) {
|
|
1216
1216
|
if (fromIndex) {
|
|
1217
1217
|
dropIndexes.push(__spreadProps$5(__spreadValues$7({}, fromIndex), {
|
|
1218
1218
|
columns: [
|
|
@@ -3663,25 +3663,13 @@ const columnsSql = ({
|
|
|
3663
3663
|
${schema}.nspname AS "schemaName",
|
|
3664
3664
|
${table}.relname AS "tableName",
|
|
3665
3665
|
a.attname AS "name",
|
|
3666
|
-
|
|
3666
|
+
t.typname AS "type",
|
|
3667
3667
|
tn.nspname AS "typeSchema",
|
|
3668
|
-
|
|
3669
|
-
information_schema._pg_char_max_length(
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
)
|
|
3673
|
-
information_schema._pg_numeric_precision(
|
|
3674
|
-
information_schema._pg_truetypid(a, t),
|
|
3675
|
-
information_schema._pg_truetypmod(a, t)
|
|
3676
|
-
) AS "numericPrecision",
|
|
3677
|
-
information_schema._pg_numeric_scale(
|
|
3678
|
-
information_schema._pg_truetypid(a, t),
|
|
3679
|
-
information_schema._pg_truetypmod(a, t)
|
|
3680
|
-
) AS "numericScale",
|
|
3681
|
-
information_schema._pg_datetime_precision(
|
|
3682
|
-
information_schema._pg_truetypid(a, t),
|
|
3683
|
-
information_schema._pg_truetypmod(a, t)
|
|
3684
|
-
) AS "dateTimePrecision",
|
|
3668
|
+
a.attndims AS "arrayDims",
|
|
3669
|
+
information_schema._pg_char_max_length(tt.id, tt.mod) "maxChars",
|
|
3670
|
+
information_schema._pg_numeric_precision(tt.id, tt.mod) "numericPrecision",
|
|
3671
|
+
information_schema._pg_numeric_scale(tt.id,tt.mod) "numericScale",
|
|
3672
|
+
information_schema._pg_datetime_precision(tt.id,tt.mod) "dateTimePrecision",
|
|
3685
3673
|
CAST(
|
|
3686
3674
|
CASE WHEN a.attgenerated = ''
|
|
3687
3675
|
THEN pg_get_expr(ad.adbin, ad.adrelid)
|
|
@@ -3704,7 +3692,7 @@ const columnsSql = ({
|
|
|
3704
3692
|
nullif(seq.seqmin, 1),
|
|
3705
3693
|
'max',
|
|
3706
3694
|
nullif(seq.seqmax, (
|
|
3707
|
-
CASE
|
|
3695
|
+
CASE t.typname
|
|
3708
3696
|
WHEN 'int2' THEN 32767
|
|
3709
3697
|
WHEN 'int4' THEN 2147483647
|
|
3710
3698
|
WHEN 'int8' THEN 9223372036854775807
|
|
@@ -3721,8 +3709,18 @@ const columnsSql = ({
|
|
|
3721
3709
|
FROM pg_attribute a
|
|
3722
3710
|
${join}
|
|
3723
3711
|
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
|
|
3724
|
-
JOIN pg_type t
|
|
3725
|
-
|
|
3712
|
+
JOIN pg_type t
|
|
3713
|
+
ON t.oid = (
|
|
3714
|
+
CASE WHEN a.attndims = 0
|
|
3715
|
+
THEN a.atttypid
|
|
3716
|
+
ELSE (SELECT t.typelem FROM pg_type t WHERE t.oid = a.atttypid)
|
|
3717
|
+
END
|
|
3718
|
+
)
|
|
3719
|
+
JOIN LATERAL (
|
|
3720
|
+
SELECT
|
|
3721
|
+
CASE WHEN t.typtype = 'd' THEN t.typbasetype ELSE t.oid END id,
|
|
3722
|
+
CASE WHEN t.typtype = 'd' THEN t.typtypmod ELSE a.atttypmod END mod
|
|
3723
|
+
) tt ON true
|
|
3726
3724
|
JOIN pg_namespace tn ON tn.oid = t.typnamespace
|
|
3727
3725
|
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
|
|
3728
3726
|
ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
|
|
@@ -3981,7 +3979,7 @@ const domainsSql = `SELECT
|
|
|
3981
3979
|
t.typname AS "type",
|
|
3982
3980
|
s.nspname AS "typeSchema",
|
|
3983
3981
|
NOT d.typnotnull AS "isNullable",
|
|
3984
|
-
d.
|
|
3982
|
+
d.typndims AS "arrayDims",
|
|
3985
3983
|
character_maximum_length AS "maxChars",
|
|
3986
3984
|
numeric_precision AS "numericPrecision",
|
|
3987
3985
|
numeric_scale AS "numericScale",
|
|
@@ -4247,7 +4245,7 @@ const makeDomainsMap = (ctx, data) => {
|
|
|
4247
4245
|
name: it.name,
|
|
4248
4246
|
type: it.type,
|
|
4249
4247
|
typeSchema: it.typeSchema,
|
|
4250
|
-
|
|
4248
|
+
arrayDims: it.arrayDims,
|
|
4251
4249
|
tableName: "",
|
|
4252
4250
|
isNullable: it.isNullable,
|
|
4253
4251
|
collate: it.collate,
|
|
@@ -4310,11 +4308,19 @@ const instantiateDbColumn = (ctx, data, domains, dbColumn) => {
|
|
|
4310
4308
|
}
|
|
4311
4309
|
}
|
|
4312
4310
|
column.data.name = void 0;
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4311
|
+
if (!column.data.isNullable)
|
|
4312
|
+
column.data.isNullable = void 0;
|
|
4313
|
+
if (dbColumn.arrayDims) {
|
|
4314
|
+
const arr = new pqb.ArrayColumn(
|
|
4315
|
+
ctx.columnSchemaConfig,
|
|
4316
|
+
column,
|
|
4317
|
+
ctx.columnSchemaConfig.type
|
|
4318
|
+
);
|
|
4319
|
+
arr.data.isNullable = dbColumn.isNullable;
|
|
4320
|
+
arr.data.arrayDims = dbColumn.arrayDims;
|
|
4321
|
+
column = arr;
|
|
4322
|
+
}
|
|
4323
|
+
return column;
|
|
4318
4324
|
};
|
|
4319
4325
|
const instantiateColumnByDbType = (ctx, type, isSerial, params) => {
|
|
4320
4326
|
const columnFn = ctx.columnsByType[!isSerial ? type : type === "int2" ? "smallserial" : type === "int4" ? "serial" : "bigserial"];
|
|
@@ -4978,11 +4984,17 @@ const astEncoders = {
|
|
|
4978
4984
|
ast.shape.createdAt,
|
|
4979
4985
|
ast.shape.updatedAt
|
|
4980
4986
|
);
|
|
4987
|
+
const toCodeCtx = {
|
|
4988
|
+
t: "t",
|
|
4989
|
+
table: ast.name,
|
|
4990
|
+
migration: true,
|
|
4991
|
+
snakeCase: config.snakeCase
|
|
4992
|
+
};
|
|
4981
4993
|
for (const key in ast.shape) {
|
|
4982
4994
|
if (timestamps.hasAnyTimestamps && (key === "createdAt" || key === "updatedAt"))
|
|
4983
4995
|
continue;
|
|
4984
4996
|
const line = [`${orchidCore.quoteObjectKey(key)}: `];
|
|
4985
|
-
const columnCode =
|
|
4997
|
+
const columnCode = ast.shape[key].toCode(toCodeCtx, key);
|
|
4986
4998
|
for (const part of columnCode) {
|
|
4987
4999
|
orchidCore.addCode(line, part);
|
|
4988
5000
|
}
|
|
@@ -5032,6 +5044,12 @@ const astEncoders = {
|
|
|
5032
5044
|
);
|
|
5033
5045
|
}
|
|
5034
5046
|
);
|
|
5047
|
+
const toCodeCtx = {
|
|
5048
|
+
t: "t",
|
|
5049
|
+
table: ast.name,
|
|
5050
|
+
migration: true,
|
|
5051
|
+
snakeCase: config.snakeCase
|
|
5052
|
+
};
|
|
5035
5053
|
for (const key in ast.shape) {
|
|
5036
5054
|
const changes = orchidCore.toArray(ast.shape[key]);
|
|
5037
5055
|
for (const change of changes) {
|
|
@@ -5044,7 +5062,7 @@ const astEncoders = {
|
|
|
5044
5062
|
(_a = change.item.data.name) != null ? _a : key
|
|
5045
5063
|
)})` : `${orchidCore.quoteObjectKey(key)}: t.${change.type}(`
|
|
5046
5064
|
];
|
|
5047
|
-
const columnCode =
|
|
5065
|
+
const columnCode = change.item.toCode(toCodeCtx, key);
|
|
5048
5066
|
for (let i = 0; i < columnCode.length; i++) {
|
|
5049
5067
|
let part = columnCode[i];
|
|
5050
5068
|
if (recreate && !i)
|
|
@@ -5059,16 +5077,20 @@ const astEncoders = {
|
|
|
5059
5077
|
const line = [
|
|
5060
5078
|
`${orchidCore.quoteObjectKey(key)}: t${change.name ? `.name(${orchidCore.singleQuote(change.name)})` : ""}.change(`
|
|
5061
5079
|
];
|
|
5062
|
-
const fromCode =
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5080
|
+
const fromCode = change.from.column.toCode(
|
|
5081
|
+
{
|
|
5082
|
+
t: "t",
|
|
5083
|
+
table: ast.name,
|
|
5084
|
+
migration: true,
|
|
5085
|
+
snakeCase: config.snakeCase
|
|
5086
|
+
},
|
|
5087
|
+
key
|
|
5066
5088
|
);
|
|
5067
5089
|
for (const part of fromCode) {
|
|
5068
5090
|
orchidCore.addCode(line, part);
|
|
5069
5091
|
}
|
|
5070
5092
|
orchidCore.addCode(line, ", ");
|
|
5071
|
-
const toCode =
|
|
5093
|
+
const toCode = change.to.column.toCode(toCodeCtx, key);
|
|
5072
5094
|
for (const part of toCode) {
|
|
5073
5095
|
orchidCore.addCode(line, part);
|
|
5074
5096
|
}
|
|
@@ -5192,9 +5214,13 @@ const astEncoders = {
|
|
|
5192
5214
|
)}, [${ast.fromValues.map(orchidCore.singleQuote).join(", ")}], [${ast.toValues.map(orchidCore.singleQuote).join(", ")}]);`;
|
|
5193
5215
|
},
|
|
5194
5216
|
domain(ast) {
|
|
5217
|
+
var _a;
|
|
5195
5218
|
return `await db.${ast.action}Domain(${quoteSchemaTable(
|
|
5196
5219
|
ast
|
|
5197
|
-
)}, (t) => ${ast.baseType.toCode(
|
|
5220
|
+
)}, (t) => ${ast.baseType.toCode(
|
|
5221
|
+
{ t: "t", table: ast.name },
|
|
5222
|
+
(_a = ast.baseType.data.name) != null ? _a : ""
|
|
5223
|
+
)});`;
|
|
5198
5224
|
},
|
|
5199
5225
|
collation(ast) {
|
|
5200
5226
|
const params = [];
|