@contember/migrations-client 2.1.0-rc.3 → 2.2.0-alpha.10

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.
Files changed (137) hide show
  1. package/dist/development/index.cjs +4 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +4 -0
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/JsLoader.cjs.map +1 -1
  6. package/dist/development/src/JsLoader.js.map +1 -1
  7. package/dist/development/src/JsonLoader.cjs.map +1 -1
  8. package/dist/development/src/JsonLoader.js.map +1 -1
  9. package/dist/development/src/MigrationCreator.cjs +3 -3
  10. package/dist/development/src/MigrationCreator.cjs.map +1 -1
  11. package/dist/development/src/MigrationCreator.js +3 -3
  12. package/dist/development/src/MigrationCreator.js.map +1 -1
  13. package/dist/development/src/MigrationExecuteHelper.cjs +14 -5
  14. package/dist/development/src/MigrationExecuteHelper.cjs.map +1 -1
  15. package/dist/development/src/MigrationExecuteHelper.js +14 -5
  16. package/dist/development/src/MigrationExecuteHelper.js.map +1 -1
  17. package/dist/development/src/MigrationFile.cjs.map +1 -1
  18. package/dist/development/src/MigrationFile.js.map +1 -1
  19. package/dist/development/src/MigrationFilesManager.cjs +11 -11
  20. package/dist/development/src/MigrationFilesManager.cjs.map +1 -1
  21. package/dist/development/src/MigrationFilesManager.js.map +1 -1
  22. package/dist/development/src/MigrationParser.cjs.map +1 -1
  23. package/dist/development/src/MigrationParser.js.map +1 -1
  24. package/dist/development/src/MigrationsResolver.cjs.map +1 -1
  25. package/dist/development/src/MigrationsResolver.js.map +1 -1
  26. package/dist/development/src/SchemaStateManager.cjs +82 -0
  27. package/dist/development/src/SchemaStateManager.cjs.map +1 -0
  28. package/dist/development/src/SchemaStateManager.js +64 -0
  29. package/dist/development/src/SchemaStateManager.js.map +1 -0
  30. package/dist/development/src/SchemaVersionBuilder.cjs +28 -4
  31. package/dist/development/src/SchemaVersionBuilder.cjs.map +1 -1
  32. package/dist/development/src/SchemaVersionBuilder.js +28 -4
  33. package/dist/development/src/SchemaVersionBuilder.js.map +1 -1
  34. package/dist/development/src/SnapshotManager.cjs +46 -0
  35. package/dist/development/src/SnapshotManager.cjs.map +1 -0
  36. package/dist/development/src/SnapshotManager.js +29 -0
  37. package/dist/development/src/SnapshotManager.js.map +1 -0
  38. package/dist/development/src/SystemClient.cjs +29 -4
  39. package/dist/development/src/SystemClient.cjs.map +1 -1
  40. package/dist/development/src/SystemClient.js +29 -4
  41. package/dist/development/src/SystemClient.js.map +1 -1
  42. package/dist/development/src/migrations.cjs.map +1 -1
  43. package/dist/development/src/migrations.js.map +1 -1
  44. package/dist/production/index.cjs +4 -0
  45. package/dist/production/index.cjs.map +1 -1
  46. package/dist/production/index.js +4 -0
  47. package/dist/production/index.js.map +1 -1
  48. package/dist/production/src/JsLoader.cjs.map +1 -1
  49. package/dist/production/src/JsLoader.js.map +1 -1
  50. package/dist/production/src/JsonLoader.cjs.map +1 -1
  51. package/dist/production/src/JsonLoader.js.map +1 -1
  52. package/dist/production/src/MigrationCreator.cjs +3 -3
  53. package/dist/production/src/MigrationCreator.cjs.map +1 -1
  54. package/dist/production/src/MigrationCreator.js +3 -3
  55. package/dist/production/src/MigrationCreator.js.map +1 -1
  56. package/dist/production/src/MigrationExecuteHelper.cjs +14 -5
  57. package/dist/production/src/MigrationExecuteHelper.cjs.map +1 -1
  58. package/dist/production/src/MigrationExecuteHelper.js +14 -5
  59. package/dist/production/src/MigrationExecuteHelper.js.map +1 -1
  60. package/dist/production/src/MigrationFile.cjs.map +1 -1
  61. package/dist/production/src/MigrationFile.js.map +1 -1
  62. package/dist/production/src/MigrationFilesManager.cjs +11 -11
  63. package/dist/production/src/MigrationFilesManager.cjs.map +1 -1
  64. package/dist/production/src/MigrationFilesManager.js.map +1 -1
  65. package/dist/production/src/MigrationParser.cjs.map +1 -1
  66. package/dist/production/src/MigrationParser.js.map +1 -1
  67. package/dist/production/src/MigrationsResolver.cjs.map +1 -1
  68. package/dist/production/src/MigrationsResolver.js.map +1 -1
  69. package/dist/production/src/SchemaStateManager.cjs +82 -0
  70. package/dist/production/src/SchemaStateManager.cjs.map +1 -0
  71. package/dist/production/src/SchemaStateManager.js +64 -0
  72. package/dist/production/src/SchemaStateManager.js.map +1 -0
  73. package/dist/production/src/SchemaVersionBuilder.cjs +28 -4
  74. package/dist/production/src/SchemaVersionBuilder.cjs.map +1 -1
  75. package/dist/production/src/SchemaVersionBuilder.js +28 -4
  76. package/dist/production/src/SchemaVersionBuilder.js.map +1 -1
  77. package/dist/production/src/SnapshotManager.cjs +46 -0
  78. package/dist/production/src/SnapshotManager.cjs.map +1 -0
  79. package/dist/production/src/SnapshotManager.js +29 -0
  80. package/dist/production/src/SnapshotManager.js.map +1 -0
  81. package/dist/production/src/SystemClient.cjs +29 -4
  82. package/dist/production/src/SystemClient.cjs.map +1 -1
  83. package/dist/production/src/SystemClient.js +29 -4
  84. package/dist/production/src/SystemClient.js.map +1 -1
  85. package/dist/production/src/migrations.cjs.map +1 -1
  86. package/dist/production/src/migrations.js.map +1 -1
  87. package/dist/types/JsLoader.d.ts +3 -3
  88. package/dist/types/JsLoader.d.ts.map +1 -1
  89. package/dist/types/JsonLoader.d.ts +4 -4
  90. package/dist/types/JsonLoader.d.ts.map +1 -1
  91. package/dist/types/MigrationCreator.d.ts +4 -2
  92. package/dist/types/MigrationCreator.d.ts.map +1 -1
  93. package/dist/types/MigrationExecuteHelper.d.ts +6 -4
  94. package/dist/types/MigrationExecuteHelper.d.ts.map +1 -1
  95. package/dist/types/MigrationFile.d.ts +2 -2
  96. package/dist/types/MigrationFile.d.ts.map +1 -1
  97. package/dist/types/MigrationFileLoader.d.ts +1 -1
  98. package/dist/types/MigrationFileLoader.d.ts.map +1 -1
  99. package/dist/types/MigrationFilesManager.d.ts +2 -2
  100. package/dist/types/MigrationFilesManager.d.ts.map +1 -1
  101. package/dist/types/MigrationParser.d.ts +2 -2
  102. package/dist/types/MigrationParser.d.ts.map +1 -1
  103. package/dist/types/MigrationsResolver.d.ts +2 -2
  104. package/dist/types/MigrationsResolver.d.ts.map +1 -1
  105. package/dist/types/SchemaStateManager.d.ts +19 -0
  106. package/dist/types/SchemaStateManager.d.ts.map +1 -0
  107. package/dist/types/SchemaVersionBuilder.d.ts +10 -2
  108. package/dist/types/SchemaVersionBuilder.d.ts.map +1 -1
  109. package/dist/types/SnapshotManager.d.ts +31 -0
  110. package/dist/types/SnapshotManager.d.ts.map +1 -0
  111. package/dist/types/SystemClient.d.ts +11 -3
  112. package/dist/types/SystemClient.d.ts.map +1 -1
  113. package/dist/types/index.d.ts +14 -12
  114. package/dist/types/index.d.ts.map +1 -1
  115. package/dist/types/migrations.d.ts +1 -1
  116. package/dist/types/migrations.d.ts.map +1 -1
  117. package/dist/types/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +6 -6
  119. package/src/JsLoader.ts +3 -3
  120. package/src/JsonLoader.ts +3 -3
  121. package/src/MigrationCreator.ts +8 -5
  122. package/src/MigrationExecuteHelper.ts +19 -8
  123. package/src/MigrationFile.ts +2 -2
  124. package/src/MigrationFileLoader.ts +1 -1
  125. package/src/MigrationFilesManager.ts +2 -2
  126. package/src/MigrationParser.ts +2 -2
  127. package/src/MigrationsResolver.ts +2 -2
  128. package/src/SchemaStateManager.ts +75 -0
  129. package/src/SchemaVersionBuilder.ts +35 -10
  130. package/src/SnapshotManager.ts +52 -0
  131. package/src/SystemClient.ts +41 -4
  132. package/src/index.ts +14 -12
  133. package/src/migrations.ts +1 -1
  134. package/tests/cases/unit/MigrationCreator.test.ts +50 -0
  135. package/tests/cases/unit/SchemaStateManager.test.ts +96 -0
  136. package/tests/cases/unit/SchemaVersionBuilder.test.ts +125 -0
  137. package/tests/cases/unit/SnapshotManager.test.ts +64 -0
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.cjs","sources":["../../../../packages/migrations-client/src/migrations.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationInfo } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile'\n\nexport interface ExecutedMigrationInfo extends MigrationInfo {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport interface ExecutedMigration extends Migration {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport enum MigrationState {\n\tTO_EXECUTE_OK = 'to_execute_ok',\n\tTO_EXECUTE_ERROR = 'to_execute_error',\n\tSKIP_EMPTY = 'skip_empty',\n\tEXECUTED_OK = 'executed_ok',\n\tEXECUTED_ERROR = 'executed_error',\n\tEXECUTED_MISSING = 'executed_missing',\n}\n\nexport interface MigrationStatusBase<S extends MigrationState> {\n\tstate: S\n\tversion: string\n\tname: string\n}\n\nexport interface MigrationToExecuteOkStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_OK> {\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationToExecuteInvalidStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_ERROR> {\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\ninterface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING> {\n\texecutedMigration: ExecutedMigrationInfo\n\terrorMessage: string\n}\n\ninterface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\nexport interface MigrationSkipStatus extends MigrationStatusBase<MigrationState.SKIP_EMPTY> {\n\tlocalMigration: MigrationFile\n}\n\nexport type ErrorMigrationStatus =\n\t| MigrationToExecuteInvalidStatus\n\t| MigrationExecutedMissingStatus\n\t| MigrationExecutedErrorStatus\n\nexport type AnyMigrationStatus =\n\t| ErrorMigrationStatus\n\t| MigrationToExecuteOkStatus\n\t| MigrationExecutedOkStatus\n\t| MigrationSkipStatus\n\nconst isErrorMigrationStatus = (migration: AnyMigrationStatus): migration is ErrorMigrationStatus =>\n\t[MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(\n\t\tmigration.state,\n\t)\n\nexport const sortMigrations = <M extends { version: string }>(migrations: M[]): M[] => {\n\treturn [...migrations].sort((a, b) => a.version.localeCompare(b.version))\n}\n\nexport class MigrationsStatusResolver {\n\tasync getMigrationsStatus(\n\t\texecutedMigrations: ExecutedMigrationInfo[],\n\t\tlocalMigrations: MigrationFile[],\n\t\tforce: boolean = false,\n\t): Promise<{\n\t\tallMigrations: AnyMigrationStatus[]\n\t\terrorMigrations: ErrorMigrationStatus[]\n\t\tmigrationsToExecute: MigrationToExecuteOkStatus[]\n\t}> {\n\t\tconst sortedExecuted = sortMigrations(executedMigrations)\n\n\t\tconst allMigrations: AnyMigrationStatus[] = []\n\t\tfor (const executed of sortedExecuted) {\n\t\t\tconst localMigration = localMigrations.find(it => it.version === executed.version)\n\t\t\tif (!localMigration) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_MISSING,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\terrorMessage: `Migration ${executed.name} is missing locally`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\n\t\t\tconst localChecksum = !isSchemaMigration(migrationContent) ? null : calculateMigrationChecksum(migrationContent)\n\n\t\t\tif (localChecksum !== executed.checksum) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_ERROR,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\terrorMessage: `Checksum of executed migration \"${executed.checksum}\" does not match \"${localChecksum}\"`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.EXECUTED_OK,\n\t\t\t\texecutedMigration: executed,\n\t\t\t\tversion: executed.version,\n\t\t\t\tname: executed.name,\n\t\t\t\tlocalMigration,\n\t\t\t})\n\t\t}\n\n\t\tconst latestExecuted = sortedExecuted.length > 0 ? sortedExecuted[sortedExecuted.length - 1] : null\n\t\tfor (const localMigration of localMigrations) {\n\t\t\tif (allMigrations.find(it => it.version === localMigration.version)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\t\t\tif (isSchemaMigration(migrationContent) && migrationContent.modifications.length === 0) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.SKIP_EMPTY,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (latestExecuted && latestExecuted.version > localMigration.version) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.TO_EXECUTE_ERROR,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t\terrorMessage: `Must follow latest executed migration ${latestExecuted.name}`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.TO_EXECUTE_OK,\n\t\t\t\tlocalMigration,\n\t\t\t\tversion: localMigration.version,\n\t\t\t\tname: localMigration.name,\n\t\t\t})\n\t\t}\n\t\tconst allMigrationsSorted = sortMigrations(allMigrations)\n\n\t\treturn {\n\t\t\tallMigrations: allMigrationsSorted,\n\t\t\terrorMigrations: allMigrationsSorted.filter(isErrorMigrationStatus),\n\t\t\tmigrationsToExecute: allMigrationsSorted.filter(\n\t\t\t\t(it): it is MigrationToExecuteOkStatus => it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR),\n\t\t\t),\n\t\t}\n\t}\n}\n"],"names":["MigrationState","isSchemaMigration","calculateMigrationChecksum"],"mappings":";;;;AAaO,IAAK,mCAAAA,oBAAL;AACNA,kBAAA,eAAA,IAAgB;AAChBA,kBAAA,kBAAA,IAAmB;AACnBA,kBAAA,YAAA,IAAa;AACbA,kBAAA,aAAA,IAAc;AACdA,kBAAA,gBAAA,IAAiB;AACjBA,kBAAA,kBAAA,IAAmB;AANR,SAAAA;AAAA,GAAA,kBAAA,CAAA,CAAA;AAuDZ,MAAM,yBAAyB,CAAC,cAC/B;AAAA,EAAC;AAAA,EAA+B;AAAA,EAAiC;AAAA;EAAiC;AAAA,EACjG,UAAU;AACX;AAEM,MAAM,iBAAiB,CAAgC,eAAyB;AACtF,SAAO,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,CAAC;AACzE;AAEO,MAAM,yBAAyB;AAAA,EACrC,MAAM,oBACL,oBACA,iBACA,QAAiB,OAKf;AACF,UAAM,iBAAiB,eAAe,kBAAkB;AAExD,UAAM,gBAAsC,CAAA;AAC5C,eAAW,YAAY,gBAAgB;AACtC,YAAM,iBAAiB,gBAAgB,KAAK,QAAM,GAAG,YAAY,SAAS,OAAO;AACjF,UAAI,CAAC,gBAAgB;AACpB,sBAAc,KAAK;AAAA,UAClB,OAAO;AAAA,UACP,mBAAmB;AAAA,UACnB,SAAS,SAAS;AAAA,UAClB,MAAM,SAAS;AAAA,UACf,cAAc,aAAa,SAAS,IAAI;AAAA,QAAA,CACxC;AACD;AAAA,MACD;AACA,YAAM,mBAAmB,MAAM,eAAe,WAAA;AAE9C,YAAM,gBAAgB,CAACC,gCAAkB,gBAAgB,IAAI,OAAOC,iBAAAA,2BAA2B,gBAAgB;AAE/G,UAAI,kBAAkB,SAAS,UAAU;AACxC,sB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,CAAC,OAAyC,GAAG,UAAU,mBAAiC,SAAS,GAAG,UAAU;AAAA;AAAA,MAAA;AAAA,IAC/G;AAAA,EAEF;AACD;;;;"}
1
+ {"version":3,"file":"migrations.cjs","sources":["../../../../packages/migrations-client/src/migrations.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationInfo } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile.js'\n\nexport interface ExecutedMigrationInfo extends MigrationInfo {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport interface ExecutedMigration extends Migration {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport enum MigrationState {\n\tTO_EXECUTE_OK = 'to_execute_ok',\n\tTO_EXECUTE_ERROR = 'to_execute_error',\n\tSKIP_EMPTY = 'skip_empty',\n\tEXECUTED_OK = 'executed_ok',\n\tEXECUTED_ERROR = 'executed_error',\n\tEXECUTED_MISSING = 'executed_missing',\n}\n\nexport interface MigrationStatusBase<S extends MigrationState> {\n\tstate: S\n\tversion: string\n\tname: string\n}\n\nexport interface MigrationToExecuteOkStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_OK> {\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationToExecuteInvalidStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_ERROR> {\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\ninterface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING> {\n\texecutedMigration: ExecutedMigrationInfo\n\terrorMessage: string\n}\n\ninterface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\nexport interface MigrationSkipStatus extends MigrationStatusBase<MigrationState.SKIP_EMPTY> {\n\tlocalMigration: MigrationFile\n}\n\nexport type ErrorMigrationStatus =\n\t| MigrationToExecuteInvalidStatus\n\t| MigrationExecutedMissingStatus\n\t| MigrationExecutedErrorStatus\n\nexport type AnyMigrationStatus =\n\t| ErrorMigrationStatus\n\t| MigrationToExecuteOkStatus\n\t| MigrationExecutedOkStatus\n\t| MigrationSkipStatus\n\nconst isErrorMigrationStatus = (migration: AnyMigrationStatus): migration is ErrorMigrationStatus =>\n\t[MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(\n\t\tmigration.state,\n\t)\n\nexport const sortMigrations = <M extends { version: string }>(migrations: M[]): M[] => {\n\treturn [...migrations].sort((a, b) => a.version.localeCompare(b.version))\n}\n\nexport class MigrationsStatusResolver {\n\tasync getMigrationsStatus(\n\t\texecutedMigrations: ExecutedMigrationInfo[],\n\t\tlocalMigrations: MigrationFile[],\n\t\tforce: boolean = false,\n\t): Promise<{\n\t\tallMigrations: AnyMigrationStatus[]\n\t\terrorMigrations: ErrorMigrationStatus[]\n\t\tmigrationsToExecute: MigrationToExecuteOkStatus[]\n\t}> {\n\t\tconst sortedExecuted = sortMigrations(executedMigrations)\n\n\t\tconst allMigrations: AnyMigrationStatus[] = []\n\t\tfor (const executed of sortedExecuted) {\n\t\t\tconst localMigration = localMigrations.find(it => it.version === executed.version)\n\t\t\tif (!localMigration) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_MISSING,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\terrorMessage: `Migration ${executed.name} is missing locally`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\n\t\t\tconst localChecksum = !isSchemaMigration(migrationContent) ? null : calculateMigrationChecksum(migrationContent)\n\n\t\t\tif (localChecksum !== executed.checksum) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_ERROR,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\terrorMessage: `Checksum of executed migration \"${executed.checksum}\" does not match \"${localChecksum}\"`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.EXECUTED_OK,\n\t\t\t\texecutedMigration: executed,\n\t\t\t\tversion: executed.version,\n\t\t\t\tname: executed.name,\n\t\t\t\tlocalMigration,\n\t\t\t})\n\t\t}\n\n\t\tconst latestExecuted = sortedExecuted.length > 0 ? sortedExecuted[sortedExecuted.length - 1] : null\n\t\tfor (const localMigration of localMigrations) {\n\t\t\tif (allMigrations.find(it => it.version === localMigration.version)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\t\t\tif (isSchemaMigration(migrationContent) && migrationContent.modifications.length === 0) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.SKIP_EMPTY,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (latestExecuted && latestExecuted.version > localMigration.version) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.TO_EXECUTE_ERROR,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t\terrorMessage: `Must follow latest executed migration ${latestExecuted.name}`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.TO_EXECUTE_OK,\n\t\t\t\tlocalMigration,\n\t\t\t\tversion: localMigration.version,\n\t\t\t\tname: localMigration.name,\n\t\t\t})\n\t\t}\n\t\tconst allMigrationsSorted = sortMigrations(allMigrations)\n\n\t\treturn {\n\t\t\tallMigrations: allMigrationsSorted,\n\t\t\terrorMigrations: allMigrationsSorted.filter(isErrorMigrationStatus),\n\t\t\tmigrationsToExecute: allMigrationsSorted.filter(\n\t\t\t\t(it): it is MigrationToExecuteOkStatus => it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR),\n\t\t\t),\n\t\t}\n\t}\n}\n"],"names":["MigrationState","isSchemaMigration","calculateMigrationChecksum"],"mappings":";;;;AAaO,IAAK,mCAAAA,oBAAL;AACNA,kBAAA,eAAA,IAAgB;AAChBA,kBAAA,kBAAA,IAAmB;AACnBA,kBAAA,YAAA,IAAa;AACbA,kBAAA,aAAA,IAAc;AACdA,kBAAA,gBAAA,IAAiB;AACjBA,kBAAA,kBAAA,IAAmB;AANR,SAAAA;AAAA,GAAA,kBAAA,CAAA,CAAA;AAuDZ,MAAM,yBAAyB,CAAC,cAC/B;AAAA,EAAC;AAAA,EAA+B;AAAA,EAAiC;AAAA;EAAiC;AAAA,EACjG,UAAU;AACX;AAEM,MAAM,iBAAiB,CAAgC,eAAyB;AACtF,SAAO,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,CAAC;AACzE;AAEO,MAAM,yBAAyB;AAAA,EACrC,MAAM,oBACL,oBACA,iBACA,QAAiB,OAKf;AACF,UAAM,iBAAiB,eAAe,kBAAkB;AAExD,UAAM,gBAAsC,CAAA;AAC5C,eAAW,YAAY,gBAAgB;AACtC,YAAM,iBAAiB,gBAAgB,KAAK,QAAM,GAAG,YAAY,SAAS,OAAO;AACjF,UAAI,CAAC,gBAAgB;AACpB,sBAAc,KAAK;AAAA,UAClB,OAAO;AAAA,UACP,mBAAmB;AAAA,UACnB,SAAS,SAAS;AAAA,UAClB,MAAM,SAAS;AAAA,UAC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QACP;AAAA,QACA,SAAS,eAAe;AAAA,QACxB,MAAM,eAAe;AAAA,MAAA,CACrB;AAAA,IACF;AACA,UAAM,sBAAsB,eAAe,aAAa;AAExD,WAAO;AAAA,MACN,eAAe;AAAA,MACf,iBAAiB,oBAAoB,OAAO,sBAAsB;AAAA,MAClE,qBAAqB,oBAAoB;AAAA,QACxC,CAAC,OAAyC,GAAG,UAAU,mBAAiC,SAAS,GAAG,UAAU;AAAA;AAAA,MAAA;AAAA,IAC/G;AAAA,EAEF;AACD;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.js","sources":["../../../../packages/migrations-client/src/migrations.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationInfo } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile'\n\nexport interface ExecutedMigrationInfo extends MigrationInfo {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport interface ExecutedMigration extends Migration {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport enum MigrationState {\n\tTO_EXECUTE_OK = 'to_execute_ok',\n\tTO_EXECUTE_ERROR = 'to_execute_error',\n\tSKIP_EMPTY = 'skip_empty',\n\tEXECUTED_OK = 'executed_ok',\n\tEXECUTED_ERROR = 'executed_error',\n\tEXECUTED_MISSING = 'executed_missing',\n}\n\nexport interface MigrationStatusBase<S extends MigrationState> {\n\tstate: S\n\tversion: string\n\tname: string\n}\n\nexport interface MigrationToExecuteOkStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_OK> {\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationToExecuteInvalidStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_ERROR> {\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\ninterface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING> {\n\texecutedMigration: ExecutedMigrationInfo\n\terrorMessage: string\n}\n\ninterface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\nexport interface MigrationSkipStatus extends MigrationStatusBase<MigrationState.SKIP_EMPTY> {\n\tlocalMigration: MigrationFile\n}\n\nexport type ErrorMigrationStatus =\n\t| MigrationToExecuteInvalidStatus\n\t| MigrationExecutedMissingStatus\n\t| MigrationExecutedErrorStatus\n\nexport type AnyMigrationStatus =\n\t| ErrorMigrationStatus\n\t| MigrationToExecuteOkStatus\n\t| MigrationExecutedOkStatus\n\t| MigrationSkipStatus\n\nconst isErrorMigrationStatus = (migration: AnyMigrationStatus): migration is ErrorMigrationStatus =>\n\t[MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(\n\t\tmigration.state,\n\t)\n\nexport const sortMigrations = <M extends { version: string }>(migrations: M[]): M[] => {\n\treturn [...migrations].sort((a, b) => a.version.localeCompare(b.version))\n}\n\nexport class MigrationsStatusResolver {\n\tasync getMigrationsStatus(\n\t\texecutedMigrations: ExecutedMigrationInfo[],\n\t\tlocalMigrations: MigrationFile[],\n\t\tforce: boolean = false,\n\t): Promise<{\n\t\tallMigrations: AnyMigrationStatus[]\n\t\terrorMigrations: ErrorMigrationStatus[]\n\t\tmigrationsToExecute: MigrationToExecuteOkStatus[]\n\t}> {\n\t\tconst sortedExecuted = sortMigrations(executedMigrations)\n\n\t\tconst allMigrations: AnyMigrationStatus[] = []\n\t\tfor (const executed of sortedExecuted) {\n\t\t\tconst localMigration = localMigrations.find(it => it.version === executed.version)\n\t\t\tif (!localMigration) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_MISSING,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\terrorMessage: `Migration ${executed.name} is missing locally`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\n\t\t\tconst localChecksum = !isSchemaMigration(migrationContent) ? null : calculateMigrationChecksum(migrationContent)\n\n\t\t\tif (localChecksum !== executed.checksum) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_ERROR,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\terrorMessage: `Checksum of executed migration \"${executed.checksum}\" does not match \"${localChecksum}\"`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.EXECUTED_OK,\n\t\t\t\texecutedMigration: executed,\n\t\t\t\tversion: executed.version,\n\t\t\t\tname: executed.name,\n\t\t\t\tlocalMigration,\n\t\t\t})\n\t\t}\n\n\t\tconst latestExecuted = sortedExecuted.length > 0 ? sortedExecuted[sortedExecuted.length - 1] : null\n\t\tfor (const localMigration of localMigrations) {\n\t\t\tif (allMigrations.find(it => it.version === localMigration.version)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\t\t\tif (isSchemaMigration(migrationContent) && migrationContent.modifications.length === 0) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.SKIP_EMPTY,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (latestExecuted && latestExecuted.version > localMigration.version) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.TO_EXECUTE_ERROR,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t\terrorMessage: `Must follow latest executed migration ${latestExecuted.name}`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.TO_EXECUTE_OK,\n\t\t\t\tlocalMigration,\n\t\t\t\tversion: localMigration.version,\n\t\t\t\tname: localMigration.name,\n\t\t\t})\n\t\t}\n\t\tconst allMigrationsSorted = sortMigrations(allMigrations)\n\n\t\treturn {\n\t\t\tallMigrations: allMigrationsSorted,\n\t\t\terrorMigrations: allMigrationsSorted.filter(isErrorMigrationStatus),\n\t\t\tmigrationsToExecute: allMigrationsSorted.filter(\n\t\t\t\t(it): it is MigrationToExecuteOkStatus => it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR),\n\t\t\t),\n\t\t}\n\t}\n}\n"],"names":["MigrationState"],"mappings":";;AAaO,IAAK,mCAAAA,oBAAL;AACNA,kBAAA,eAAA,IAAgB;AAChBA,kBAAA,kBAAA,IAAmB;AACnBA,kBAAA,YAAA,IAAa;AACbA,kBAAA,aAAA,IAAc;AACdA,kBAAA,gBAAA,IAAiB;AACjBA,kBAAA,kBAAA,IAAmB;AANR,SAAAA;AAAA,GAAA,kBAAA,CAAA,CAAA;AAuDZ,MAAM,yBAAyB,CAAC,cAC/B;AAAA,EAAC;AAAA,EAA+B;AAAA,EAAiC;AAAA;EAAiC;AAAA,EACjG,UAAU;AACX;AAEM,MAAM,iBAAiB,CAAgC,eAAyB;AACtF,SAAO,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,CAAC;AACzE;AAEO,MAAM,yBAAyB;AAAA,EACrC,MAAM,oBACL,oBACA,iBACA,QAAiB,OAKf;AACF,UAAM,iBAAiB,eAAe,kBAAkB;AAExD,UAAM,gBAAsC,CAAA;AAC5C,eAAW,YAAY,gBAAgB;A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,UAClB,OAAO;AAAA,UACP;AAAA,UACA,SAAS,eAAe;AAAA,UACxB,MAAM,eAAe;AAAA,UACrB,cAAc,yCAAyC,eAAe,IAAI;AAAA,QAAA,CAC1E;AACD;AAAA,MACD;AACA,oBAAc,KAAK;AAAA,QAClB,OAAO;AAAA,QACP;AAAA,QACA,SAAS,eAAe;AAAA,QACxB,MAAM,eAAe;AAAA,MAAA,CACrB;AAAA,IACF;AACA,UAAM,sBAAsB,eAAe,aAAa;AAExD,WAAO;AAAA,MACN,eAAe;AAAA,MACf,iBAAiB,oBAAoB,OAAO,sBAAsB;AAAA,MAClE,qBAAqB,oBAAoB;AAAA,QACxC,CAAC,OAAyC,GAAG,UAAU,mBAAiC,SAAS,GAAG,UAAU;AAAA;AAAA,MAAA;AAAA,IAC/G;AAAA,EAEF;AACD;"}
1
+ {"version":3,"file":"migrations.js","sources":["../../../../packages/migrations-client/src/migrations.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationInfo } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile.js'\n\nexport interface ExecutedMigrationInfo extends MigrationInfo {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport interface ExecutedMigration extends Migration {\n\treadonly executedAt: Date\n\treadonly checksum: string\n}\n\nexport enum MigrationState {\n\tTO_EXECUTE_OK = 'to_execute_ok',\n\tTO_EXECUTE_ERROR = 'to_execute_error',\n\tSKIP_EMPTY = 'skip_empty',\n\tEXECUTED_OK = 'executed_ok',\n\tEXECUTED_ERROR = 'executed_error',\n\tEXECUTED_MISSING = 'executed_missing',\n}\n\nexport interface MigrationStatusBase<S extends MigrationState> {\n\tstate: S\n\tversion: string\n\tname: string\n}\n\nexport interface MigrationToExecuteOkStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_OK> {\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationToExecuteInvalidStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_ERROR> {\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\ninterface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n}\n\ninterface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING> {\n\texecutedMigration: ExecutedMigrationInfo\n\terrorMessage: string\n}\n\ninterface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR> {\n\texecutedMigration: ExecutedMigrationInfo\n\tlocalMigration: MigrationFile\n\terrorMessage: string\n}\n\nexport interface MigrationSkipStatus extends MigrationStatusBase<MigrationState.SKIP_EMPTY> {\n\tlocalMigration: MigrationFile\n}\n\nexport type ErrorMigrationStatus =\n\t| MigrationToExecuteInvalidStatus\n\t| MigrationExecutedMissingStatus\n\t| MigrationExecutedErrorStatus\n\nexport type AnyMigrationStatus =\n\t| ErrorMigrationStatus\n\t| MigrationToExecuteOkStatus\n\t| MigrationExecutedOkStatus\n\t| MigrationSkipStatus\n\nconst isErrorMigrationStatus = (migration: AnyMigrationStatus): migration is ErrorMigrationStatus =>\n\t[MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(\n\t\tmigration.state,\n\t)\n\nexport const sortMigrations = <M extends { version: string }>(migrations: M[]): M[] => {\n\treturn [...migrations].sort((a, b) => a.version.localeCompare(b.version))\n}\n\nexport class MigrationsStatusResolver {\n\tasync getMigrationsStatus(\n\t\texecutedMigrations: ExecutedMigrationInfo[],\n\t\tlocalMigrations: MigrationFile[],\n\t\tforce: boolean = false,\n\t): Promise<{\n\t\tallMigrations: AnyMigrationStatus[]\n\t\terrorMigrations: ErrorMigrationStatus[]\n\t\tmigrationsToExecute: MigrationToExecuteOkStatus[]\n\t}> {\n\t\tconst sortedExecuted = sortMigrations(executedMigrations)\n\n\t\tconst allMigrations: AnyMigrationStatus[] = []\n\t\tfor (const executed of sortedExecuted) {\n\t\t\tconst localMigration = localMigrations.find(it => it.version === executed.version)\n\t\t\tif (!localMigration) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_MISSING,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\terrorMessage: `Migration ${executed.name} is missing locally`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\n\t\t\tconst localChecksum = !isSchemaMigration(migrationContent) ? null : calculateMigrationChecksum(migrationContent)\n\n\t\t\tif (localChecksum !== executed.checksum) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.EXECUTED_ERROR,\n\t\t\t\t\texecutedMigration: executed,\n\t\t\t\t\tversion: executed.version,\n\t\t\t\t\tname: executed.name,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\terrorMessage: `Checksum of executed migration \"${executed.checksum}\" does not match \"${localChecksum}\"`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.EXECUTED_OK,\n\t\t\t\texecutedMigration: executed,\n\t\t\t\tversion: executed.version,\n\t\t\t\tname: executed.name,\n\t\t\t\tlocalMigration,\n\t\t\t})\n\t\t}\n\n\t\tconst latestExecuted = sortedExecuted.length > 0 ? sortedExecuted[sortedExecuted.length - 1] : null\n\t\tfor (const localMigration of localMigrations) {\n\t\t\tif (allMigrations.find(it => it.version === localMigration.version)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst migrationContent = await localMigration.getContent()\n\t\t\tif (isSchemaMigration(migrationContent) && migrationContent.modifications.length === 0) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.SKIP_EMPTY,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (latestExecuted && latestExecuted.version > localMigration.version) {\n\t\t\t\tallMigrations.push({\n\t\t\t\t\tstate: MigrationState.TO_EXECUTE_ERROR,\n\t\t\t\t\tlocalMigration,\n\t\t\t\t\tversion: localMigration.version,\n\t\t\t\t\tname: localMigration.name,\n\t\t\t\t\terrorMessage: `Must follow latest executed migration ${latestExecuted.name}`,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tallMigrations.push({\n\t\t\t\tstate: MigrationState.TO_EXECUTE_OK,\n\t\t\t\tlocalMigration,\n\t\t\t\tversion: localMigration.version,\n\t\t\t\tname: localMigration.name,\n\t\t\t})\n\t\t}\n\t\tconst allMigrationsSorted = sortMigrations(allMigrations)\n\n\t\treturn {\n\t\t\tallMigrations: allMigrationsSorted,\n\t\t\terrorMigrations: allMigrationsSorted.filter(isErrorMigrationStatus),\n\t\t\tmigrationsToExecute: allMigrationsSorted.filter(\n\t\t\t\t(it): it is MigrationToExecuteOkStatus => it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR),\n\t\t\t),\n\t\t}\n\t}\n}\n"],"names":["MigrationState"],"mappings":";;AAaO,IAAK,mCAAAA,oBAAL;AACNA,kBAAA,eAAA,IAAgB;AAChBA,kBAAA,kBAAA,IAAmB;AACnBA,kBAAA,YAAA,IAAa;AACbA,kBAAA,aAAA,IAAc;AACdA,kBAAA,gBAAA,IAAiB;AACjBA,kBAAA,kBAAA,IAAmB;AANR,SAAAA;AAAA,GAAA,kBAAA,CAAA,CAAA;AAuDZ,MAAM,yBAAyB,CAAC,cAC/B;AAAA,EAAC;AAAA,EAA+B;AAAA,EAAiC;AAAA;EAAiC;AAAA,EACjG,UAAU;AACX;AAEM,MAAM,iBAAiB,CAAgC,eAAyB;AACtF,SAAO,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO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UAClB,OAAO;AAAA,UACP;AAAA,UACA,SAAS,eAAe;AAAA,UACxB,MAAM,eAAe;AAAA,QAAA,CACrB;AACD;AAAA,MACD;AAEA,UAAI,kBAAkB,eAAe,UAAU,eAAe,SAAS;AACtE,sBAAc,KAAK;AAAA,UAClB,OAAO;AAAA,UACP;AAAA,UACA,SAAS,eAAe;AAAA,UACxB,MAAM,eAAe;AAAA,UACrB,cAAc,yCAAyC,eAAe,IAAI;AAAA,QAAA,CAC1E;AACD;AAAA,MACD;AACA,oBAAc,KAAK;AAAA,QAClB,OAAO;AAAA,QACP;AAAA,QACA,SAAS,eAAe;AAAA,QACxB,MAAM,eAAe;AAAA,MAAA,CACrB;AAAA,IACF;AACA,UAAM,sBAAsB,eAAe,aAAa;AAExD,WAAO;AAAA,MACN,eAAe;AAAA,MACf,iBAAiB,oBAAoB,OAAO,sBAAsB;AAAA,MAClE,qBAAqB,oBAAoB;AAAA,QACxC,CAAC,OAAyC,GAAG,UAAU,mBAAiC,SAAS,GAAG,UAAU;AAAA;AAAA,MAAA;AAAA,IAC/G;AAAA,EAEF;AACD;"}
@@ -10,7 +10,9 @@ const MigrationFilesManager = require("./src/MigrationFilesManager.cjs");
10
10
  const MigrationParser = require("./src/MigrationParser.cjs");
