@yongdall/migrate 0.4.0 → 0.5.2
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/index.d.mts +10 -1
- package/index.mjs +19 -7
- package/index.mjs.map +1 -1
- package/package.json +7 -10
- package/bin.mjs +0 -20
- package/bin.mjs.map +0 -1
package/index.d.mts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { ModelTable } from "@yongdall/model";
|
|
2
|
+
|
|
1
3
|
//#region cli/migrate/index.d.mts
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} Profile
|
|
6
|
+
* @property {ModelTable[]} models
|
|
7
|
+
*/
|
|
2
8
|
/**
|
|
3
9
|
*
|
|
4
10
|
* @param {object} [options]
|
|
@@ -16,5 +22,8 @@ declare function _default({
|
|
|
16
22
|
database?: string | undefined;
|
|
17
23
|
domain?: string | undefined;
|
|
18
24
|
}): Promise<void>;
|
|
25
|
+
type Profile = {
|
|
26
|
+
models: ModelTable[];
|
|
27
|
+
};
|
|
19
28
|
//#endregion
|
|
20
|
-
export { _default as default };
|
|
29
|
+
export { Profile, _default as default };
|
package/index.mjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { hooks } from "@yongdall/core";
|
|
1
|
+
import { useDatabase } from "@yongdall/connection";
|
|
3
2
|
import { _run } from "@yongdall/context";
|
|
3
|
+
import { loadPluginProfiles } from "@yongdall/plugins";
|
|
4
4
|
|
|
5
5
|
//#region cli/migrate/index.mjs
|
|
6
|
+
/** @import { ModelTable } from '@yongdall/model' */
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} Profile
|
|
9
|
+
* @property {ModelTable[]} models
|
|
10
|
+
*/
|
|
6
11
|
/**
|
|
7
12
|
*
|
|
8
13
|
* @param {object} [options]
|
|
@@ -12,18 +17,25 @@ import { _run } from "@yongdall/context";
|
|
|
12
17
|
* @returns {Promise<void>}
|
|
13
18
|
*/
|
|
14
19
|
async function migrate_default({ plugins, database, domain } = {}) {
|
|
15
|
-
const
|
|
20
|
+
const pluginSet = plugins?.length ? new Set(plugins) : null;
|
|
21
|
+
const modelList = await Array.fromAsync(loadPluginProfiles("migration", function* (config, plugin) {
|
|
22
|
+
if (!config) return;
|
|
23
|
+
if (pluginSet && !pluginSet.has(plugin)) return;
|
|
24
|
+
const models = config.models;
|
|
25
|
+
if (!Array.isArray(models)) return;
|
|
26
|
+
yield* models;
|
|
27
|
+
}));
|
|
16
28
|
return _run({ domain: domain || "" }, async () => {
|
|
17
29
|
if (typeof database === "string") {
|
|
18
30
|
const id = ["-_/"].includes(database) ? "" : database;
|
|
19
|
-
const models =
|
|
20
|
-
await
|
|
31
|
+
const models = modelList.filter((v) => (v.databaseId || "") === id);
|
|
32
|
+
await useDatabase(id).transaction((t) => t.syncTables(models));
|
|
21
33
|
return;
|
|
22
34
|
}
|
|
23
|
-
const models = Object.groupBy(
|
|
35
|
+
const models = Object.groupBy(modelList, (d) => d.databaseId || "");
|
|
24
36
|
for (const [databaseId, list] of Object.entries(models)) {
|
|
25
37
|
if (!list) continue;
|
|
26
|
-
await
|
|
38
|
+
await useDatabase(databaseId).transaction((t) => t.syncTables(list));
|
|
27
39
|
}
|
|
28
40
|
});
|
|
29
41
|
}
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../cli/migrate/index.mjs"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../cli/migrate/index.mjs"],"sourcesContent":["/** @import { ModelTable } from '@yongdall/model' */\nimport { useDatabase } from '@yongdall/connection';\nimport { _run } from '@yongdall/context';\nimport { loadPluginProfiles } from '@yongdall/plugins';\n\n/**\n * @typedef {object} Profile\n * @property {ModelTable[]} models\n */\n/**\n * \n * @param {object} [options]\n * @param {string[]} [options.plugins]\n * @param {string} [options.database] \n * @param {string} [options.domain] \n * @returns {Promise<void>}\n */\nexport default async function ({\n\tplugins, database, domain\n} = {}) {\n\tconst pluginSet = plugins?.length ? new Set(plugins) : null;\n\tconst modelList = await Array.fromAsync(\n\t\tloadPluginProfiles('migration', function* (/** @type {Partial<Profile>} */config, plugin) {\n\t\t\tif (!config) { return; }\n\t\t\tif (pluginSet && !pluginSet.has(plugin)) { return; }\n\t\t\tconst models = config.models;\n\t\t\tif (!Array.isArray(models)) { return; }\n\t\t\tyield* models;\n\t\t})\n\t);\n\treturn _run({ domain: domain || '' }, async () => {\n\t\tif (typeof database === 'string') {\n\t\t\tconst id = ['-_/'].includes(database) ? '' : database;\n\t\t\tconst models = modelList.filter(v => (v.databaseId || '') === id);\n\t\t\tawait useDatabase(id).transaction(t => t.syncTables(models));\n\t\t\treturn;\n\t\t}\n\t\tconst models = Object.groupBy(modelList, d => d.databaseId || '');\n\t\tfor (const [databaseId, list] of Object.entries(models)) {\n\t\t\tif (!list) { continue; }\n\t\t\tawait useDatabase(databaseId).transaction(t => t.syncTables(list));\n\t\t}\n\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,+BAA+B,EAC9B,SAAS,UAAU,WAChB,EAAE,EAAE;CACP,MAAM,YAAY,SAAS,SAAS,IAAI,IAAI,QAAQ,GAAG;CACvD,MAAM,YAAY,MAAM,MAAM,UAC7B,mBAAmB,aAAa,WAA0C,QAAQ,QAAQ;AACzF,MAAI,CAAC,OAAU;AACf,MAAI,aAAa,CAAC,UAAU,IAAI,OAAO,CAAI;EAC3C,MAAM,SAAS,OAAO;AACtB,MAAI,CAAC,MAAM,QAAQ,OAAO,CAAI;AAC9B,SAAO;GACN,CACF;AACD,QAAO,KAAK,EAAE,QAAQ,UAAU,IAAI,EAAE,YAAY;AACjD,MAAI,OAAO,aAAa,UAAU;GACjC,MAAM,KAAK,CAAC,MAAM,CAAC,SAAS,SAAS,GAAG,KAAK;GAC7C,MAAM,SAAS,UAAU,QAAO,OAAM,EAAE,cAAc,QAAQ,GAAG;AACjE,SAAM,YAAY,GAAG,CAAC,aAAY,MAAK,EAAE,WAAW,OAAO,CAAC;AAC5D;;EAED,MAAM,SAAS,OAAO,QAAQ,YAAW,MAAK,EAAE,cAAc,GAAG;AACjE,OAAK,MAAM,CAAC,YAAY,SAAS,OAAO,QAAQ,OAAO,EAAE;AACxD,OAAI,CAAC,KAAQ;AACb,SAAM,YAAY,WAAW,CAAC,aAAY,MAAK,EAAE,WAAW,KAAK,CAAC;;GAGlE"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/migrate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"bin": {
|
|
6
|
-
"migrate.yongdall": "./bin.mjs"
|
|
7
|
-
},
|
|
8
5
|
"main": "./index.mjs",
|
|
9
6
|
"imports": {
|
|
10
7
|
"#index": "./index.mjs"
|
|
11
8
|
},
|
|
12
9
|
"dependencies": {
|
|
13
|
-
"@yongdall/plugins": "^0.
|
|
14
|
-
"@yongdall/context": "^0.
|
|
15
|
-
"@yongdall/
|
|
16
|
-
"@yongdall/
|
|
17
|
-
"@yongdall/
|
|
10
|
+
"@yongdall/plugins": "^0.5.0",
|
|
11
|
+
"@yongdall/context": "^0.5.0",
|
|
12
|
+
"@yongdall/init": "^0.5.0",
|
|
13
|
+
"@yongdall/connection": "^0.5.0",
|
|
14
|
+
"@yongdall/model": "^0.5.0"
|
|
18
15
|
},
|
|
19
16
|
"devDependencies": {
|
|
20
|
-
"@yongdall/cli-parse": "^0.
|
|
17
|
+
"@yongdall/cli-parse": "^0.5.0"
|
|
21
18
|
},
|
|
22
19
|
"exports": {
|
|
23
20
|
".": "./index.mjs"
|
package/bin.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { stop } from "@yongdall/connection";
|
|
2
|
-
import init from "@yongdall/init";
|
|
3
|
-
import migrate from "#index";
|
|
4
|
-
|
|
5
|
-
//#region cli/migrate/bin.mjs
|
|
6
|
-
let args = process.argv.slice(2);
|
|
7
|
-
let index = args.indexOf("--");
|
|
8
|
-
if (index >= 0) args = args.slice(0, index);
|
|
9
|
-
await init({ development: args.includes("--development") });
|
|
10
|
-
const domain = args.find((v) => v.startsWith("--domain="))?.slice(9) || "";
|
|
11
|
-
const plugins = [...args.filter((v) => v.startsWith("--plugin=")).map((v) => v.slice(9)), ...args.filter((v) => v.startsWith("--plugins=")).map((v) => v.slice(10))].flatMap((v) => v.split(",")).filter(Boolean);
|
|
12
|
-
const database = args.find((v) => v.startsWith("--database="))?.slice(11);
|
|
13
|
-
migrate({
|
|
14
|
-
domain,
|
|
15
|
-
plugins,
|
|
16
|
-
database
|
|
17
|
-
}).then(stop);
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//# sourceMappingURL=bin.mjs.map
|
package/bin.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bin.mjs","names":[],"sources":["../../cli/migrate/bin.mjs"],"sourcesContent":["import { stop } from '@yongdall/connection';\nimport init from '@yongdall/init';\nimport migrate from '#index';\n\n\n\nlet args = process.argv.slice(2);\nlet index = args.indexOf('--');\nif (index >= 0) {\n\targs = args.slice(0, index);\n}\nconst development = args.includes('--development');\nawait init({ development });\n\nconst domain = args.find(v => v.startsWith('--domain='))?.slice('--domain='.length) || '';\n\nconst plugins = [\n\t...args.filter(v => v.startsWith('--plugin=')).map(v => v.slice('--plugin='.length)),\n\t...args.filter(v => v.startsWith('--plugins=')).map(v => v.slice('--plugins='.length)),\n].flatMap(v => v.split(',')).filter(Boolean);\nconst database = args.find(v => v.startsWith('--database='))?.slice('--database='.length);\nmigrate({ domain, plugins, database }).then(stop);\n"],"mappings":";;;;;AAMA,IAAI,OAAO,QAAQ,KAAK,MAAM,EAAE;AAChC,IAAI,QAAQ,KAAK,QAAQ,KAAK;AAC9B,IAAI,SAAS,EACZ,QAAO,KAAK,MAAM,GAAG,MAAM;AAG5B,MAAM,KAAK,EAAE,aADO,KAAK,SAAS,gBAAgB,EACxB,CAAC;AAE3B,MAAM,SAAS,KAAK,MAAK,MAAK,EAAE,WAAW,YAAY,CAAC,EAAE,MAAM,EAAmB,IAAI;AAEvF,MAAM,UAAU,CACf,GAAG,KAAK,QAAO,MAAK,EAAE,WAAW,YAAY,CAAC,CAAC,KAAI,MAAK,EAAE,MAAM,EAAmB,CAAC,EACpF,GAAG,KAAK,QAAO,MAAK,EAAE,WAAW,aAAa,CAAC,CAAC,KAAI,MAAK,EAAE,MAAM,GAAoB,CAAC,CACtF,CAAC,SAAQ,MAAK,EAAE,MAAM,IAAI,CAAC,CAAC,OAAO,QAAQ;AAC5C,MAAM,WAAW,KAAK,MAAK,MAAK,EAAE,WAAW,cAAc,CAAC,EAAE,MAAM,GAAqB;AACzF,QAAQ;CAAE;CAAQ;CAAS;CAAU,CAAC,CAAC,KAAK,KAAK"}
|