@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 2.49 kB
JavaScript
import{copy as e}from"../../i18n/copy.mjs";import t from"../../../constants/constants.mjs";import n from"../../logger/index.mjs";import{addColumn as r,dropColumn as i,modifyColumn as a}from"./column-builder.mjs";import{addIndex as o,dropIndex as s}from"./index-builder.mjs";const c=async(c,l)=>{try{let e=c.config.db.supports(`multipleAlterTables`)??!1,u=!1;if(await Promise.all(l.migration.indexOperations.filter(e=>e.type===`remove`).map(e=>s(c,l.migration.tableName,e.index.name))),e){let e=c.db.client.schema.alterTable(l.migration.tableName);for(let o of l.migration.columnOperations)switch(o.type){case`add`:e=r(e,o,c.config.db),u=!0,n.debug({message:`Operation of type 'add' ran on column '${o.column.name}' for table '${l.migration.tableName}'`,scope:t.logScopes.migrations});break;case`modify`:e=a(e,o,c.config.db),u=!0,n.debug({message:`Operation of type 'modify' ran on column '${o.column.name}' for table '${l.migration.tableName}'`,scope:t.logScopes.migrations});break;case`remove`:e=i(e,o),u=!0,n.debug({message:`Operation of type 'remove' ran on column '${o.columnName}' for table '${l.migration.tableName}'`,scope:t.logScopes.migrations});break}return u&&await e.execute(),await Promise.all(l.migration.indexOperations.filter(e=>e.type===`add`).map(e=>o(c,l.migration.tableName,e.index))),{data:void 0,error:void 0}}let d=[];for(let e of l.migration.columnOperations){let o=c.db.client.schema.alterTable(l.migration.tableName);switch(e.type){case`add`:o=r(o,e,c.config.db),u=!0,n.debug({message:`Operation of type 'add' ran on column '${e.column.name}' for table '${l.migration.tableName}'`,scope:t.logScopes.migrations});break;case`modify`:o=a(o,e,c.config.db),u=!0,n.debug({message:`Operation of type 'modify' ran on column '${e.column.name}' for table '${l.migration.tableName}'`,scope:t.logScopes.migrations});break;case`remove`:o=i(o,e),u=!0,n.debug({message:`Operation of type 'remove' ran on column '${e.columnName}' for table '${l.migration.tableName}'`,scope:t.logScopes.migrations});break}u&&=(d.push(o.execute()),!1)}return await Promise.all(d),await Promise.all(l.migration.indexOperations.filter(e=>e.type===`add`).map(e=>o(c,l.migration.tableName,e.index))),{data:void 0,error:void 0}}catch(t){return{data:void 0,error:{message:e(`server:core.collections.migration.table.modify.failed.message`,{data:{tableName:l.migration.tableName,errorMessage:t instanceof Error?t.message:String(t)}})}}}};export{c as default};
//# sourceMappingURL=modify-table-query.mjs.map