Add database setup scripts and fix navigation

This commit is contained in:
Aman Varshney
2025-03-17 01:55:36 +05:30
parent b4274c796c
commit 30e16b5d09
4 changed files with 36 additions and 11 deletions

View File

@@ -127,6 +127,22 @@ ${options.orm === "prisma" ? 'DATABASE_URL="file:./dev.db"' : ""}
); );
await fs.writeFile(prismaAuthPath, authContent); await fs.writeFile(prismaAuthPath, authContent);
} }
const packageJsonPath = path.join(projectDir, "package.json");
if (await fs.pathExists(packageJsonPath)) {
const packageJson = await fs.readJson(packageJsonPath);
packageJson.scripts["prisma:generate"] =
"cd packages/server && npx prisma generate";
packageJson.scripts["prisma:push"] =
"cd packages/server && npx prisma db push";
packageJson.scripts["prisma:studio"] =
"cd packages/server && npx prisma studio";
packageJson.scripts["db:setup"] =
"npm run auth:generate && npm run prisma:generate && npm run prisma:push";
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
}
} else if (options.orm === "drizzle") { } else if (options.orm === "drizzle") {
const drizzleAuthPath = path.join(serverDir, "src/lib/auth.ts"); const drizzleAuthPath = path.join(serverDir, "src/lib/auth.ts");
const defaultDrizzleAuthPath = path.join( const defaultDrizzleAuthPath = path.join(
@@ -141,6 +157,18 @@ ${options.orm === "prisma" ? 'DATABASE_URL="file:./dev.db"' : ""}
await fs.ensureDir(path.dirname(drizzleAuthPath)); await fs.ensureDir(path.dirname(drizzleAuthPath));
await fs.copy(defaultDrizzleAuthPath, drizzleAuthPath); await fs.copy(defaultDrizzleAuthPath, drizzleAuthPath);
} }
const packageJsonPath = path.join(projectDir, "package.json");
if (await fs.pathExists(packageJsonPath)) {
const packageJson = await fs.readJson(packageJsonPath);
packageJson.scripts["db:push"] =
"cd packages/server && npx @better-auth/cli migrate";
packageJson.scripts["db:setup"] =
"npm run auth:generate && npm run db:push";
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
}
} }
} }
} catch (error) { } catch (error) {

View File

@@ -151,11 +151,11 @@ ${packageManagerRunCmd} auth:generate
? `Generate the Prisma client and push the schema: ? `Generate the Prisma client and push the schema:
\`\`\`bash \`\`\`bash
${packageManagerRunCmd} prisma:generate ${packageManagerRunCmd} prisma:generate
${packageManagerRunCmd} prisma:push ${packageManagerRunCmd} db:push
\`\`\`` \`\`\``
: `Apply the Drizzle migrations: : `Apply the Drizzle migrations:
\`\`\`bash \`\`\`bash
${packageManagerRunCmd} drizzle:migrate ${packageManagerRunCmd} db:push
\`\`\`` \`\`\``
} }
`; `;
@@ -183,7 +183,7 @@ function generateScriptsList(
if (orm === "prisma") { if (orm === "prisma") {
scripts += ` scripts += `
- \`${packageManagerRunCmd} prisma:generate\`: Generate Prisma client - \`${packageManagerRunCmd} prisma:generate\`: Generate Prisma client
- \`${packageManagerRunCmd} prisma:push\`: Push schema changes to database - \`${packageManagerRunCmd} db:push\`: Push schema changes to database
- \`${packageManagerRunCmd} prisma:studio\`: Open Prisma Studio`; - \`${packageManagerRunCmd} prisma:studio\`: Open Prisma Studio`;
} else if (orm === "drizzle") { } else if (orm === "drizzle") {
scripts += ` scripts += `

View File

@@ -19,21 +19,18 @@ export function displayPostInstallInstructions(
} }
if (hasAuth && database !== "none") { if (hasAuth && database !== "none") {
steps.push(`${pc.yellow("Authentication Setup:")}`); steps.push(`${pc.yellow("Database Setup:")}`);
steps.push(
`${pc.cyan("1.")} Generate auth schema: ${pc.green(`${runCmd} auth:generate`)}`,
);
if (orm === "prisma") { if (orm === "prisma") {
steps.push( steps.push(
`${pc.cyan("2.")} Generate Prisma client: ${pc.green(`${runCmd} prisma:generate`)}`, `${pc.cyan("1.")} Generate Prisma client: ${pc.green(`${runCmd} prisma:generate`)}`,
); );
steps.push( steps.push(
`${pc.cyan("3.")} Push schema to database: ${pc.green(`${runCmd} prisma:push`)}`, `${pc.cyan("2.")} Push schema to database: ${pc.green(`${runCmd} prisma:push`)}`,
); );
} else if (orm === "drizzle") { } else if (orm === "drizzle") {
steps.push( steps.push(
`${pc.cyan("2.")} Apply migrations: ${pc.green(`${runCmd} drizzle:migrate`)}`, `${pc.cyan("1.")} Apply migrations: ${pc.green(`${runCmd} db:push`)}`,
); );
} }
} }

View File

@@ -43,7 +43,7 @@ export default function UserMenu() {
className="w-full" className="w-full"
onClick={() => { onClick={() => {
navigate({ navigate({
to: "/sign-in", to: "/",
}); });
}} }}
> >