11
11
  const migrations = require("./src/migrations.cjs");
12
12
  const MigrationsResolver = require("./src/MigrationsResolver.cjs");
13
+ const SchemaStateManager = require("./src/SchemaStateManager.cjs");
13
14
  const SchemaVersionBuilder = require("./src/SchemaVersionBuilder.cjs");
15
+ const SnapshotManager = require("./src/SnapshotManager.cjs");
14
16
  const SystemClient = require("./src/SystemClient.cjs");
15
17
  Object.defineProperty(exports, "MigrationDescriber", {
16
18
  enumerable: true,
@@ -47,7 +49,9 @@ exports.MigrationState = migrations.MigrationState;
47
49
  exports.MigrationsStatusResolver = migrations.MigrationsStatusResolver;
48
50
  exports.sortMigrations = migrations.sortMigrations;
49
51
  exports.MigrationsResolver = MigrationsResolver.MigrationsResolver;
52
+ exports.SchemaStateManager = SchemaStateManager.SchemaStateManager;
50
53
  exports.SchemaVersionBuilder = SchemaVersionBuilder.SchemaVersionBuilder;
54
+ exports.SnapshotManager = SnapshotManager.SnapshotManager;
51
55
  exports.MigrateErrorCode = SystemClient.MigrateErrorCode;
52
56
  exports.SystemClient = SystemClient.SystemClient;
53
57
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -8,7 +8,9 @@ import { MigrationFilesManager } from "./src/MigrationFilesManager.js";
8
8
  import { MigrationParser } from "./src/MigrationParser.js";
9
9
  import { MigrationState, MigrationsStatusResolver, sortMigrations } from "./src/migrations.js";
10
10
  import { MigrationsResolver } from "./src/MigrationsResolver.js";
11
+ import { SchemaStateManager } from "./src/SchemaStateManager.js";
11
12
  import { SchemaVersionBuilder } from "./src/SchemaVersionBuilder.js";
13
+ import { SnapshotManager } from "./src/SnapshotManager.js";
12
14
  import { MigrateErrorCode, SystemClient } from "./src/SystemClient.js";
13
15
  export {
14
16
  JsLoader,
@@ -25,7 +27,9 @@ export {
25
27
  ModificationHandlerFactory,
26
28
  SchemaDiffer,
27
29
  SchemaMigrator,
30
+ SchemaStateManager,
28
31
  SchemaVersionBuilder,
32
+ SnapshotManager,
29
33
  SystemClient,
30
34
  VERSION_LATEST,
31
35
  calculateMigrationChecksum,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsLoader.cjs","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default(args)\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":";;AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAgD;AACjE,UAAMA,YAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC/C,QAAI,EAAE,aAAaA,cAAY,EAAE,WAAWA,cAAY,EAAE,aAAaA,YAAU;AAChF,YAAM,8CAA8C,KAAK,IAAI;AAAA,IAC9D;AACA,QAAI,OAAOA,UAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,UAAQ,WAAWA,SAAO;AAAA,IACnE;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,OAAO,SAAiE;AAChF,cAAM,SAAS,MAAMA,UAAQ,QAAQ,IAAI;AACzC,cAAM,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AAC5E,YAAI,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAA;AAAA,QACX;AACA,eAAO;AAAA,MACR;AAAA,IAAA;AAAA,EAEF;AACD;;"}
1
+ {"version":3,"file":"JsLoader.cjs","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader.js'\nimport { MigrationParser } from './MigrationParser.js'\nimport { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile.js'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default(args)\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":";;AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAgD;AACjE,UAAMA,YAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC/C,QAAI,EAAE,aAAaA,cAAY,EAAE,WAAWA,cAAY,EAAE,aAAaA,YAAU;AAChF,YAAM,8CAA8C,KAAK,IAAI;AAAA,IAC9D;AACA,QAAI,OAAOA,UAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,UAAQ,WAAWA,SAAO;AAAA,IACnE;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,OAAO,SAAiE;AAChF,cAAM,SAAS,MAAMA,UAAQ,QAAQ,IAAI;AACzC,cAAM,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AAC5E,YAAI,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAA;AAAA,QACX;AACA,eAAO;AAAA,MACR;AAAA,IAAA;AAAA,EAEF;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsLoader.js","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default(args)\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":"AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAgD;AACjE,UAAMA,YAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC/C,QAAI,EAAE,aAAaA,cAAY,EAAE,WAAWA,cAAY,EAAE,aAAaA,YAAU;AAChF,YAAM,8CAA8C,KAAK,IAAI;AAAA,IAC9D;AACA,QAAI,OAAOA,UAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,UAAQ,WAAWA,SAAO;AAAA,IACnE;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,OAAO,SAAiE;AAChF,cAAM,SAAS,MAAMA,UAAQ,QAAQ,IAAI;AACzC,cAAM,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AAC5E,YAAI,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAA;AAAA,QACX;AACA,eAAO;AAAA,MACR;AAAA,IAAA;AAAA,EAEF;AACD;"}
1
+ {"version":3,"file":"JsLoader.js","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader.js'\nimport { MigrationParser } from './MigrationParser.js'\nimport { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile.js'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default(args)\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":"AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAgD;AACjE,UAAMA,YAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC/C,QAAI,EAAE,aAAaA,cAAY,EAAE,WAAWA,cAAY,EAAE,aAAaA,YAAU;AAChF,YAAM,8CAA8C,KAAK,IAAI;AAAA,IAC9D;AACA,QAAI,OAAOA,UAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,UAAQ,WAAWA,SAAO;AAAA,IACnE;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,OAAO,SAAiE;AAChF,cAAM,SAAS,MAAMA,UAAQ,QAAQ,IAAI;AACzC,cAAM,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AAC5E,YAAI,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAA;AAAA,QACX;AACA,eAAO;AAAA,MACR;AAAA,IAAA;AAAA,EAEF;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsonLoader.cjs","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser'\nimport { MigrationFile } from './MigrationFile'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAMA,cAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;;"}
1
+ {"version":3,"file":"JsonLoader.cjs","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader.js'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser.js'\nimport { MigrationFile } from './MigrationFile.js'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAMA,cAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsonLoader.js","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser'\nimport { MigrationFile } from './MigrationFile'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;"}
1
+ {"version":3,"file":"JsonLoader.js","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader.js'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser.js'\nimport { MigrationFile } from './MigrationFile.js'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;"}
@@ -17,9 +17,8 @@ class MigrationCreator {
17
17
  const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
18
18
  return filename;
19
19
  }
20
- async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
21
- await this.migrationFilesManager.createDirIfNotExist();
22
- const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
20
+ async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false } = {}) {
21
+ const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews });
23
22
  if (modifications.length === 0) {
24
23
  return null;
25
24
  }
@@ -27,6 +26,7 @@ class MigrationCreator {
27
26
  return { initialSchema, migration };
28
27
  }
29
28
  async saveMigration(migration) {
29
+ await this.migrationFilesManager.createDirIfNotExist();
30
30
  const jsonDiff = MigrationCreator.createContent(migration);
31
31
  const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name);
32
32
  return filename;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationCreator.cjs","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}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AAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;;"}
