feat: Add database

This commit is contained in:
Wanjohi
2025-09-19 01:25:29 +03:00
parent 6bd17a4d5f
commit 639616ce73
13 changed files with 77 additions and 146 deletions

View File

View File

45
cloud/infra/database.ts Normal file
View File

@@ -0,0 +1,45 @@
const dbProject = neon.getProjectOutput({
id: "curly-fire-59112557",
});
const dbBranchId =
$app.stage !== "production"
? new neon.Branch("NeonBranch", {
parentId: dbProject.defaultBranchId,
projectId: dbProject.id,
name: $app.stage,
}).id
: dbProject.defaultBranchId;
const dbEndpoint = new neon.Endpoint("NeonEndpoint", {
projectId: dbProject.id,
branchId: dbBranchId,
poolerEnabled: true,
type: "read_write",
});
const dbRole = new neon.Role("NeonRole", {
name: `nestri-${$app.stage}-role`,
branchId: dbBranchId,
projectId: dbProject.id,
});
const db = new neon.Database(
"NeonDatabase",
{
branchId: dbBranchId,
projectId: dbProject.id,
ownerName: dbRole.name,
name: `nestri-${$app.stage}`,
},
{ dependsOn: [dbRole] },
);
export const database = new sst.Linkable("Database", {
properties: {
name: db.name,
user: dbRole.name,
host: dbEndpoint.host,
password: dbRole.password,
},
});

View File

View File

@@ -3,7 +3,7 @@
/* eslint-disable */
/* deno-fmt-ignore-file */
/// <reference path="../../sst-env.d.ts" />
/// <reference path="../../../sst-env.d.ts" />
import "sst"
export {}

View File

@@ -3,7 +3,7 @@
/* eslint-disable */
/* deno-fmt-ignore-file */
/// <reference path="../../sst-env.d.ts" />
/// <reference path="../../../sst-env.d.ts" />
import "sst"
export {}

View File

@@ -3,7 +3,7 @@
/* eslint-disable */
/* deno-fmt-ignore-file */
/// <reference path="../../sst-env.d.ts" />
/// <reference path="../../../sst-env.d.ts" />
import "sst"
export {}