@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
4 lines • 3.75 kB
JavaScript
import e from"../../constants/constants.mjs";import t from"../logger/index.mjs";import n from"../../utils/errors/lucid-error.mjs";import{translate as r}from"../i18n/translate.mjs";import i from"./migrations/00000001-locales.mjs";import a from"./migrations/00000002-options.mjs";import o from"./migrations/00000003-users-and-permissions.mjs";import s from"./migrations/00000004-queues.mjs";import c from"./migrations/00000005-emails.mjs";import l from"./migrations/00000006-media.mjs";import u from"./migrations/00000007-collections.mjs";import d from"./migrations/00000008-integrations.mjs";import f from"./migrations/00000009-share-links.mjs";import p from"./migrations/00000010-alerts.mjs";import m from"./migrations/00000011-ai-generations.mjs";import h from"./migrations/00000012-preview-sessions.mjs";import{sql as g}from"kysely";import{Migrator as _}from"kysely/migration";var v=class{adapter;externalMigrations={};constructor(e){this.adapter=e}protectedMigrations=[`00000001-locales`,`00000002-options`,`00000003-users-and-permissions`,`00000004-queues`,`00000005-emails`,`00000006-media`,`00000007-collections`,`00000008-integrations`,`00000009-share-link`,`00000010-alerts`,`00000011-ai-generations`,`00000012-preview-sessions`];formatInsertValue(e,t){if(t==null)return t;if(e===`integer`&&typeof t==`boolean`||e===`boolean`&&typeof t==`boolean`)return this.supports(`boolean`)?t:+!!t;if(e===`jsonb`||e===`json`)try{return typeof t==`object`&&t?JSON.stringify(t):null}catch{return null}return t}getDataType(e,...t){let n=this.config.dataTypes[e];return typeof n==`function`?n(...t):n}primaryKeyColumnBuilder(e){return this.supports(`autoIncrement`)?e.primaryKey().autoIncrement():e.primaryKey()}supports(e){return this.config.support[e]}getDefault(e,t){let n=this.config.defaults[e];return t?n[t]:n}registerExternalMigrations(t){for(let r of Object.keys(t))if(!e.db.externalMigrationNameRegex.test(r))throw new n({message:`External migration "${r}" must start with a 13 digit timestamp, eg. "1751400000000-example".`});this.externalMigrations=t}async migrateToLatest(i){let a=this.migrations,{error:o,results:s}=await new _({db:i.client,provider:{async getMigrations(){return a}},allowUnorderedMigrations:!0}).migrateToLatest();if(s)for(let n of s)n.status===`Success`?t.debug({message:`"${n.migrationName}" was executed successfully`,scope:e.logScopes.migrations}):n.status===`Error`&&t.error({message:`failed to execute migration "${n.migrationName}"`,scope:e.logScopes.migrations});if(o){let e=typeof o==`object`&&o&&`errors`in o&&typeof o.errors==`object`&&o.errors!==null?o.errors:void 0;throw o instanceof Error&&o.message.includes(`previously executed migration`)&&o.message.includes(`is missing`)?new n({message:`${o.message}. A migration that has already run is no longer registered - if you removed a plugin or migration file, restore it, or roll its migrations back before removing it.`,data:e}):new n({message:o instanceof Error?o?.message:r(`server:core.database.migrations.failed`),data:e})}}async needsMigration(e){try{let t=Object.keys(this.migrations),n=(await g`
SELECT name FROM kysely_migration
`.execute(e)).rows.map(e=>e.name);return t.some(e=>!n.includes(e))}catch{return!0}}get migrations(){let e={"00000001-locales":i(this),"00000002-options":a(this),"00000003-users-and-permissions":o(this),"00000004-queues":s(this),"00000005-emails":c(this),"00000006-media":l(this),"00000007-collections":u(this),"00000008-integrations":d(this),"00000009-share-link":f(this),"00000010-alerts":p(this),"00000011-ai-generations":m(this),"00000012-preview-sessions":h(this)};for(let[t,n]of Object.entries(this.externalMigrations))e[t]=n({adapter:this});return e}};export{v as default};
//# sourceMappingURL=adapter-base.mjs.map