1
+ {"version":3,"file":"MigrationCreator.cjs","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager.js'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false }: {\n\t\t\tskipInitialSchemaValidation?: boolean\n\t\t\tskipNonModelDiffers?: boolean\n\t\t\trecreateViews?: boolean\n\t\t} = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":["MigrationVersionHelper","VERSION_LATEST"],"mappings":";;;;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EACf;AAAA,EAEH,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAC3C;AACA,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,CAAA,EAAG,QAAQ,IAAIA,oCAAuB,cAAc,aAAa;AACvE,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAE1G,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,OAAO,sBAAsB,OAAO,gBAAgB,MAAA,IAIhF,CAAA,GAC8D;AAClE,UAAM,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B,qBAAqB,eAAe;AACjJ,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AAEA,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAEnE,WAAO,EAAE,eAAe,UAAA;AAAA,EACzB;AAAA,EAEA,MAAM,cAAc,WAAuC;AAC1D,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AACrF,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,gBAAgB,MAA6B;AAClD,UAAM,KAAK,sBAAsB,WAAW,IAAI;AAAA,EACjD;AAAA,EAEQ,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAIA,aAAAA,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAeC,iBAAAA,gBAAgB,eAAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;;"}
@@ -15,9 +15,8 @@ class MigrationCreator {
15
15
  const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
16
16
  return filename;
17
17
  }
