Skip to content

Commit 30e16b5

Browse files
Add database setup scripts and fix navigation
1 parent b4274c7 commit 30e16b5

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

apps/cli/src/helpers/auth-setup.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ ${options.orm === "prisma" ? 'DATABASE_URL="file:./dev.db"' : ""}
127127
);
128128
await fs.writeFile(prismaAuthPath, authContent);
129129
}
130+
131+
const packageJsonPath = path.join(projectDir, "package.json");
132+
if (await fs.pathExists(packageJsonPath)) {
133+
const packageJson = await fs.readJson(packageJsonPath);
134+
135+
packageJson.scripts["prisma:generate"] =
136+
"cd packages/server && npx prisma generate";
137+
packageJson.scripts["prisma:push"] =
138+
"cd packages/server && npx prisma db push";
139+
packageJson.scripts["prisma:studio"] =
140+
"cd packages/server && npx prisma studio";
141+
packageJson.scripts["db:setup"] =
142+
"npm run auth:generate && npm run prisma:generate && npm run prisma:push";
143+
144+
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
145+
}
130146
} else if (options.orm === "drizzle") {
131147
const drizzleAuthPath = path.join(serverDir, "src/lib/auth.ts");
132148
const defaultDrizzleAuthPath = path.join(
@@ -141,6 +157,18 @@ ${options.orm === "prisma" ? 'DATABASE_URL="file:./dev.db"' : ""}
141157
await fs.ensureDir(path.dirname(drizzleAuthPath));
142158
await fs.copy(defaultDrizzleAuthPath, drizzleAuthPath);
143159
}
160+
161+
const packageJsonPath = path.join(projectDir, "package.json");
162+
if (await fs.pathExists(packageJsonPath)) {
163+
const packageJson = await fs.readJson(packageJsonPath);
164+
165+
packageJson.scripts["db:push"] =
166+
"cd packages/server && npx @better-auth/cli migrate";
167+
packageJson.scripts["db:setup"] =
168+
"npm run auth:generate && npm run db:push";
169+
170+
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
171+
}
144172
}
145173
}
146174
} catch (error) {

apps/cli/src/helpers/create-readme.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ ${packageManagerRunCmd} auth:generate
151151
? `Generate the Prisma client and push the schema:
152152
\`\`\`bash
153153
${packageManagerRunCmd} prisma:generate
154-
${packageManagerRunCmd} prisma:push
154+
${packageManagerRunCmd} db:push
155155
\`\`\``
156156
: `Apply the Drizzle migrations:
157157
\`\`\`bash
158-
${packageManagerRunCmd} drizzle:migrate
158+
${packageManagerRunCmd} db:push
159159
\`\`\``
160160
}
161161
`;
@@ -183,7 +183,7 @@ function generateScriptsList(
183183
if (orm === "prisma") {
184184
scripts += `
185185
- \`${packageManagerRunCmd} prisma:generate\`: Generate Prisma client
186-
- \`${packageManagerRunCmd} prisma:push\`: Push schema changes to database
186+
- \`${packageManagerRunCmd} db:push\`: Push schema changes to database
187187
- \`${packageManagerRunCmd} prisma:studio\`: Open Prisma Studio`;
188188
} else if (orm === "drizzle") {
189189
scripts += `

apps/cli/src/helpers/post-installation.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ export function displayPostInstallInstructions(
1919
}
2020

2121
if (hasAuth && database !== "none") {
22-
steps.push(`${pc.yellow("Authentication Setup:")}`);
23-
steps.push(
24-
`${pc.cyan("1.")} Generate auth schema: ${pc.green(`${runCmd} auth:generate`)}`,
25-
);
22+
steps.push(`${pc.yellow("Database Setup:")}`);
2623

2724
if (orm === "prisma") {
2825
steps.push(
29-
`${pc.cyan("2.")} Generate Prisma client: ${pc.green(`${runCmd} prisma:generate`)}`,
26+
`${pc.cyan("1.")} Generate Prisma client: ${pc.green(`${runCmd} prisma:generate`)}`,
3027
);
3128
steps.push(
32-
`${pc.cyan("3.")} Push schema to database: ${pc.green(`${runCmd} prisma:push`)}`,
29+
`${pc.cyan("2.")} Push schema to database: ${pc.green(`${runCmd} prisma:push`)}`,
3330
);
3431
} else if (orm === "drizzle") {
3532
steps.push(
36-
`${pc.cyan("2.")} Apply migrations: ${pc.green(`${runCmd} drizzle:migrate`)}`,
33+
`${pc.cyan("1.")} Apply migrations: ${pc.green(`${runCmd} db:push`)}`,
3734
);
3835
}
3936
}

apps/cli/template/base/packages/client/src/components/user-menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function UserMenu() {
4343
className="w-full"
4444
onClick={() => {
4545
navigate({
46-
to: "/sign-in",
46+
to: "/",
4747
});
4848
}}
4949
>

0 commit comments

Comments
 (0)