UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

17 lines (16 loc) 1.23 kB
import e from"../../../constants/constants.mjs";import t from"../logger.mjs";import n from"../../config/get-config-path.mjs";import r from"node:fs/promises";import i from"node:path";const a=async a=>{try{/^[a-z0-9][a-z0-9-_]*$/.test(a)||(t.error(`Invalid migration name "${a}". Migration names must only contain lowercase letters, numbers, hyphens and underscores.`),process.exit(1));let o=i.dirname(n(process.cwd())),s=i.join(o,e.db.externalMigrationDirectory),c=`${Date.now()}-${a}.ts`,l=i.join(s,c);await r.mkdir(s,{recursive:!0}),await r.writeFile(l,`import { defineMigration } from "@lucidcms/core/plugin"; export default defineMigration((ctx) => ({ async up(db) { // await db.schema // .createTable("example") // .addColumn("id", ctx.adapter.getDataType("primary"), (col) => // ctx.adapter.primaryKeyColumnBuilder(col), // ) // .execute(); }, async down(db) { // await db.schema.dropTable("example").execute(); }, })); `,{flag:`wx`}),t.success(`Created migration`,t.color.cyan(i.relative(process.cwd(),l))),process.exit(0)}catch(e){t.error(`Failed to create migration`,e instanceof Error?e.message:`Unknown error`),process.exit(1)}};export{a as default}; //# sourceMappingURL=migrate-new.mjs.map