18
- async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
19
- await this.migrationFilesManager.createDirIfNotExist();
20
- const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
18
+ async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false } = {}) {
19
+ const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews });
21
20
  if (modifications.length === 0) {
22
21
  return null;
23
22
  }
@@ -25,6 +24,7 @@ class MigrationCreator {
25
24
  return { initialSchema, migration };
26
25
  }
27
26
  async saveMigration(migration) {
27
+ await this.migrationFilesManager.createDirIfNotExist();
28
28
  const jsonDiff = MigrationCreator.createContent(migration);
29
29
  const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name);
30
30
  return filename;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationCreator.js","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EACf;AAAA,EAEH,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAC3C;AACA,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,CAAA,EAAG,QAAQ,IAAI,uBAAuB,cAAc,aAAa;AACvE,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAE1G,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,MAAA,IAAqD,IACnB;AAClE,UAAM,KAAK,sBAAsB,oBAAA;AAEjC,UAAM,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B;AAC7G,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AAEA,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAEnE,WAAO,EAAE,eAAe,UAAA;AAAA,EACzB;AAAA,EAEA,MAAM,cAAc,WAAuC;AAC1D,UAAM,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AACrF,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,gBAAgB,MAA6B;AAClD,UAAM,KAAK,sBAAsB,WAAW,IAAI;AAAA,EACjD;AAAA,EAEQ,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAI,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAe,gBAAgB,eAAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;"}
