@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.6 kB
Source Map (JSON)
{"version":3,"file":"create-table-query.mjs","names":["constants"],"sources":["../../../../src/libs/collection/migration/create-table-query.ts"],"sourcesContent":["import constants from \"../../../constants/constants.js\";\nimport logger from \"../../../libs/logger/index.js\";\nimport type { ServiceFn } from \"../../../types.js\";\nimport { copy } from \"../../i18n/index.js\";\nimport { addColumn } from \"./column-builder.js\";\nimport { addIndex } from \"./index-builder.js\";\nimport type { TableMigration } from \"./types.js\";\n\nconst createTableQuery: ServiceFn<\n\t[\n\t\t{\n\t\t\tmigration: TableMigration;\n\t\t},\n\t],\n\tundefined\n> = async (context, data) => {\n\ttry {\n\t\tlet query = context.db.client.schema.createTable(data.migration.tableName);\n\n\t\tfor (const op of data.migration.columnOperations) {\n\t\t\tif (op.type !== \"add\") continue; //* if its a new table, only columns can be added\n\n\t\t\tquery = addColumn(query, op, context.config.db);\n\t\t\tlogger.debug({\n\t\t\t\tmessage: `Operation of type 'add' ran on column '${op.column.name}' for table '${data.migration.tableName}'`,\n\t\t\t\tscope: constants.logScopes.migrations,\n\t\t\t});\n\t\t}\n\n\t\tawait query.execute();\n\n\t\tawait Promise.all(\n\t\t\tdata.migration.indexOperations\n\t\t\t\t.filter((op) => op.type === \"add\")\n\t\t\t\t.map((op) => addIndex(context, data.migration.tableName, op.index)),\n\t\t);\n\n\t\treturn {\n\t\t\tdata: undefined,\n\t\t\terror: undefined,\n\t\t};\n\t} catch (err) {\n\t\treturn {\n\t\t\tdata: undefined,\n\t\t\terror: {\n\t\t\t\tmessage: copy(\n\t\t\t\t\t\"server:core.collections.migration.table.create.failed.message\",\n\t\t\t\t\t{\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\ttableName: data.migration.tableName,\n\t\t\t\t\t\t\terrorMessage: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t},\n\t\t};\n\t}\n};\n\nexport default createTableQuery;\n"],"mappings":"iOAQA,MAAM,EAOF,MAAO,EAAS,IAAS,CAC5B,GAAI,CACH,IAAI,EAAQ,EAAQ,GAAG,OAAO,OAAO,YAAY,EAAK,UAAU,SAAS,EAEzE,IAAK,IAAM,KAAM,EAAK,UAAU,iBAC3B,EAAG,OAAS,QAEhB,EAAQ,EAAU,EAAO,EAAI,EAAQ,OAAO,EAAE,EAC9C,EAAO,MAAM,CACZ,QAAS,0CAA0C,EAAG,OAAO,KAAK,eAAe,EAAK,UAAU,UAAU,GAC1G,MAAOA,EAAU,UAAU,UAC5B,CAAC,GAWF,OARA,MAAM,EAAM,QAAQ,EAEpB,MAAM,QAAQ,IACb,EAAK,UAAU,gBACb,OAAQ,GAAO,EAAG,OAAS,KAAK,CAAC,CACjC,IAAK,GAAO,EAAS,EAAS,EAAK,UAAU,UAAW,EAAG,KAAK,CAAC,CACpE,EAEO,CACN,KAAM,IAAA,GACN,MAAO,IAAA,EACR,CACD,OAAS,EAAK,CACb,MAAO,CACN,KAAM,IAAA,GACN,MAAO,CACN,QAAS,EACR,gEACA,CACC,KAAM,CACL,UAAW,EAAK,UAAU,UAC1B,aAAc,aAAe,MAAQ,EAAI,QAAU,OAAO,CAAG,CAC9D,CACD,CACD,CACD,CACD,CACD,CACD"}