@oliasoft-open-source/node-json-migrator 5.3.0 → 5.4.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/dist/index.d.mts +0 -4
- package/dist/index.mjs +21 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -111,10 +111,6 @@ declare const getPlannedVersion: ({
|
|
|
111
111
|
//#region src/migrate/migrate.d.ts
|
|
112
112
|
/**
|
|
113
113
|
* Migrates a payload
|
|
114
|
-
*
|
|
115
|
-
* There are two ways to use this function:
|
|
116
|
-
* i) function looks up the pending migrations for you (default)
|
|
117
|
-
* ii) pass in pre-fetched pending migrators via config.pending
|
|
118
114
|
*/
|
|
119
115
|
declare const migrate: ({
|
|
120
116
|
payload,
|
package/dist/index.mjs
CHANGED
|
@@ -4749,9 +4749,9 @@ const getPendingMigrations = ({ plannedMigrations, executedMigrations, printPend
|
|
|
4749
4749
|
migrator: m.migrator
|
|
4750
4750
|
}));
|
|
4751
4751
|
};
|
|
4752
|
-
const getPendingMigrators = async ({ config }) => {
|
|
4752
|
+
const getPendingMigrators = async ({ config, preparedPlan }) => {
|
|
4753
4753
|
const { directory, database, pgpHelpers, entity, version, printPendingFileNames, force } = config;
|
|
4754
|
-
const { plannedMigrations, nextVersion } = await PlanModule.getPlannedMigrations({ config });
|
|
4754
|
+
const { plannedMigrations, nextVersion } = preparedPlan ?? await PlanModule.getPlannedMigrations({ config });
|
|
4755
4755
|
const executedMigrations = database ? await getExecutedMigrationsFromVersion(database, pgpHelpers, entity, directory, version, nextVersion, plannedMigrations) : [];
|
|
4756
4756
|
return {
|
|
4757
4757
|
pendingMigrators: getPendingMigrations({
|
|
@@ -4767,13 +4767,19 @@ const getPendingMigrators = async ({ config }) => {
|
|
|
4767
4767
|
//#region src/migrate/migrate.ts
|
|
4768
4768
|
/**
|
|
4769
4769
|
* Migrates a payload
|
|
4770
|
-
*
|
|
4771
|
-
* There are two ways to use this function:
|
|
4772
|
-
* i) function looks up the pending migrations for you (default)
|
|
4773
|
-
* ii) pass in pre-fetched pending migrators via config.pending
|
|
4774
4770
|
*/
|
|
4775
4771
|
const migrate = async ({ payload, config, metaData }) => {
|
|
4776
|
-
|
|
4772
|
+
return migrateWithPlan({
|
|
4773
|
+
payload,
|
|
4774
|
+
config,
|
|
4775
|
+
metaData
|
|
4776
|
+
});
|
|
4777
|
+
};
|
|
4778
|
+
const migrateWithPlan = async ({ payload, config, metaData, preparedPlan }) => {
|
|
4779
|
+
const { pendingMigrators, nextVersion } = await getPendingMigrators({
|
|
4780
|
+
config,
|
|
4781
|
+
preparedPlan
|
|
4782
|
+
});
|
|
4777
4783
|
return {
|
|
4778
4784
|
nextPayload: pendingMigrators.length ? PipeModule.pipe(pendingMigrators, payload, metaData) : payload,
|
|
4779
4785
|
nextVersion
|
|
@@ -4785,7 +4791,7 @@ const MAX_ATTEMPTS = 3;
|
|
|
4785
4791
|
/**
|
|
4786
4792
|
* Migrate an entity record in the database
|
|
4787
4793
|
*/
|
|
4788
|
-
const migrateRecord = async ({ record, config, beforeMigrateRecord, afterMigrateRecord }) => {
|
|
4794
|
+
const migrateRecord = async ({ record, config, preparedPlan, beforeMigrateRecord, afterMigrateRecord }) => {
|
|
4789
4795
|
const { dry } = config;
|
|
4790
4796
|
console.log(chalk.gray(` ${record.name}`));
|
|
4791
4797
|
try {
|
|
@@ -4797,8 +4803,9 @@ const migrateRecord = async ({ record, config, beforeMigrateRecord, afterMigrate
|
|
|
4797
4803
|
transaction,
|
|
4798
4804
|
dry
|
|
4799
4805
|
});
|
|
4800
|
-
const { nextPayload: nextData, nextVersion } = await
|
|
4806
|
+
const { nextPayload: nextData, nextVersion } = await migrateWithPlan({
|
|
4801
4807
|
payload,
|
|
4808
|
+
preparedPlan,
|
|
4802
4809
|
config: {
|
|
4803
4810
|
...config,
|
|
4804
4811
|
version: currentVersion,
|
|
@@ -4830,7 +4837,7 @@ const migrateRecord = async ({ record, config, beforeMigrateRecord, afterMigrate
|
|
|
4830
4837
|
return migrationErrorPayload;
|
|
4831
4838
|
}
|
|
4832
4839
|
};
|
|
4833
|
-
const migrateRecords = async ({ recordList, config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4840
|
+
const migrateRecords = async ({ recordList, config, preparedPlan, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4834
4841
|
const { dry } = config;
|
|
4835
4842
|
const migrationErrors = [];
|
|
4836
4843
|
if (recordList.length) {
|
|
@@ -4843,6 +4850,7 @@ const migrateRecords = async ({ recordList, config, beforeMigrateRecord, afterMi
|
|
|
4843
4850
|
const migrationErrorPayload = await migrateRecord({
|
|
4844
4851
|
record,
|
|
4845
4852
|
config,
|
|
4853
|
+
preparedPlan,
|
|
4846
4854
|
beforeMigrateRecord,
|
|
4847
4855
|
afterMigrateRecord
|
|
4848
4856
|
});
|
|
@@ -4867,9 +4875,11 @@ const migrateRecords = async ({ recordList, config, beforeMigrateRecord, afterMi
|
|
|
4867
4875
|
* Migrate all records (only use via command line interface)
|
|
4868
4876
|
*/
|
|
4869
4877
|
const migrateAll = async ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4870
|
-
const
|
|
4878
|
+
const preparedPlan = await PlanModule.getPlannedMigrations({ config });
|
|
4879
|
+
const { validatedPlan: latestPlan, nextVersion: latestVersion } = preparedPlan;
|
|
4871
4880
|
await migrateRecords({
|
|
4872
4881
|
config,
|
|
4882
|
+
preparedPlan,
|
|
4873
4883
|
recordList: await getRecordList(config?.database, config?.entity, config?.entityTableName, config?.entityColumnNames, latestVersion, latestPlan),
|
|
4874
4884
|
beforeMigrateRecord,
|
|
4875
4885
|
afterMigrateRecord,
|