1
+ {"version":3,"file":"MigrationCreator.js","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager.js'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false }: {\n\t\t\tskipInitialSchemaValidation?: boolean\n\t\t\tskipNonModelDiffers?: boolean\n\t\t\trecreateViews?: boolean\n\t\t} = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EACf;AAAA,EAEH,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAC3C;AACA,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,CAAA,EAAG,QAAQ,IAAI,uBAAuB,cAAc,aAAa;AACvE,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAE1G,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,OAAO,sBAAsB,OAAO,gBAAgB,MAAA,IAIhF,CAAA,GAC8D;AAClE,UAAM,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B,qBAAqB,eAAe;AACjJ,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AAEA,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAEnE,WAAO,EAAE,eAAe,UAAA;AAAA,EACzB;AAAA,EAEA,MAAM,cAAc,WAAuC;AAC1D,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AACrF,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,gBAAgB,MAA6B;AAClD,UAAM,KAAK,sBAAsB,WAAW,IAAI;AAAA,EACjD;AAAA,EAEQ,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAI,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAe,gBAAgB,eAAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;"}
@@ -7,14 +7,16 @@ class MigrationExecutor {
7
7
  migrations,
8
8
  contentMigrationFactoryArgs,
9
9
  force,
10
+ schemaState,
10
11
  log = () => null
11
12
  }) {
12
- if (migrations.length === 0) {
13
+ if (migrations.length === 0 && !schemaState) {
13
14
  return;
14
15
  }
15
16
  let migrationsToRun = [];
17
+ let batchSchemaState;
16
18
  const executeMigrations = async () => {
17
- if (migrationsToRun.length === 0) {
19
+ if (migrationsToRun.length === 0 && !batchSchemaState) {
18
20
  return;
19
21
  }
20
22
  await client.migrate(
@@ -41,14 +43,18 @@ class MigrationExecutor {
41
43
  }
42
44
  return assertNever.assertNever();
43
45
  }),
44
- force
46
+ force,
47
+ batchSchemaState
45
48
  );
46
49
  migrationsToRun.forEach((it) => {
47
50
  log(it.name);
48
51
  });
49
52
  migrationsToRun = [];
53
+ batchSchemaState = void 0;
50
54
  };
51
- log("Executing...");
55
+ if (migrations.length > 0) {
56
+ log("Executing...");
57
+ }
52
58
  for (const migration of migrations) {
53
59
  const migrationContent = await migration.localMigration.getContent();
54
60
  if (migrationContent.type === "factory") {
@@ -63,8 +69,11 @@ class MigrationExecutor {
63
69
  migrationsToRun.push(migrationContent);
64
70
  }
65
71
  }
72
+ batchSchemaState = schemaState;
66
73
  await executeMigrations();
67
- log("Migration executed");
74
+ if (migrations.length > 0) {
75
+ log("Migration executed");
76
+ }
68
77
  }
69
78
  }
