fix: update database switching to modify schema file directly
This commit is contained in:
@@ -16,7 +16,7 @@ function checkPostgresConnection() {
|
||||
console.error('❌ DATABASE_URL is not set for PostgreSQL');
|
||||
console.error('Please update your .env file with:');
|
||||
console.error('DATABASE_PROVIDER=postgresql');
|
||||
console.error('DATABASE_URL="postgresql://username:password@localhost:5432/euchre_camp"');
|
||||
console.error('DATABASE_URL="postgresql://euchre_camp:o_7urWjkvPfsE1Q*@localhost:5432/euchre_camp"');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ function updateEnvFile(provider) {
|
||||
envContent = fs.readFileSync(envExampleFile, 'utf8');
|
||||
}
|
||||
|
||||
// Update DATABASE_PROVIDER
|
||||
// Update DATABASE_PROVIDER (note: this is for reference only, not used by Prisma)
|
||||
const providerRegex = /^DATABASE_PROVIDER=.*$/m;
|
||||
if (providerRegex.test(envContent)) {
|
||||
envContent = envContent.replace(providerRegex, `DATABASE_PROVIDER=${provider}`);
|
||||
@@ -54,6 +54,33 @@ function updateEnvFile(provider) {
|
||||
console.log(`✅ Updated ${envFile} to use ${provider} database`);
|
||||
}
|
||||
|
||||
function updateSchemaFile(provider) {
|
||||
const schemaPath = path.join(process.cwd(), 'prisma', 'schema.prisma');
|
||||
|
||||
if (!fs.existsSync(schemaPath)) {
|
||||
console.error(`❌ Schema file not found: ${schemaPath}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let schemaContent = fs.readFileSync(schemaPath, 'utf8');
|
||||
|
||||
// Update the provider in the datasource block
|
||||
const providerRegex = /(datasource db\s*\{[^}]*provider\s*=\s*)"[^"]+"/;
|
||||
if (providerRegex.test(schemaContent)) {
|
||||
schemaContent = schemaContent.replace(
|
||||
providerRegex,
|
||||
`$1"${provider}"`
|
||||
);
|
||||
|
||||
fs.writeFileSync(schemaPath, schemaContent);
|
||||
console.log(`✅ Updated schema.prisma to use ${provider} provider`);
|
||||
return true;
|
||||
} else {
|
||||
console.error(`❌ Could not find provider declaration in schema.prisma`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const provider = args[0];
|
||||
@@ -70,6 +97,7 @@ function main() {
|
||||
|
||||
const normalizedProvider = provider === 'postgres' ? 'postgresql' : provider;
|
||||
updateEnvFile(normalizedProvider);
|
||||
updateSchemaFile(normalizedProvider);
|
||||
|
||||
console.log('\nNext steps:');
|
||||
console.log('1. Run: npx prisma generate');
|
||||
|
||||
Reference in New Issue
Block a user