@apso/cli 0.47.2 → 0.47.4
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/lib/ddl/change.js
CHANGED
|
@@ -99,6 +99,7 @@ const nullableSql = (c) => `${(0, _1.q)(c.name)} ${c.type}${c.default === undefi
|
|
|
99
99
|
const changed = (x, y) => !y || x.name !== y.name || x.body !== y.body || x.unique !== y.unique;
|
|
100
100
|
/** The enum type name in a column type like "public"."contact_status_enum". */
|
|
101
101
|
const typeOf = (t) => { var _a; return ((_a = t.match(/^"public"\."(.+)"$/)) !== null && _a !== void 0 ? _a : [])[1]; };
|
|
102
|
+
const isArray = (t) => t.endsWith("[]");
|
|
102
103
|
function changeDdl(before, after, plan) {
|
|
103
104
|
const renamed = applyRenames(before, after, plan);
|
|
104
105
|
const was = (0, _1.schemaModel)((0, apsorc_parser_1.parseApsorcV2)(before));
|
|
@@ -190,6 +191,9 @@ function changeDdl(before, after, plan) {
|
|
|
190
191
|
using = `${(0, _1.q)(c.name)}::text::${c.type}`;
|
|
191
192
|
else if ((cast === null || cast === void 0 ? void 0 : cast.answer) === "sql")
|
|
192
193
|
using = `(${cast.sql})`;
|
|
194
|
+
else if (isArray(o.type) !== isArray(c.type))
|
|
195
|
+
// A plain cast between a value and an array fails or garbles the data.
|
|
196
|
+
throw new Error(`${t.name}.${c.name} changes between ${o.type} and ${c.type}; a plain cast can't convert it. Answer "sql" with an expression that builds the new value.`);
|
|
193
197
|
if (o.default !== undefined)
|
|
194
198
|
up.push(`${at} DROP DEFAULT`);
|
|
195
199
|
up.push(`${at} TYPE ${c.type} USING ${using}`);
|
package/dist/lib/ddl/index.js
CHANGED
|
@@ -107,6 +107,14 @@ function columnSpec(table, f) {
|
|
|
107
107
|
case "json-plain":
|
|
108
108
|
type = "json";
|
|
109
109
|
break;
|
|
110
|
+
case "array": {
|
|
111
|
+
// entity-col-array.eta: { type: elementType || "text", array: true }, no default.
|
|
112
|
+
const element = f.elementType || "text";
|
|
113
|
+
if (!/^[a-z][\w ]*$/i.test(element))
|
|
114
|
+
throw new Error(`Field ${table}.${f.name} has an invalid elementType "${element}".`);
|
|
115
|
+
type = `${element}[]`;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
110
118
|
default:
|
|
111
119
|
// ponytail: spatial, range and other special templates; add each with a parity case.
|
|
112
120
|
throw new Error(`The DDL writer does not support field type "${f.type}" yet (${table}.${f.name}).`);
|
|
@@ -152,13 +160,24 @@ function schemaModel(input) {
|
|
|
152
160
|
const joinTables = [];
|
|
153
161
|
const inline = [];
|
|
154
162
|
const foreignKeys = [];
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
columns,
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
// The same columns can be indexed twice (a field or relationship
|
|
164
|
+
// "index": true plus an "indexes" entry). TypeORM names an index by its
|
|
165
|
+
// table and columns, so a second CREATE INDEX would fail on deploy: keep one.
|
|
166
|
+
const index = (table, columns, unique = false) => {
|
|
167
|
+
const key = `index:${table}(${columns.join(",")})`;
|
|
168
|
+
const seen = model.indexes.find((i) => i.key === key);
|
|
169
|
+
if (seen) {
|
|
170
|
+
seen.unique || (seen.unique = unique);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
model.indexes.push({
|
|
174
|
+
key,
|
|
175
|
+
name: exports.constraintName.index(table, columns),
|
|
176
|
+
table,
|
|
177
|
+
columns,
|
|
178
|
+
unique,
|
|
179
|
+
});
|
|
180
|
+
};
|
|
162
181
|
const unique = (table, columns, name, list = inline) => list.push({
|
|
163
182
|
key: `unique:${table}(${columns.join(",")})`,
|
|
164
183
|
name,
|
package/dist/lib/plan/index.d.ts
CHANGED
package/dist/lib/plan/index.js
CHANGED
|
@@ -28,6 +28,8 @@ const STRING_TYPES = new Set(["text", "varchar", "char", "string"]);
|
|
|
28
28
|
const sameType = (a, b) => {
|
|
29
29
|
const ta = (0, field_1.normalizeFieldType)(a.type);
|
|
30
30
|
const tb = (0, field_1.normalizeFieldType)(b.type);
|
|
31
|
+
if (ta === "array" && tb === "array")
|
|
32
|
+
return (a.elementType || "text") === (b.elementType || "text");
|
|
31
33
|
return ta === tb || (STRING_TYPES.has(ta) && STRING_TYPES.has(tb));
|
|
32
34
|
};
|
|
33
35
|
const fieldsOf = (e) => { var _a; return (_a = e === null || e === void 0 ? void 0 : e.fields) !== null && _a !== void 0 ? _a : []; };
|
|
@@ -150,7 +152,10 @@ function planMigration(before, after, previous) {
|
|
|
150
152
|
id: `cast:${now.name}.${old.name}`,
|
|
151
153
|
kind: "cast",
|
|
152
154
|
subject: `Field ${now.name}.${old.name} changes type from ${old.type} to ${cur.type}`,
|
|
153
|
-
|
|
155
|
+
// No plain cast turns a value into an array or back.
|
|
156
|
+
options: (cur.type === "array") === (old.type === "array")
|
|
157
|
+
? ["cast", "sql"]
|
|
158
|
+
: ["sql"],
|
|
154
159
|
});
|
|
155
160
|
}
|
|
156
161
|
else if (old.values && cur.values) {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.4",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@apso/cli",
|
|
9
|
-
"version": "0.47.
|
|
9
|
+
"version": "0.47.4",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@apso/schema-tools": "^0.2.0",
|
package/oclif.manifest.json
CHANGED