70
79
  exports.MigrationExecutor = MigrationExecutor;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecuteHelper.cjs","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile'\nimport { assertNever } from './utils/assertNever'\nimport { SystemClient } from './SystemClient'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t}): Promise<void> {\n\t\tif (migrations.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t}\n\n\t\tlog('Executing...')\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tawait executeMigrations()\n\t\tlog('Migration executed')\n\t}\n}\n"],"names":["assertNever"],"mappings":";;;AAKO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AAA,MACtC;AAAA,IACD;AACA,UAAM,kBAAA;AACN,QAAI,oBAAoB;AAAA,EACzB;AACD;;"}
1
+ {"version":3,"file":"MigrationExecuteHelper.cjs","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations.js'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile.js'\nimport { assertNever } from './utils/assertNever.js'\nimport { SystemClient } from './SystemClient.js'\nimport { SchemaState } from './SchemaStateManager.js'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tschemaState,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t\tschemaState?: SchemaState\n\t}): Promise<void> {\n\t\tif (migrations.length === 0 && !schemaState) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\t\tlet batchSchemaState: SchemaState | undefined\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0 && !batchSchemaState) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t\tbatchSchemaState,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t\tbatchSchemaState = undefined\n\t\t}\n\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Executing...')\n\t\t}\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tbatchSchemaState = schemaState\n\t\tawait executeMigrations()\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Migration executed')\n\t\t}\n\t}\n}\n"],"names":["assertNever"],"mappings":";;;AAMO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAQK;AACjB,QAAI,WAAW,WAAW,KAAK,CAAC,aAAa;AAC5C;AAAA,IACD;AACA,QAAI,kBAA8C,CAAA;AAClD,QAAI;AAEJ,UAAM,oBAAoB,YAAY;AACrC,UAAI,gBAAgB,WAAW,KAAK,CAAC,kBAAkB;A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ationFactoryArgs,
7
7
  force,
