miqro 1.9.3 → 3.0.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/README.md +18 -37
- package/build/cli.js +6 -0
- package/build/cmd-map.d.ts +79 -0
- package/{dist/cli.js → build/cmd-map.js} +21 -43
- package/build/cmds/doc-json.d.ts +2 -0
- package/build/cmds/doc-json.js +17 -0
- package/build/cmds/doc-md.d.ts +2 -0
- package/{dist/cmds/doc-json.js → build/cmds/doc-md.js} +6 -5
- package/{dist → build}/cmds/handler-main-new.js +21 -15
- package/build/cmds/help.d.ts +1 -0
- package/build/cmds/help.js +9 -0
- package/{dist → build}/cmds/new-test.js +13 -2
- package/{dist → build}/cmds/new.js +20 -15
- package/{dist → build}/cmds/serve.d.ts +1 -1
- package/{dist → build}/cmds/serve.js +12 -7
- package/{dist → build}/cmds/start.d.ts +1 -1
- package/{dist → build}/cmds/start.js +1 -1
- package/build/utils/doc/json.d.ts +6 -0
- package/build/utils/doc/json.js +15 -0
- package/build/utils/doc/md.d.ts +18 -0
- package/build/utils/doc/md.js +129 -0
- package/{dist → build}/utils/index.d.ts +8 -5
- package/{dist → build}/utils/index.js +20 -14
- package/package.json +15 -16
- package/dist/cmds/db-console.d.ts +0 -2
- package/dist/cmds/db-console.js +0 -38
- package/dist/cmds/db-createmodel.d.ts +0 -2
- package/dist/cmds/db-createmodel.js +0 -37
- package/dist/cmds/db-dump-data.d.ts +0 -2
- package/dist/cmds/db-dump-data.js +0 -43
- package/dist/cmds/db-init.d.ts +0 -2
- package/dist/cmds/db-init.js +0 -38
- package/dist/cmds/db-makemigrations.d.ts +0 -2
- package/dist/cmds/db-makemigrations.js +0 -14
- package/dist/cmds/db-migrate.d.ts +0 -2
- package/dist/cmds/db-migrate.js +0 -12
- package/dist/cmds/db-push-data.d.ts +0 -2
- package/dist/cmds/db-push-data.js +0 -79
- package/dist/cmds/db-sync-makemigrations.d.ts +0 -2
- package/dist/cmds/db-sync-makemigrations.js +0 -14
- package/dist/cmds/doc-json.d.ts +0 -2
- package/dist/cmds/doc-md.d.ts +0 -2
- package/dist/cmds/doc-md.js +0 -234
- package/dist/cmds/test.d.ts +0 -2
- package/dist/cmds/test.js +0 -15
- package/dist/utils/db/automigrations/index.d.ts +0 -2
- package/dist/utils/db/automigrations/index.js +0 -121
- package/dist/utils/db/automigrations/migrate.d.ts +0 -45
- package/dist/utils/db/automigrations/migrate.js +0 -750
- package/dist/utils/db/index.d.ts +0 -20
- package/dist/utils/db/index.js +0 -127
- package/dist/utils/doc/index.d.ts +0 -18
- package/dist/utils/doc/index.js +0 -36
- /package/{dist → build}/cli.d.ts +0 -0
- /package/{dist → build}/cmds/config-bash.d.ts +0 -0
- /package/{dist → build}/cmds/config-bash.js +0 -0
- /package/{dist → build}/cmds/config-env.d.ts +0 -0
- /package/{dist → build}/cmds/config-env.js +0 -0
- /package/{dist → build}/cmds/config-init.d.ts +0 -0
- /package/{dist → build}/cmds/config-init.js +0 -0
- /package/{dist → build}/cmds/config.d.ts +0 -0
- /package/{dist → build}/cmds/config.js +0 -0
- /package/{dist → build}/cmds/handler-apiroute-new.d.ts +0 -0
- /package/{dist → build}/cmds/handler-apiroute-new.js +0 -0
- /package/{dist → build}/cmds/handler-main-new.d.ts +0 -0
- /package/{dist → build}/cmds/new-test.d.ts +0 -0
- /package/{dist → build}/cmds/new.d.ts +0 -0
- /package/{dist → build}/cmds/watch.d.ts +0 -0
- /package/{dist → build}/cmds/watch.js +0 -0
- /package/{dist → build}/cmds/wc-new.d.ts +0 -0
- /package/{dist → build}/cmds/wc-new.js +0 -0
- /package/{dist → build}/index.d.ts +0 -0
- /package/{dist → build}/index.js +0 -0
- /package/{dist → build}/utils/templates.d.ts +0 -0
- /package/{dist → build}/utils/templates.js +0 -0
package/dist/cmds/doc-md.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.main = exports.usage = void 0;
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const doc_1 = require("../utils/doc");
|
|
8
|
-
exports.usage = `usage: [NODE_ENV=development] npx miqro doc:md <api_folder> <subPath> <out.md>`;
|
|
9
|
-
const main = () => {
|
|
10
|
-
if (process.argv.length !== 6) {
|
|
11
|
-
throw new Error(exports.usage);
|
|
12
|
-
}
|
|
13
|
-
const dirname = process.argv[3];
|
|
14
|
-
const subPath = process.argv[4];
|
|
15
|
-
const outPath = process.argv[5];
|
|
16
|
-
(0, core_1.loadConfig)();
|
|
17
|
-
const parseOptionMap2ParseOptionList = (map) => {
|
|
18
|
-
return Object.keys(map).map(name => {
|
|
19
|
-
const val = map[name];
|
|
20
|
-
return typeof val !== "object" ? {
|
|
21
|
-
name,
|
|
22
|
-
required: true,
|
|
23
|
-
type: val
|
|
24
|
-
} : val.required === undefined ? {
|
|
25
|
-
...val,
|
|
26
|
-
required: true,
|
|
27
|
-
name
|
|
28
|
-
} : {
|
|
29
|
-
...val,
|
|
30
|
-
name
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const docJSON = (0, doc_1.getDOCJSON)({ dirname, subPath }, (0, core_1.getLogger)("miqro"));
|
|
35
|
-
const policyTable = (policy) => {
|
|
36
|
-
if (policy) {
|
|
37
|
-
return `|policy|groups|\n|----|----|\n|${policy.groupPolicy}|${policy.groups.join(", ")}|`;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return "";
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const methodUrlTable = (options) => {
|
|
44
|
-
if (options && options.path) {
|
|
45
|
-
const rows = [];
|
|
46
|
-
const paths = options.path instanceof Array ? options.path : [options.path];
|
|
47
|
-
for (const p of paths) {
|
|
48
|
-
if (options.method instanceof Array) {
|
|
49
|
-
for (const m of options.method) {
|
|
50
|
-
rows.push(`|${m}|${p}|`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
rows.push(`|${options.method}|${p}|`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return `|method|path|\n|----|----|\n${rows.join("\n")}`;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const getRange = (o, t) => {
|
|
64
|
-
let range = " ";
|
|
65
|
-
switch (t) {
|
|
66
|
-
case "string":
|
|
67
|
-
if (o.stringMinLength !== undefined || o.stringMaxLength !== undefined) {
|
|
68
|
-
range = "";
|
|
69
|
-
}
|
|
70
|
-
if (o.stringMinLength !== undefined) {
|
|
71
|
-
range = `${o.stringMinLength}:`;
|
|
72
|
-
}
|
|
73
|
-
if (o.stringMaxLength !== undefined) {
|
|
74
|
-
range += `:${o.stringMaxLength}`;
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
case "number":
|
|
78
|
-
if (o.numberMin !== undefined || o.numberMax !== undefined) {
|
|
79
|
-
range = "";
|
|
80
|
-
}
|
|
81
|
-
if (o.numberMin !== undefined) {
|
|
82
|
-
range = `${o.numberMin}:`;
|
|
83
|
-
}
|
|
84
|
-
if (o.numberMax !== undefined) {
|
|
85
|
-
range += `:${o.numberMax}`;
|
|
86
|
-
}
|
|
87
|
-
if (o.numberMinDecimals !== undefined) {
|
|
88
|
-
range = `${range ? " " : ""}decimal ${o.numberMinDecimals}:`;
|
|
89
|
-
}
|
|
90
|
-
if (o.numberMaxDecimals !== undefined) {
|
|
91
|
-
range += `${range ? " " : ""}${o.numberMinDecimals !== undefined ? "" : "decimal "}:${o.numberMaxDecimals}`;
|
|
92
|
-
}
|
|
93
|
-
break;
|
|
94
|
-
case "array":
|
|
95
|
-
if (o.arrayMinLength !== undefined || o.arrayMaxLength !== undefined) {
|
|
96
|
-
range = "";
|
|
97
|
-
}
|
|
98
|
-
if (o.arrayMinLength !== undefined) {
|
|
99
|
-
range = `${o.arrayMinLength}:`;
|
|
100
|
-
}
|
|
101
|
-
if (o.arrayMaxLength !== undefined) {
|
|
102
|
-
range += `:${o.arrayMaxLength}`;
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
return range;
|
|
107
|
-
};
|
|
108
|
-
const parseOptionTable = (options, subName = "", tableHeaders = 0) => {
|
|
109
|
-
if (typeof options !== "boolean" && options) {
|
|
110
|
-
let padding = "";
|
|
111
|
-
for (let i = 0; i < tableHeaders; i++) {
|
|
112
|
-
padding += "| ";
|
|
113
|
-
}
|
|
114
|
-
const hl = "|----|----|----|----|----|----|----|----|----|----|";
|
|
115
|
-
const list = options.options instanceof Array ? options.options : parseOptionMap2ParseOptionList(options.options);
|
|
116
|
-
const headers = `|**name**|**description**|**type**|**arrayRange**|**arrayType**|**range**|**values**|**defaultValue**|**required**|**allowNull**|`;
|
|
117
|
-
return `${tableHeaders >= 0 ? `${padding}${headers}\n${tableHeaders === 0 ? `${padding}${hl}\n` : ""}` : ""}${list.map(o => {
|
|
118
|
-
const arrayRange = o.type === "array" ? getRange(o, o.type) : " ";
|
|
119
|
-
const range = o.type === "array" ? (o.arrayType ? getRange(o, o.arrayType) : " ") : getRange(o, o.type);
|
|
120
|
-
let out = `${padding}|${subName}${o.name}|${o.description ? o.description : " "}|${o.type}|${arrayRange}|${o.arrayType ? o.arrayType : " "}|` +
|
|
121
|
-
`${range}|` +
|
|
122
|
-
`${o.enumValues ? o.enumValues.join(", ") : " "}|${o.defaultValue !== undefined ? o.defaultValue : " "}|${o.required === undefined ? true : o.required}|${o.allowNull ? "true" : "false"}|`;
|
|
123
|
-
if (o.type === "multiple" || o.arrayType === "multiple") {
|
|
124
|
-
out += `\n${(o.multipleOptions ? o.multipleOptions : []).map(oM => {
|
|
125
|
-
return parseOptionTable({
|
|
126
|
-
options: [{
|
|
127
|
-
name: o.name,
|
|
128
|
-
...oM
|
|
129
|
-
}]
|
|
130
|
-
}, "", tableHeaders ? tableHeaders + 1 : 1);
|
|
131
|
-
})}`;
|
|
132
|
-
return out;
|
|
133
|
-
}
|
|
134
|
-
else if (o.type === "nested" || o.arrayType === "nested") {
|
|
135
|
-
out += `\n${parseOptionTable({ options: o.nestedOptions ? o.nestedOptions.options : [] }, `${subName}${o.name}${o.type === "array" ? "[..]" : ""}.`, tableHeaders ? tableHeaders + 1 : 1)}`;
|
|
136
|
-
return out;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return out;
|
|
140
|
-
}
|
|
141
|
-
}).join("\n")}`;
|
|
142
|
-
}
|
|
143
|
-
else if (options === false) {
|
|
144
|
-
return "";
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return "";
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const FAKE_TAB = " ";
|
|
151
|
-
const FAKE_DOUBLE_TAB = `${FAKE_TAB}${FAKE_TAB}`;
|
|
152
|
-
const featureIndex = `${docJSON.map(doc => {
|
|
153
|
-
return `- [${doc.featureName}](#${doc.featureName.toLowerCase()})\n\n${doc.description ? `${FAKE_TAB}${doc.description}\n\n` : ""}${FAKE_DOUBLE_TAB}${doc.path}`;
|
|
154
|
-
}).join("\n\n")}`;
|
|
155
|
-
(0, fs_1.writeFileSync)((0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), outPath), `${featureIndex}\n\n` + docJSON.map(doc => {
|
|
156
|
-
const param = doc.params instanceof Array ? doc.params : [doc.params];
|
|
157
|
-
const paramsTable = [];
|
|
158
|
-
for (const q of param) {
|
|
159
|
-
let paramTable = typeof q === "string" ? `${q}` : parseOptionTable(q);
|
|
160
|
-
if (paramTable.split("\n").length > 1) {
|
|
161
|
-
paramTable = `### params${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}\n\n${paramTable}`;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
paramTable = paramTable === "" ? "" : `### params${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}: ${paramTable}`;
|
|
165
|
-
}
|
|
166
|
-
if (paramTable !== "") {
|
|
167
|
-
paramsTable.push(paramTable);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const query = doc.query instanceof Array ? doc.query : [doc.query];
|
|
171
|
-
const queryTables = [];
|
|
172
|
-
for (const q of query) {
|
|
173
|
-
let queryTable = typeof q === "string" ? `${q}` : parseOptionTable(q);
|
|
174
|
-
// let paramsTable = parseOptionTable(doc.params);
|
|
175
|
-
if (queryTable.split("\n").length > 1) {
|
|
176
|
-
queryTable = `### query${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}\n\n${queryTable}`;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
queryTable = queryTable === "" ? "" : `### query${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}: ${queryTable}`;
|
|
180
|
-
}
|
|
181
|
-
if (queryTable !== "") {
|
|
182
|
-
queryTables.push(queryTable);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/*if (paramsTable.split("\n").length > 1) {
|
|
186
|
-
paramsTable = `- params\n\n${paramsTable}`;
|
|
187
|
-
} else {
|
|
188
|
-
paramsTable = paramsTable === "" ? "" : `- params: ${paramsTable}`;
|
|
189
|
-
}*/
|
|
190
|
-
const body = doc.body instanceof Array ? doc.body : [doc.body];
|
|
191
|
-
const bodyTables = [];
|
|
192
|
-
for (const b of body) {
|
|
193
|
-
let bodyTable = typeof b === "string" ? `${b}` : parseOptionTable(b);
|
|
194
|
-
if (bodyTable.split("\n").length > 1) {
|
|
195
|
-
bodyTable = `### body${typeof b !== "boolean" && typeof b !== "string" && b && b.description ? ` (${b.description})` : ""}\n\n${bodyTable}`;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
bodyTable = bodyTable === "" ? "" : `### body${typeof b !== "boolean" && typeof b !== "string" && b && b.description ? ` (${b.description})` : ""}: ${bodyTable}`;
|
|
199
|
-
}
|
|
200
|
-
if (bodyTable !== "") {
|
|
201
|
-
bodyTables.push(bodyTable);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const results = doc.response instanceof Array ? doc.response : [doc.response];
|
|
205
|
-
const resultTables = [];
|
|
206
|
-
for (const r of results) {
|
|
207
|
-
if (!r) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
let resultsTable = r && typeof r !== "string" && typeof r !== "boolean" ? parseOptionTable(r) : r;
|
|
211
|
-
if (resultsTable.split("\n").length > 1) {
|
|
212
|
-
resultsTable = `### response${typeof r !== "boolean" && typeof r !== "string" && r.description ? ` (${r.description})` : ""}\n\n${resultsTable}`;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
resultsTable = resultsTable === "" ? "" : `### response${typeof r !== "boolean" && typeof r !== "string" && r.description ? ` (${r.description})` : ""}: ${resultsTable}`;
|
|
216
|
-
}
|
|
217
|
-
if (resultsTable !== "") {
|
|
218
|
-
resultTables.push(resultsTable);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const pTable = policyTable(doc.policy);
|
|
222
|
-
return `## ${doc.featureName}\n\n` +
|
|
223
|
-
`${doc.description ? `${doc.description}\n\n` : ""}` +
|
|
224
|
-
`${pTable ? `${pTable}\n\n` : ""}` +
|
|
225
|
-
`### endpoint\n\n` +
|
|
226
|
-
`${methodUrlTable(doc)}\n\n` +
|
|
227
|
-
// `${paramsTable ? `${paramsTable}\n\n` : ""}` +
|
|
228
|
-
`${paramsTable.length > 0 ? `${paramsTable.join("\n\n")}\n\n` : ""}` +
|
|
229
|
-
`${queryTables.length > 0 ? `${queryTables.join("\n\n")}\n\n` : ""}` +
|
|
230
|
-
`${bodyTables.length > 0 ? `${bodyTables.join("\n\n")}\n\n` : ""}` +
|
|
231
|
-
`${resultTables.length > 0 ? `${resultTables.join("\n\n")}\n\n` : ""}`;
|
|
232
|
-
}).join("\n\n"));
|
|
233
|
-
};
|
|
234
|
-
exports.main = main;
|
package/dist/cmds/test.d.ts
DELETED
package/dist/cmds/test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.main = exports.usage = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const test_1 = require("@miqro/test");
|
|
6
|
-
const core_1 = require("@miqro/core");
|
|
7
|
-
exports.usage = "usage: npx miqro test <test_files> [-r <folder>] [-i] [-n testname]";
|
|
8
|
-
const main = () => {
|
|
9
|
-
if (process.argv.length <= 3) {
|
|
10
|
-
throw new Error(`invalid number of args\n${exports.usage}`);
|
|
11
|
-
}
|
|
12
|
-
(0, core_1.loadConfig)();
|
|
13
|
-
(0, utils_1.execSync)(`${process.argv[0]} ${(0, test_1.mainPath)()} ${process.argv.slice(3).join(" ")}`);
|
|
14
|
-
};
|
|
15
|
-
exports.main = main;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makemigrationsImpl = exports.syncMakeMigrationsImpl = void 0;
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const __1 = require("..");
|
|
8
|
-
const migrate_1 = require("./migrate");
|
|
9
|
-
const syncMakeMigrationsImpl = () => {
|
|
10
|
-
// Windows support
|
|
11
|
-
if (!process.env.PWD) {
|
|
12
|
-
process.env.PWD = process.cwd();
|
|
13
|
-
}
|
|
14
|
-
const sequelizeRC = (0, __1.loadSequelizeRC)();
|
|
15
|
-
// noinspection SpellCheckingInspection
|
|
16
|
-
const logger = (0, core_1.getLogger)("makemigrations");
|
|
17
|
-
try {
|
|
18
|
-
if (!(0, fs_1.existsSync)(sequelizeRC["models-path"])) {
|
|
19
|
-
logger.error("Can't find models directory. Use `sequelize init` to create it");
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (!(0, fs_1.existsSync)(sequelizeRC["migrations-path"])) {
|
|
23
|
-
logger.error("Can't find migrations directory. Use `sequelize init` to create it");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
// load last state
|
|
27
|
-
let previousState;
|
|
28
|
-
try {
|
|
29
|
-
previousState = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")).toString());
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
previousState = {
|
|
33
|
-
revision: 0,
|
|
34
|
-
tables: {}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const { modelsModule } = (0, __1.loadModels)({ ["models-path"]: sequelizeRC["models-path"] });
|
|
38
|
-
// current state
|
|
39
|
-
const currentState = {
|
|
40
|
-
revision: previousState.revision + 1,
|
|
41
|
-
tables: (0, migrate_1.reverseModels)(modelsModule.Sequelize, modelsModule.sequelize, modelsModule.sequelize.models, logger)
|
|
42
|
-
};
|
|
43
|
-
// backup _current file
|
|
44
|
-
if ((0, fs_1.existsSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"))) {
|
|
45
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current_bak.json"), (0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")));
|
|
46
|
-
}
|
|
47
|
-
// save current state
|
|
48
|
-
currentState.revision = previousState.revision + 1;
|
|
49
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"), JSON.stringify(currentState, null, 4));
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
logger.error(e);
|
|
53
|
-
throw e;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
exports.syncMakeMigrationsImpl = syncMakeMigrationsImpl;
|
|
57
|
-
// noinspection SpellCheckingInspection
|
|
58
|
-
const makemigrationsImpl = () => {
|
|
59
|
-
// Windows support
|
|
60
|
-
if (!process.env.PWD) {
|
|
61
|
-
process.env.PWD = process.cwd();
|
|
62
|
-
}
|
|
63
|
-
const sequelizeRC = (0, __1.loadSequelizeRC)();
|
|
64
|
-
// noinspection SpellCheckingInspection
|
|
65
|
-
const logger = (0, core_1.getLogger)("makemigrations");
|
|
66
|
-
try {
|
|
67
|
-
if (!(0, fs_1.existsSync)(sequelizeRC["models-path"])) {
|
|
68
|
-
logger.error("Can't find models directory. Use `sequelize init` to create it");
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (!(0, fs_1.existsSync)(sequelizeRC["migrations-path"])) {
|
|
72
|
-
logger.error("Can't find migrations directory. Use `sequelize init` to create it");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// load last state
|
|
76
|
-
let previousState;
|
|
77
|
-
try {
|
|
78
|
-
previousState = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")).toString());
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
previousState = {
|
|
82
|
-
revision: 0,
|
|
83
|
-
tables: {}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const { modelsModule } = (0, __1.loadModels)({ ["models-path"]: sequelizeRC["models-path"] });
|
|
87
|
-
// current state
|
|
88
|
-
const currentState = {
|
|
89
|
-
revision: previousState.revision + 1,
|
|
90
|
-
tables: (0, migrate_1.reverseModels)(modelsModule.Sequelize, modelsModule.sequelize, modelsModule.sequelize.models, logger)
|
|
91
|
-
};
|
|
92
|
-
const actions = (0, migrate_1.parseDifference)(previousState.tables, currentState.tables, logger);
|
|
93
|
-
// sort actions
|
|
94
|
-
(0, migrate_1.sortActions)(actions);
|
|
95
|
-
const migration = (0, migrate_1.getMigration)(actions);
|
|
96
|
-
if (migration.commandsUp.length === 0) {
|
|
97
|
-
logger.info("No changes found");
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
// log migration actions
|
|
101
|
-
migration.consoleOut.forEach((v) => {
|
|
102
|
-
logger.info("[Actions] " + v);
|
|
103
|
-
});
|
|
104
|
-
// backup _current file
|
|
105
|
-
if ((0, fs_1.existsSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"))) {
|
|
106
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current_bak.json"), (0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")));
|
|
107
|
-
}
|
|
108
|
-
// save current state
|
|
109
|
-
currentState.revision = previousState.revision + 1;
|
|
110
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"), JSON.stringify(currentState, null, 4));
|
|
111
|
-
// write migration to file
|
|
112
|
-
const info = (0, migrate_1.writeMigration)(currentState.revision, migration, sequelizeRC["migrations-path"], "noname", "");
|
|
113
|
-
logger.info(`New migration to revision ${currentState.revision} has been saved to file '${info.filename}'`);
|
|
114
|
-
return info.filename;
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
logger.error(e);
|
|
118
|
-
throw e;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
exports.makemigrationsImpl = makemigrationsImpl;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
interface TableMap {
|
|
2
|
-
[tableName: string]: {
|
|
3
|
-
tableName: string;
|
|
4
|
-
schema: any;
|
|
5
|
-
indexes: any;
|
|
6
|
-
model?: any;
|
|
7
|
-
options?: any;
|
|
8
|
-
fields?: any[];
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export interface MigrationState {
|
|
12
|
-
tables: TableMap;
|
|
13
|
-
revision: number;
|
|
14
|
-
}
|
|
15
|
-
export declare const reverseModels: (sequelizeModule: any, sequelize: any, realModels: {
|
|
16
|
-
[model: string]: any;
|
|
17
|
-
}, logger: any) => TableMap;
|
|
18
|
-
interface DiffAction {
|
|
19
|
-
actionType: string;
|
|
20
|
-
columnName?: string;
|
|
21
|
-
attributeName?: any;
|
|
22
|
-
fields?: string[];
|
|
23
|
-
tableName?: any;
|
|
24
|
-
attributes?: any;
|
|
25
|
-
options?: any;
|
|
26
|
-
depends?: any;
|
|
27
|
-
}
|
|
28
|
-
export declare const parseDifference: (previousState: TableMap, currentState: TableMap, logger: any) => DiffAction[];
|
|
29
|
-
export declare const sortActions: (actions: DiffAction[]) => void;
|
|
30
|
-
interface Migration {
|
|
31
|
-
commandsUp: string[];
|
|
32
|
-
consoleOut: string[];
|
|
33
|
-
}
|
|
34
|
-
export declare const getMigration: (actions: DiffAction[]) => Migration;
|
|
35
|
-
interface WritenMigration {
|
|
36
|
-
filename: string;
|
|
37
|
-
info: {
|
|
38
|
-
revision: number;
|
|
39
|
-
name: string;
|
|
40
|
-
created: Date;
|
|
41
|
-
comment: string;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export declare const writeMigration: (revision: number, migration: Migration, migrationsDir: string, name?: string, comment?: string) => WritenMigration;
|
|
45
|
-
export {};
|