Skip to content

Commit a3f1850

Browse files
committed
feat(cli): Add manual connection string setup option for Neon database
1 parent 5b2827e commit a3f1850

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

.changeset/fair-streets-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": minor
3+
---
4+
5+
Add support for manual Neon setup with connection string

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ yarn-error.log*
3737
*.pem
3838
.vscode
3939
.env*.local
40+
.idea
4041

41-
.smoke
42+
.smoke

apps/cli/src/helpers/database-providers/neon-setup.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ import {
1212
type EnvVariable,
1313
} from "../project-generation/env-setup";
1414

15-
type NeonConfig = {
16-
connectionString: string;
17-
projectId: string;
18-
dbName: string;
19-
roleName: string;
20-
};
21-
2215
type NeonRegion = {
2316
label: string;
2417
value: string;
@@ -100,13 +93,13 @@ async function createNeonProject(
10093
}
10194
}
10295

103-
async function writeEnvFile(projectDir: string, config?: NeonConfig) {
96+
async function writeEnvFile(projectDir: string, connectionString?: string) {
10497
const envPath = path.join(projectDir, "apps/server", ".env");
10598
const variables: EnvVariable[] = [
10699
{
107100
key: "DATABASE_URL",
108101
value:
109-
config?.connectionString ??
102+
connectionString ??
110103
"postgresql://postgres:postgres@localhost:5432/mydb?schema=public",
111104
condition: true,
112105
},
@@ -174,6 +167,11 @@ export async function setupNeonPostgres(config: ProjectConfig) {
174167
value: "neonctl",
175168
hint: "More control - choose project name and region",
176169
},
170+
{
171+
label: "Manual setup",
172+
value: "manual",
173+
hint: "Enter connection string manually",
174+
}
177175
],
178176
initialValue: "neondb",
179177
});
@@ -182,7 +180,7 @@ export async function setupNeonPostgres(config: ProjectConfig) {
182180

183181
if (setupMethod === "neondb") {
184182
await setupWithNeonDb(projectDir, packageManager);
185-
} else {
183+
} else if (setupMethod === 'neonctl') {
186184
const suggestedProjectName = path.basename(projectDir);
187185
const projectName = await text({
188186
message: "Enter a name for your Neon project:",
@@ -215,9 +213,21 @@ export async function setupNeonPostgres(config: ProjectConfig) {
215213
finalSpinner.start("Configuring database connection");
216214

217215
await fs.ensureDir(path.join(projectDir, "apps/server"));
218-
await writeEnvFile(projectDir, neonConfig);
216+
await writeEnvFile(projectDir, neonConfig.connectionString);
219217

220218
finalSpinner.stop("Neon database configured!");
219+
} else if (setupMethod === "manual") {
220+
const connectionString = await text({
221+
message: "Enter your Neon connection string:",
222+
validate(value) {
223+
if (!value) return "Please enter a connection string";
224+
},
225+
});
226+
227+
if (isCancel(connectionString)) return exitCancelled("Operation cancelled");
228+
229+
await fs.ensureDir(path.join(projectDir, "apps/server"));
230+
await writeEnvFile(projectDir, connectionString);
221231
}
222232
} catch (error) {
223233
if (error instanceof Error) {

0 commit comments

Comments
 (0)