MCPcopy
hub / github.com/OneUptime/oneuptime / getDataMigrationStatus

Function getDataMigrationStatus

App/API/AdminHealth.ts:739–832  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

737 * pending migration is the one that is blocking every migration after it.
738 */
739async function getDataMigrationStatus(): Promise<JSONObject> {
740 const result: JSONObject = {
741 connected: false,
742 isUpToDate: false,
743 totalDefined: 0,
744 totalApplied: 0,
745 totalPending: 0,
746 latestDefinedMigration: null,
747 lastExecutedMigration: null,
748 nextPendingMigration: null,
749 pendingMigrations: [],
750 };
751
752 try {
753 // Ordered list of data / ClickHouse migrations compiled into this build.
754 const definedNames: Array<string> = distinctNames(
755 DataMigrationsList.map((migration: { name: string }): string => {
756 return migration.name;
757 }),
758 );
759
760 result["totalDefined"] = definedNames.length;
761
762 if (definedNames.length > 0) {
763 result["latestDefinedMigration"] = {
764 name: definedNames[definedNames.length - 1],
765 };
766 }
767
768 const dataSource: ReturnType<typeof PostgresAppInstance.getDataSource> =
769 PostgresAppInstance.getDataSource();
770
771 if (!dataSource) {
772 return result;
773 }
774
775 const rows: Array<{ name: string; executedAt: string | null }> =
776 await dataSource.query(
777 'SELECT name, "executedAt" FROM "DataMigrations" WHERE executed = true',
778 );
779
780 result["connected"] = true;
781 result["totalApplied"] = rows.length;
782
783 const appliedNames: Set<string> = new Set(
784 rows.map((row: { name: string }): string => {
785 return row.name;
786 }),
787 );
788
789 // Keep run order so the first pending migration is the one blocking the chain.
790 const pending: Array<string> = definedNames.filter(
791 (name: string): boolean => {
792 return !appliedNames.has(name);
793 },
794 );
795
796 result["pendingMigrations"] = pending;

Callers 1

getMigrationStatusFunction · 0.85

Calls 7

distinctNamesFunction · 0.85
mapMethod · 0.45
getDataSourceMethod · 0.45
queryMethod · 0.45
hasMethod · 0.45
sortMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected