mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-01 11:56:43 -05:00
fix(cli): only show the overwrite message when the schema file exists and the code has changed (#3826)
This commit is contained in:
committed by
Bereket Engida
parent
772e6c78cc
commit
7c43ff0bf2
@@ -9,7 +9,7 @@ import prompts from "prompts";
|
||||
import fs from "fs/promises";
|
||||
import chalk from "chalk";
|
||||
import { getAdapter } from "better-auth/db";
|
||||
import { getGenerator } from "../generators";
|
||||
import { generateSchema } from "../generators";
|
||||
|
||||
export async function generateAction(opts: any) {
|
||||
const options = z
|
||||
@@ -45,7 +45,7 @@ export async function generateAction(opts: any) {
|
||||
|
||||
const spinner = yoctoSpinner({ text: "preparing schema..." }).start();
|
||||
|
||||
const schema = await getGenerator({
|
||||
const schema = await generateSchema({
|
||||
adapter,
|
||||
file: options.output,
|
||||
options: config,
|
||||
@@ -56,7 +56,7 @@ export async function generateAction(opts: any) {
|
||||
logger.info("Your schema is already up to date.");
|
||||
process.exit(0);
|
||||
}
|
||||
if (schema.append || schema.overwrite) {
|
||||
if (schema.overwrite) {
|
||||
let confirm = options.y || options.yes;
|
||||
if (!confirm) {
|
||||
const response = await prompts({
|
||||
|
||||
@@ -15,6 +15,7 @@ export const generatePrismaSchema: SchemaGenerator = async ({
|
||||
const tables = getAuthTables(options);
|
||||
const filePath = file || "./prisma/schema.prisma";
|
||||
const schemaPrismaExist = existsSync(path.join(process.cwd(), filePath));
|
||||
|
||||
let schemaPrisma = "";
|
||||
if (schemaPrismaExist) {
|
||||
schemaPrisma = await fs.readFile(
|
||||
@@ -222,10 +223,12 @@ export const generatePrismaSchema: SchemaGenerator = async ({
|
||||
}
|
||||
});
|
||||
|
||||
const schemaChanged = schema.trim() !== schemaPrisma.trim();
|
||||
|
||||
return {
|
||||
code: schema.trim() === schemaPrisma.trim() ? "" : schema,
|
||||
code: schemaChanged ? schema : "",
|
||||
fileName: filePath,
|
||||
overwrite: true,
|
||||
overwrite: schemaPrismaExist && schemaChanged,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user