Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
3.7 KiB
Plaintext
1 line
3.7 KiB
Plaintext
{"version":3,"sources":["../../../src/database/migrations/migrate.ts"],"sourcesContent":["import type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { createLocalReq } from '../../utilities/createLocalReq.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\nexport const migrate: BaseDatabaseAdapter['migrate'] = async function migrate(\n this: BaseDatabaseAdapter,\n args,\n): Promise<void> {\n const { payload } = this\n const migrationFiles = args?.migrations || (await readMigrationFiles({ payload }))\n const { existingMigrations, latestBatch } = await getMigrations({ payload })\n\n const newBatch = latestBatch + 1\n\n // Execute 'up' function for each migration sequentially\n for (const migration of migrationFiles) {\n const existingMigration = existingMigrations.find(\n (existing) => existing.name === migration.name,\n )\n\n // Run migration if not found in database\n if (existingMigration) {\n continue\n }\n\n const start = Date.now()\n const req = await createLocalReq({}, payload)\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n try {\n await initTransaction(req)\n const session = payload.db.sessions?.[await req.transactionID!]\n await migration.up({ payload, req, session })\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: newBatch,\n },\n req,\n })\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({ err, msg: `Error running migration ${migration.name}` })\n throw err\n }\n }\n}\n"],"names":["commitTransaction","createLocalReq","initTransaction","killTransaction","getMigrations","readMigrationFiles","migrate","args","payload","migrationFiles","migrations","existingMigrations","latestBatch","newBatch","migration","existingMigration","find","existing","name","start","Date","now","req","logger","info","msg","session","db","sessions","transactionID","up","create","collection","data","batch","err","error"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,OAAO,MAAMC,UAA0C,eAAeA,QAEpEC,IAAI;IAEJ,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiBF,MAAMG,cAAe,MAAML,mBAAmB;QAAEG;IAAQ;IAC/E,MAAM,EAAEG,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMR,cAAc;QAAEI;IAAQ;IAE1E,MAAMK,WAAWD,cAAc;IAE/B,wDAAwD;IACxD,KAAK,MAAME,aAAaL,eAAgB;QACtC,MAAMM,oBAAoBJ,mBAAmBK,IAAI,CAC/C,CAACC,WAAaA,SAASC,IAAI,KAAKJ,UAAUI,IAAI;QAGhD,yCAAyC;QACzC,IAAIH,mBAAmB;YACrB;QACF;QAEA,MAAMI,QAAQC,KAAKC,GAAG;QACtB,MAAMC,MAAM,MAAMrB,eAAe,CAAC,GAAGO;QAErCA,QAAQe,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEX,UAAUI,IAAI,EAAE;QAAC;QAE1D,IAAI;YACF,MAAMhB,gBAAgBoB;YACtB,MAAMI,UAAUlB,QAAQmB,EAAE,CAACC,QAAQ,EAAE,CAAC,MAAMN,IAAIO,aAAa,CAAE;YAC/D,MAAMf,UAAUgB,EAAE,CAAC;gBAAEtB;gBAASc;gBAAKI;YAAQ;YAC3ClB,QAA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