8
+ schemaState,
8
9
  log = () => null
9
10
  }) {
10
- if (migrations.length === 0) {
11
+ if (migrations.length === 0 && !schemaState) {
11
12
  return;
12
13
  }
13
14
  let migrationsToRun = [];
15
+ let batchSchemaState;
14
16
  const executeMigrations = async () => {
15
- if (migrationsToRun.length === 0) {
17
+ if (migrationsToRun.length === 0 && !batchSchemaState) {
16
18
  return;
17
19
  }
18
20
  await client.migrate(
@@ -39,14 +41,18 @@ class MigrationExecutor {
39
41
  }
40
42
  return assertNever();
41
43
  }),
42
- force
44
+ force,
45
+ batchSchemaState
43
46
  );
44
47
  migrationsToRun.forEach((it) => {
45
48
  log(it.name);
46
49
  });
47
50
  migrationsToRun = [];
51
+ batchSchemaState = void 0;
48
52
  };
49
- log("Executing...");
53
+ if (migrations.length > 0) {
54
+ log("Executing...");
55
+ }
50
56
  for (const migration of migrations) {
51
57
  const migrationContent = await migration.localMigration.getContent();
52
58
  if (migrationContent.type === "factory") {
@@ -61,8 +67,11 @@ class MigrationExecutor {
61
67
  migrationsToRun.push(migrationContent);
62
68
  }
63
69
  }
70
+ batchSchemaState = schemaState;
64
71
  await executeMigrations();
65
- log("Migration executed");
72
+ if (migrations.length > 0) {
73
+ log("Migration executed");
74
+ }
66
75
  }
67
76
  }
