@medusajs/link-modules 0.2.12-preview-20240515135539 → 0.2.12-preview-20240515175257
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,3 +5,4 @@ export declare const initialize: (options?: ModuleServiceInitializeOptions | Mod
|
|
5
5
|
[link: string]: ILinkModule;
|
6
6
|
}>;
|
7
7
|
export declare function runMigrations({ options, logger, }: Omit<LoaderOptions<ModuleServiceInitializeOptions>, "container">, modulesDefinition?: ModuleJoinerConfig[]): Promise<void>;
|
8
|
+
export declare function revertMigrations({ options, logger, }: Omit<LoaderOptions<ModuleServiceInitializeOptions>, "container">, modulesDefinition?: ModuleJoinerConfig[]): Promise<void>;
|
package/dist/initialize/index.js
CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.runMigrations = exports.initialize = void 0;
|
26
|
+
exports.revertMigrations = exports.runMigrations = exports.initialize = void 0;
|
27
27
|
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
28
28
|
const types_1 = require("@medusajs/types");
|
29
29
|
const utils_1 = require("@medusajs/utils");
|
@@ -109,7 +109,7 @@ const initialize = async (options, modulesDefinition, injectedDependencies) => {
|
|
109
109
|
return allLinks;
|
110
110
|
};
|
111
111
|
exports.initialize = initialize;
|
112
|
-
async function
|
112
|
+
async function applyMigrationUpOrDown({ options, logger, }, modulesDefinition, revert = false) {
|
113
113
|
const modulesLoadedKeys = modules_sdk_1.MedusaModule.getLoadedModules().map((mod) => Object.keys(mod)[0]);
|
114
114
|
const allLinksToLoad = Object.values(linkDefinitions).concat(modulesDefinition ?? []);
|
115
115
|
const allLinks = new Set();
|
@@ -131,8 +131,17 @@ async function runMigrations({ options, logger, }, modulesDefinition) {
|
|
131
131
|
!modulesLoadedKeys.includes(foreign.serviceName)) {
|
132
132
|
continue;
|
133
133
|
}
|
134
|
-
const migrate =
|
134
|
+
const migrate = revert
|
135
|
+
? (0, migration_1.getRevertMigration)(definition, serviceKey, primary, foreign)
|
136
|
+
: (0, migration_1.getMigration)(definition, serviceKey, primary, foreign);
|
135
137
|
await migrate({ options, logger });
|
136
138
|
}
|
137
139
|
}
|
140
|
+
async function runMigrations({ options, logger, }, modulesDefinition) {
|
141
|
+
await applyMigrationUpOrDown({ options, logger }, modulesDefinition);
|
142
|
+
}
|
138
143
|
exports.runMigrations = runMigrations;
|
144
|
+
async function revertMigrations({ options, logger, }, modulesDefinition) {
|
145
|
+
await applyMigrationUpOrDown({ options, logger }, modulesDefinition, true);
|
146
|
+
}
|
147
|
+
exports.revertMigrations = revertMigrations;
|
@@ -1,2 +1,3 @@
|
|
1
1
|
import { JoinerRelationship, LoaderOptions, ModuleJoinerConfig, ModuleServiceInitializeOptions } from "@medusajs/types";
|
2
2
|
export declare function getMigration(joinerConfig: ModuleJoinerConfig, serviceName: string, primary: JoinerRelationship, foreign: JoinerRelationship): ({ options, logger, }?: Pick<LoaderOptions<ModuleServiceInitializeOptions>, "options" | "logger">) => Promise<void>;
|
3
|
+
export declare function getRevertMigration(joinerConfig: ModuleJoinerConfig, serviceName: string, primary: JoinerRelationship, foreign: JoinerRelationship): ({ options, logger, }?: Pick<LoaderOptions<ModuleServiceInitializeOptions>, "options" | "logger">) => Promise<void>;
|
package/dist/migration/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getMigration = void 0;
|
3
|
+
exports.getRevertMigration = exports.getMigration = void 0;
|
4
4
|
const utils_1 = require("../utils");
|
5
5
|
const utils_2 = require("@medusajs/utils");
|
6
6
|
function getMigration(joinerConfig, serviceName, primary, foreign) {
|
@@ -54,3 +54,22 @@ function getMigration(joinerConfig, serviceName, primary, foreign) {
|
|
54
54
|
};
|
55
55
|
}
|
56
56
|
exports.getMigration = getMigration;
|
57
|
+
function getRevertMigration(joinerConfig, serviceName, primary, foreign) {
|
58
|
+
return async function revertMigrations({ options, logger, } = {}) {
|
59
|
+
logger ??= console;
|
60
|
+
const dbData = utils_2.ModulesSdkUtils.loadDatabaseConfig("link_modules", options);
|
61
|
+
const entity = (0, utils_1.generateEntity)(joinerConfig, primary, foreign);
|
62
|
+
const pathToMigrations = __dirname + "/../migrations";
|
63
|
+
const orm = await utils_2.DALUtils.mikroOrmCreateConnection(dbData, [entity], pathToMigrations);
|
64
|
+
try {
|
65
|
+
const migrator = orm.getMigrator();
|
66
|
+
await migrator.down();
|
67
|
+
logger.info(`Link module "${serviceName}" migration executed`);
|
68
|
+
}
|
69
|
+
catch (error) {
|
70
|
+
logger.error(`Link module "${serviceName}" migration failed to run - Error: ${error}`);
|
71
|
+
}
|
72
|
+
await orm.close();
|
73
|
+
};
|
74
|
+
}
|
75
|
+
exports.getRevertMigration = getRevertMigration;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/link-modules",
|
3
|
-
"version": "0.2.12-preview-
|
3
|
+
"version": "0.2.12-preview-20240515175257",
|
4
4
|
"description": "Medusa Default Link Modules Package and Definitions",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -39,9 +39,9 @@
|
|
39
39
|
"typescript": "^5.1.6"
|
40
40
|
},
|
41
41
|
"dependencies": {
|
42
|
-
"@medusajs/modules-sdk": "1.13.0-preview-
|
43
|
-
"@medusajs/types": "1.12.0-preview-
|
44
|
-
"@medusajs/utils": "1.12.0-preview-
|
42
|
+
"@medusajs/modules-sdk": "1.13.0-preview-20240515175257",
|
43
|
+
"@medusajs/types": "1.12.0-preview-20240515175257",
|
44
|
+
"@medusajs/utils": "1.12.0-preview-20240515175257",
|
45
45
|
"@mikro-orm/core": "5.9.7",
|
46
46
|
"@mikro-orm/postgresql": "5.9.7",
|
47
47
|
"awilix": "^8.0.0"
|