mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix mongodb templates and add migrate and generate scripts
This commit is contained in:
@@ -58,8 +58,8 @@ async function updateRootPackageJson(
|
||||
const needsDbScripts =
|
||||
options.backend !== "convex" &&
|
||||
options.database !== "none" &&
|
||||
options.orm !== "none";
|
||||
|
||||
options.orm !== "none" &&
|
||||
options.orm !== "mongoose";
|
||||
if (options.addons.includes("turborepo")) {
|
||||
scripts.dev = "turbo dev";
|
||||
scripts.build = "turbo build";
|
||||
@@ -73,6 +73,13 @@ async function updateRootPackageJson(
|
||||
if (needsDbScripts) {
|
||||
scripts["db:push"] = `turbo -F ${backendPackageName} db:push`;
|
||||
scripts["db:studio"] = `turbo -F ${backendPackageName} db:studio`;
|
||||
if (options.orm === "prisma") {
|
||||
scripts["db:generate"] = `turbo -F ${backendPackageName} db:generate`;
|
||||
scripts["db:migrate"] = `turbo -F ${backendPackageName} db:migrate`;
|
||||
} else if (options.orm === "drizzle") {
|
||||
scripts["db:generate"] = `turbo -F ${backendPackageName} db:generate`;
|
||||
scripts["db:migrate"] = `turbo -F ${backendPackageName} db:migrate`;
|
||||
}
|
||||
}
|
||||
} else if (options.packageManager === "pnpm") {
|
||||
scripts.dev = devScript;
|
||||
@@ -87,6 +94,17 @@ async function updateRootPackageJson(
|
||||
if (needsDbScripts) {
|
||||
scripts["db:push"] = `pnpm --filter ${backendPackageName} db:push`;
|
||||
scripts["db:studio"] = `pnpm --filter ${backendPackageName} db:studio`;
|
||||
if (options.orm === "prisma") {
|
||||
scripts["db:generate"] =
|
||||
`pnpm --filter ${backendPackageName} db:generate`;
|
||||
scripts["db:migrate"] =
|
||||
`pnpm --filter ${backendPackageName} db:migrate`;
|
||||
} else if (options.orm === "drizzle") {
|
||||
scripts["db:generate"] =
|
||||
`pnpm --filter ${backendPackageName} db:generate`;
|
||||
scripts["db:migrate"] =
|
||||
`pnpm --filter ${backendPackageName} db:migrate`;
|
||||
}
|
||||
}
|
||||
} else if (options.packageManager === "npm") {
|
||||
scripts.dev = devScript;
|
||||
@@ -102,6 +120,17 @@ async function updateRootPackageJson(
|
||||
scripts["db:push"] = `npm run db:push --workspace ${backendPackageName}`;
|
||||
scripts["db:studio"] =
|
||||
`npm run db:studio --workspace ${backendPackageName}`;
|
||||
if (options.orm === "prisma") {
|
||||
scripts["db:generate"] =
|
||||
`npm run db:generate --workspace ${backendPackageName}`;
|
||||
scripts["db:migrate"] =
|
||||
`npm run db:migrate --workspace ${backendPackageName}`;
|
||||
} else if (options.orm === "drizzle") {
|
||||
scripts["db:generate"] =
|
||||
`npm run db:generate --workspace ${backendPackageName}`;
|
||||
scripts["db:migrate"] =
|
||||
`npm run db:migrate --workspace ${backendPackageName}`;
|
||||
}
|
||||
}
|
||||
} else if (options.packageManager === "bun") {
|
||||
scripts.dev = devScript;
|
||||
@@ -116,6 +145,17 @@ async function updateRootPackageJson(
|
||||
if (needsDbScripts) {
|
||||
scripts["db:push"] = `bun run --filter ${backendPackageName} db:push`;
|
||||
scripts["db:studio"] = `bun run --filter ${backendPackageName} db:studio`;
|
||||
if (options.orm === "prisma") {
|
||||
scripts["db:generate"] =
|
||||
`bun run --filter ${backendPackageName} db:generate`;
|
||||
scripts["db:migrate"] =
|
||||
`bun run --filter ${backendPackageName} db:migrate`;
|
||||
} else if (options.orm === "drizzle") {
|
||||
scripts["db:generate"] =
|
||||
`bun run --filter ${backendPackageName} db:generate`;
|
||||
scripts["db:migrate"] =
|
||||
`bun run --filter ${backendPackageName} db:migrate`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,9 +232,13 @@ async function updateServerPackageJson(
|
||||
if (options.orm === "prisma") {
|
||||
scripts["db:push"] = "prisma db push --schema ./prisma/schema";
|
||||
scripts["db:studio"] = "prisma studio";
|
||||
scripts["db:generate"] = "prisma generate --schema ./prisma/schema";
|
||||
scripts["db:migrate"] = "prisma migrate dev";
|
||||
} else if (options.orm === "drizzle") {
|
||||
scripts["db:push"] = "drizzle-kit push";
|
||||
scripts["db:studio"] = "drizzle-kit studio";
|
||||
scripts["db:generate"] = "drizzle-kit generate";
|
||||
scripts["db:migrate"] = "drizzle-kit migrate";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -371,7 +371,7 @@ export async function setupAuthTemplate(
|
||||
authDbSrc = path.join(
|
||||
PKG_ROOT,
|
||||
`templates/auth/server/db/mongoose/${db}`,
|
||||
)
|
||||
);
|
||||
}
|
||||
if (authDbSrc && (await fs.pathExists(authDbSrc))) {
|
||||
await processAndCopyFiles("**/*", authDbSrc, serverAppDir, context);
|
||||
|
||||
@@ -446,82 +446,86 @@ function processAndValidateFlags(
|
||||
config.dbSetup = "none";
|
||||
}
|
||||
|
||||
if (effectiveDatabase === "mongodb" && effectiveOrm === "drizzle") {
|
||||
consola.fatal(
|
||||
"Drizzle ORM is not compatible with MongoDB. Please use --orm prisma or --orm mongoose.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (config.orm === "mongoose" && !providedFlags.has("database")) {
|
||||
config.database = "mongodb";
|
||||
}
|
||||
|
||||
if (
|
||||
effectiveOrm === "mongoose" &&
|
||||
effectiveDatabase &&
|
||||
effectiveDatabase !== "mongodb"
|
||||
) {
|
||||
consola.fatal(
|
||||
`Mongoose ORM requires MongoDB. Cannot use --orm mongoose with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (config.dbSetup && config.dbSetup !== "none") {
|
||||
const dbSetup = config.dbSetup;
|
||||
|
||||
if (!effectiveDatabase || effectiveDatabase === "none") {
|
||||
if (effectiveDatabase === "mongodb" && effectiveOrm === "drizzle") {
|
||||
consola.fatal(
|
||||
`Database setup '--db-setup ${dbSetup}' requires a database. Cannot use when database is 'none'.`,
|
||||
"Drizzle ORM is not compatible with MongoDB. Please use --orm prisma or --orm mongoose.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (dbSetup === "turso") {
|
||||
if (effectiveDatabase && effectiveDatabase !== "sqlite") {
|
||||
if (
|
||||
effectiveOrm === "mongoose" &&
|
||||
effectiveDatabase &&
|
||||
effectiveDatabase !== "mongodb"
|
||||
) {
|
||||
consola.fatal(
|
||||
`Mongoose ORM requires MongoDB. Cannot use --orm mongoose with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (config.dbSetup && config.dbSetup !== "none") {
|
||||
const dbSetup = config.dbSetup;
|
||||
|
||||
if (!effectiveDatabase || effectiveDatabase === "none") {
|
||||
consola.fatal(
|
||||
`Turso setup requires SQLite. Cannot use --db-setup turso with --database ${effectiveDatabase}`,
|
||||
`Database setup '--db-setup ${dbSetup}' requires a database. Cannot use when database is 'none'.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (effectiveOrm !== "drizzle") {
|
||||
consola.fatal(
|
||||
`Turso setup requires Drizzle ORM. Cannot use --db-setup turso with --orm ${effectiveOrm ?? "none"}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (dbSetup === "prisma-postgres") {
|
||||
if (effectiveDatabase !== "postgres") {
|
||||
consola.fatal(
|
||||
`Prisma PostgreSQL setup requires PostgreSQL. Cannot use --db-setup prisma-postgres with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (effectiveOrm !== "prisma") {
|
||||
consola.fatal(
|
||||
`Prisma PostgreSQL setup requires Prisma ORM. Cannot use --db-setup prisma-postgres with --orm ${effectiveOrm}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (dbSetup === "mongodb-atlas") {
|
||||
if (effectiveDatabase !== "mongodb") {
|
||||
consola.fatal(
|
||||
`MongoDB Atlas setup requires MongoDB. Cannot use --db-setup mongodb-atlas with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (effectiveOrm !== "prisma" && effectiveOrm !== "mongoose") {
|
||||
consola.fatal(
|
||||
`MongoDB Atlas setup requires Prisma or Mongoose ORM. Cannot use --db-setup mongodb-atlas with --orm ${effectiveOrm}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (dbSetup === "neon") {
|
||||
if (effectiveDatabase !== "postgres") {
|
||||
consola.fatal(
|
||||
`Neon PostgreSQL setup requires PostgreSQL. Cannot use --db-setup neon with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
|
||||
if (dbSetup === "turso") {
|
||||
if (effectiveDatabase && effectiveDatabase !== "sqlite") {
|
||||
consola.fatal(
|
||||
`Turso setup requires SQLite. Cannot use --db-setup turso with --database ${effectiveDatabase}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (effectiveOrm !== "drizzle") {
|
||||
consola.fatal(
|
||||
`Turso setup requires Drizzle ORM. Cannot use --db-setup turso with --orm ${effectiveOrm ?? "none"}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (dbSetup === "prisma-postgres") {
|
||||
if (effectiveDatabase !== "postgres") {
|
||||
consola.fatal(
|
||||
`Prisma PostgreSQL setup requires PostgreSQL. Cannot use --db-setup prisma-postgres with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (effectiveOrm !== "prisma") {
|
||||
consola.fatal(
|
||||
`Prisma PostgreSQL setup requires Prisma ORM. Cannot use --db-setup prisma-postgres with --orm ${effectiveOrm}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (dbSetup === "mongodb-atlas") {
|
||||
if (effectiveDatabase !== "mongodb") {
|
||||
consola.fatal(
|
||||
`MongoDB Atlas setup requires MongoDB. Cannot use --db-setup mongodb-atlas with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (effectiveOrm !== "prisma" && effectiveOrm !== "mongoose") {
|
||||
consola.fatal(
|
||||
`MongoDB Atlas setup requires Prisma or Mongoose ORM. Cannot use --db-setup mongodb-atlas with --orm ${effectiveOrm}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (dbSetup === "neon") {
|
||||
if (effectiveDatabase !== "postgres") {
|
||||
consola.fatal(
|
||||
`Neon PostgreSQL setup requires PostgreSQL. Cannot use --db-setup neon with --database ${effectiveDatabase}.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const includesNuxt = effectiveFrontend?.includes("nuxt");
|
||||
const includesSvelte = effectiveFrontend?.includes("svelte");
|
||||
@@ -580,13 +584,13 @@ function processAndValidateFlags(
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (config.addons.includes("husky") && !config.addons.includes("biome")) {
|
||||
consola.warn(
|
||||
"Husky addon is recommended to be used with Biome for lint-staged configuration.",
|
||||
);
|
||||
if (config.addons.includes("husky") && !config.addons.includes("biome")) {
|
||||
consola.warn(
|
||||
"Husky addon is recommended to be used with Biome for lint-staged configuration.",
|
||||
);
|
||||
}
|
||||
config.addons = [...new Set(config.addons)];
|
||||
}
|
||||
config.addons = [...new Set(config.addons)];
|
||||
}
|
||||
|
||||
const onlyNativeFrontend =
|
||||
effectiveFrontend &&
|
||||
|
||||
Reference in New Issue
Block a user