68
77
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecuteHelper.js","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile'\nimport { assertNever } from './utils/assertNever'\nimport { SystemClient } from './SystemClient'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t}): Promise<void> {\n\t\tif (migrations.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t}\n\n\t\tlog('Executing...')\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tawait executeMigrations()\n\t\tlog('Migration executed')\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAOK;AACjB,QAAI,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,QAAI,kBAA8C,CAAA;AAElD,UAAM,oBAAoB,YAAY;AACrC,UAAI,gBAAgB,WAAW,GAAG;AACjC;AAAA,MACD;AACA,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAA,OAAM;AACzB,cAAI,GAAG,SAAS,UAAU;AACzB,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,iBAAiB;AAAA,gBAChB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEF;AACA,cAAI,GAAG,SAAS,WAAW;AAC1B,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YAAA;AAAA,UAEvB;AACA,iBAAO,YAAc;AAAA,QACtB,CAAC;AAAA,QACD;AAAA,MAAA;AAED,sBAAgB,QAAQ,CAAA,OAAM;AAC7B,YAAI,GAAG,IAAI;AAAA,MACZ,CAAC;AACD,wBAAkB,CAAA;AAAA,IACnB;AAEA,QAAI,cAAc;AAElB,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAA;AACxD,UAAI,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAA;AACN,cAAM,SAAS,MAAM,iBAAiB,QAAQ;AAAA,UAC7C,GAAG;AAAA,UACH,WAAW,UAAU;AAAA,QAAA,CACrB;AACD,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAA;AAAA,MACP,OAAO;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MACtC;AAAA,IACD;AACA,UAAM,kBAAA;AACN,QAAI,oBAAoB;AAAA,EACzB;AACD;"}
1
+ {"version":3,"file":"MigrationExecuteHelper.js","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations.js'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile.js'\nimport { assertNever } from './utils/assertNever.js'\nimport { SystemClient } from './SystemClient.js'\nimport { SchemaState } from './SchemaStateManager.js'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tschemaState,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t\tschemaState?: SchemaState\n\t}): Promise<void> {\n\t\tif (migrations.length === 0 && !schemaState) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\t\tlet batchSchemaState: SchemaState | undefined\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0 && !batchSchemaState) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t\tbatchSchemaState,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t\tbatchSchemaState = undefined\n\t\t}\n\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Executing...')\n\t\t}\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tbatchSchemaState = schemaState\n\t\tawait executeMigrations()\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Migration executed')\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAMO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAQK;AACjB,QAAI,WAAW,WAAW,KAAK,CAA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I,WAAW,SAAS,GAAG;AAC1B,UAAI,oBAAoB;AAAA,IACzB;AAAA,EACD;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFile.cjs","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;;"}
1
+ {"version":3,"file":"MigrationFile.cjs","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json.js'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder.js'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFile.js","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":"AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;"}
1
+ {"version":3,"file":"MigrationFile.js","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json.js'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder.js'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":"AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const engineCommon = require("@contember/engine-common");
4
4
  const fs = require("node:fs/promises");
5
- const node_path = require("node:path");
5
+ const path = require("node:path");
6
6
  function _interopNamespaceDefault(e) {
7
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
8
  if (e) {
@@ -31,14 +31,14 @@ class MigrationFilesManager {
31
31
  }
32
32
  async createFile(content, name, extension = "json") {
33
33
  this.migrations = null;
34
- const path = this.formatPath(name, extension);
35
- await fs__namespace.writeFile(path, content, { encoding: "utf8" });
36
- return await fs__namespace.realpath(path);
34
+ const path2 = this.formatPath(name, extension);
35
+ await fs__namespace.writeFile(path2, content, { encoding: "utf8" });
36
+ return await fs__namespace.realpath(path2);
37
37
  }
38
38
  async removeFile(name) {
39
39
  this.migrations = null;
40
- const path = this.formatPath(name);
41
- await fs__namespace.unlink(path);
40
+ const path2 = this.formatPath(name);
41
+ await fs__namespace.unlink(path2);
42
42
  }
43
43
  async moveFile(oldName, newName) {
44
44
  this.migrations = null;
@@ -63,12 +63,12 @@ class MigrationFilesManager {
63
63
  }));
64
64
  return files.map(({ version, filename }) => {
65
65
  const ext = filename.substring(filename.lastIndexOf(".") + 1);
66
- const path = node_path.join(this.directory, filename);
66
+ const path$1 = path.join(this.directory, filename);
67
67
  let content = null;
68
68
  const file = {
69
- path,
69
+ path: path$1,
70
70
  version,
71
- name: engineCommon.MigrationVersionHelper.extractName(path.substring(path.lastIndexOf("/") + 1)),
71
+ name: engineCommon.MigrationVersionHelper.extractName(path$1.substring(path$1.lastIndexOf("/") + 1)),
72
72
  getContent: () => {
73
73
  content ?? (content = this.loaders[ext].load(file));
74
74
  return content;
@@ -98,8 +98,8 @@ class MigrationFilesManager {
98
98
  }
99
99
  formatPath(version, extension = "json") {
100
100
  const filename = `${version}.${extension}`;
101
- const path = `${this.directory}/${filename}`;
102
- return path;
101
+ const path2 = `${this.directory}/${filename}`;
102
+ return path2;
103
103
  }
104
104
  }
105
105
  exports.MigrationFilesManager = MigrationFilesManager;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFilesManager.cjs","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationContent, MigrationFile } from './MigrationFile'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":["fs","MigrationVersionHelper","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOO,MAAM,sBAAsB;AAAA,EAGlC,YACiB,WACC,SAChB;AAFe,SAAA,YAAA;A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AAAA,QACA,MAAMD,aAAAA,uBAAuB,YAAY,KAAK,UAAU,KAAK,YAAY,GAAG,IAAI,CAAC,CAAC;AAAA,QAClF,YAAY,MAAM;AACjB,sBAAA,UAAY,KAAK,QAAQ,GAAG,EAAE,KAAK,IAAI;AACvC,iBAAO;AAAA,QACR;AAAA,MAAA;AAED,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,aAAgC;AAC7C,QAAI;AACH,aAAO,MAAMD,cAAG,QAAQ,KAAK,WAAW,EAAE,eAAe,MAAM;AAAA,IAChE,SAAS,GAAG;AACX,UAAI,aAAa,SAAS,UAAU,KAAM,EAAU,SAAS,UAAU;AACtE,eAAO,CAAA;AAAA,MACR;AACA,YAAM;AAAA,IACP;AAAA,EACD;AAAA,EAEA,MAAc,YAA+B;AAC5C,UAAM,QAAQ,MAAM,KAAK,WAAA;AAEzB,UAAM,aAAa,OAAO,KAAK,KAAK,OAAO,EAAE,KAAK,GAAG;AACrD,UAAM,QAAQ,IAAI,OAAO,6CAA6C,aAAa,IAAI;AACvF,UAAM,gBAAgB,MAAM,QAAQ;AAAA,MACnC,MACE,OAAO,CAAA,OAAM,GAAG,OAAA,CAAQ,EACxB,IAAI,CAAA,OAAM,GAAG,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAO;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"MigrationFilesManager.cjs","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader.js'\nimport { MigrationContent, MigrationFile } from './MigrationFile.js'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":["path","fs","MigrationVersionHelper","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOO,MAAM,sBAAsB;AAAA,EAGlC,YACiB,WACC,SAChB;AAFe,SAAA,YAAA;AACC,SAAA,UAAA;AAJlB,kBAAA,MAAQ,cAA8C,IAAA;AAAA,EAKnD;AAAA,EAEH,MAAa,WAAW,SAAiB,MAAc,YAAY,QAAyB;AAC3F,SAAK,aAAa;AAClB,UAAMA,QAAO,KAAK,WAAW,MAAM,SAAS;AAC5C,UAAMC,cAAG,UAAUD,OAAM,SAAS,EAAE,UAAU,QAAQ;AACtD,WAAO,MAAMC,cAAG,SAASD,KAAI;AAAA,EAC9B;AAAA,EAEA,MAAa,WAAW,MAAc;AACrC,SAAK,aAAa;AAClB,UAAMA,QAAO,KAAK,WA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A,IAChE,SAAS,GAAG;AACX,UAAI,aAAa,SAAS,UAAU,KAAM,EAAU,SAAS,UAAU;AACtE,eAAO,CAAA;AAAA,MACR;AACA,YAAM;AAAA,IACP;AAAA,EACD;AAAA,EAEA,MAAc,YAA+B;AAC5C,UAAM,QAAQ,MAAM,KAAK,WAAA;AAEzB,UAAM,aAAa,OAAO,KAAK,KAAK,OAAO,EAAE,KAAK,GAAG;AACrD,UAAM,QAAQ,IAAI,OAAO,6CAA6C,aAAa,IAAI;AACvF,UAAM,gBAAgB,MAAM,QAAQ;AAAA,MACnC,MACE,OAAO,CAAA,OAAM,GAAG,OAAA,CAAQ,EACxB,IAAI,CAAA,OAAM,GAAG,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAMD,QAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAOA;AAAA,EACR;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFilesManager.js","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationContent, MigrationFile } from './MigrationFile'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,sBAAsB;AAAA,EAGlC,YACiB,WACC,SAChB;AAFe,SAAA,YAAA;AACC,SAAA,UAAA;AAJlB,kBAAA,MAAQ,cAA8C,IAAA;AAAA,EAKnD;AAAA,EAEH,MAAa,WAAW,SAAiB,MAAc,YAAY,QAAyB;AAC3F,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,MAAM,SAAS;AAC5C,UAAM,GAAG,UAAU,MAAM,SAAS,EAAE,UAAU,QAAQ;AACtD,WAAO,MAAM,GAAG,SAAS,IAAI;AAAA,EAC9B;AAAA,EAEA,MAAa,WAAW,MAAc;AACrC,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,IAAI;AACjC,UAAM,GAAG,OAAO,IAAI;AAAA,EACrB;AAAA,EAEA,MAAa,SAAS,SAAiB,SAAiB;AACvD,SAAK,aAAa;AAClB,UAAM,GAAG,OAAO,KAAK,WAAW,OAAO,GAAG,KAAK,WAAW,OAAO,CAAC;AAAA,EACnE;AAAA,EAEA,MAAa,sBAAqC;AACjD,QAAI;AACH,YAAM,GAAG,MAAM,KAAK,SAAS;AAAA,IAC9B,SAAS,GAAG;AACX,UAAI,EAAE,aAAa,UAAU,EAAE,UAAU,MAAO,EAAU,SAAS,UAAU;AAC5E,cAAM;AAAA,MACP;AAAA,IAC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IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"MigrationFilesManager.js","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader.js'\nimport { MigrationContent, MigrationFile } from './MigrationFile.js'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,sBAAsB;AAA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AAAA,QAC3B;AAAA,QACA;AAAA,QACA,MAAM,uBAAuB,YAAY,KAAK,UAAU,KAAK,YAAY,GAAG,IAAI,CAAC,CAAC;AAAA,QAClF,YAAY,MAAM;AACjB,sBAAA,UAAY,KAAK,QAAQ,GAAG,EAAE,KAAK,IAAI;AACvC,iBAAO;AAAA,QACR;AAAA,MAAA;AAED,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,aAAgC;AAC7C,QAAI;AACH,aAAO,MAAM,GAAG,QAAQ,KAAK,WAAW,EAAE,eAAe,MAAM;AAAA,IAChE,SAAS,GAAG;AACX,UAAI,aAAa,SAAS,UAAU,KAAM,EAAU,SAAS,UAAU;AACtE,eAAO,CAAA;AAAA,MACR;AACA,YAAM;AAAA,IACP;AAAA,EACD;AAAA,EAEA,MAAc,YAA+B;AAC5C,UAAM,QAAQ,MAAM,KAAK,WAAA;AAEzB,UAAM,aAAa,OAAO,KAAK,KAAK,OAAO,EAAE,KAAK,GAAG;AACrD,UAAM,QAAQ,IAAI,OAAO,6CAA6C,aAAa,IAAI;AACvF,UAAM,gBAAgB,MAAM,QAAQ;AAAA,MACnC,MACE,OAAO,CAAA,OAAM,GAAG,OAAA,CAAQ,EACxB,IAAI,CAAA,OAAM,GAAG,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAO;AAAA,EACR;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationParser.cjs","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile'\nimport { JSONValue } from './utils/json'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":["VERSION_INITIAL"],"mappings":";;;AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiBA,iBAAAA;AAAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;;"}
1
+ {"version":3,"file":"MigrationParser.cjs","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile.js'\nimport { JSONValue } from './utils/json.js'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":["VERSION_INITIAL"],"mappings":";;;AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiBA,iBAAAA;AAAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationParser.js","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile'\nimport { JSONValue } from './utils/json'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":[],"mappings":";AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiB;AAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;"}
1
+ {"version":3,"file":"MigrationParser.js","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile.js'\nimport { JSONValue } from './utils/json.js'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":[],"mappings":";AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiB;AAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;"}