@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
4 lines • 3.12 kB
JavaScript
import{startLoggerBuffering as e,stopLoggerBuffering as t}from"../../logger/index.mjs";import n from"../../i18n/prepare-translations.mjs";import r from"../../../utils/services/create-service-context.mjs";import i from"../../collection/migration/assess-migration-plan.mjs";import a from"../../collection/plan-collection-migrations.mjs";import o from"../logger.mjs";import s from"../../config/load-config-file.mjs";import{prepareExternalMigrations as c}from"../../db/load-external-migrations.mjs";import{describeMigrationRiskReason as l}from"../services/migration-report.mjs";import u from"../services/validate-env-vars.mjs";import{sql as d}from"kysely";const f=async f=>{let p,m,h,g;try{e();let _=o.startTimer(),v=await s({prepareRuntime:!0});p=v.config,m=v.env,h=v.runtimeContext;let{translationStore:y}=await n({config:p,projectRoot:v.projectRoot});await u({envSchema:v.envSchema,env:v.env})||(await t(),process.exit(1)),o.info(`Checking the migration status`),await c(p,v.projectRoot),g=await p.db.connect(m);let b=Object.keys(p.db.migrations).sort(),x=[];try{x=(await d`
SELECT name FROM kysely_migration
`.execute(g.client)).rows.map(e=>e.name)}catch{}let S=b.filter(e=>!x.includes(e)),C=x.filter(e=>!b.includes(e)),w=r({config:p,database:g,translationStore:y,env:m,runtimeContext:h}),T=await a(w),E=[],D;if(T.error?D=w.translate.english(T.error.message)||`Unknown error`:E=T.data.collections.map(({migrationPlan:e})=>({collectionKey:e.collectionKey,assessment:i([e])})).filter(({assessment:e})=>e.reasons.length>0),o.info(`Found ${x.length} applied migration(s)`),S.length===0)o.success(`No database schema migrations are pending`);else{o.warn(`${S.length} database schema migration(s) are pending`);for(let e of S)o.log(o.color.yellow(e),{indent:2})}if(D)o.warn(`Could not check collection migration status: ${D}`);else if(E.length===0)o.success(`No collection/brick table migrations are needed`);else{o.warn(`${E.length} collection(s) need table migrations`);for(let e of[`safe`,`warning`,`destructive`]){let t=E.filter(t=>t.assessment.risk===e);if(t.length!==0){o.log(`${e.toUpperCase()} (${t.length})`,{indent:2});for(let e of t){o.log(o.color.yellow(e.collectionKey),{indent:4});for(let t of e.assessment.reasons)o.log(l(t),{indent:6})}}}}if(C.length>0){o.error(`${C.length} previously executed migration(s) are no longer registered`);for(let e of C)o.log(o.color.red(e),{indent:2});o.info(`If you removed a plugin or migration file, restore it so its migrations can be run or rolled back.`)}let O=S.length>0||E.length>0||D!==void 0,k=C.length>0,A=_();o.log(o.createBadge(`LUCID CMS`),O||k?`Migration status checked with`:`Migration status checked`,O||k?o.color.yellow(`outstanding work`):o.color.green(`successfully`),`in`,o.color.green(o.formatMilliseconds(A)),{spaceAfter:!0,spaceBefore:!0}),await g.destroy(),g=void 0,await t(),process.exit(f?.check&&(O||k)?1:0)}catch(e){await g?.destroy(),e instanceof Error?o.errorInstance(e,`Migration status failed`):o.error(`Migration status failed`,`Unknown error`),await t(),process.exit(1)}};export{f as default};
//# sourceMappingURL=migrate-status.mjs.map