mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
🐜 fix(db): Fix database state issues (#203)
## Description This attempts to fix all database issues for all teammates ## Related Issues 1. Getting funny errors while trying to run `sst dev` 2. The neon pulumi stuff trying to create a db each time on push ## Type of Change - [x] Bug fix (non-breaking change) - [ ] New feature (non-breaking change) - [ ] Breaking change (fix or feature that changes existing functionality) - [ ] Documentation update - [ ] Other (please describe): ## Checklist - [ ] I have updated relevant documentation - [ ] My code follows the project's coding style - [x] My changes generate no new warnings/errors ## Notes for Reviewers <!-- Point out areas you'd like reviewers to focus on, questions you have, or decisions that need discussion --> ## Screenshots/Demo <!-- If applicable, add screenshots or a GIF demo of your changes (especially for UI changes) --> ## Additional Context <!-- Add any other context about the pull request here -->
This commit is contained in:
@@ -1,27 +1,29 @@
|
|||||||
//Created manually from the dashboard and shared with the whole team/org
|
//Created manually from the dashboard and shared with the whole team/org
|
||||||
const dbProject = neon.getProjectOutput({
|
const dbProject = neon.getProjectOutput({
|
||||||
id:"red-mud-17843368"
|
id: "little-band-76544985",
|
||||||
})
|
})
|
||||||
|
|
||||||
const dbBranchId = $app.stage !== "production" ?
|
const dbBranchId = $app.stage !== "production" ?
|
||||||
new neon.Branch("DatabaseBranch", {
|
new neon.Branch("NeonBranch", {
|
||||||
parentId: dbProject.defaultBranchId,
|
parentId: dbProject.defaultBranchId,
|
||||||
projectId: dbProject.id,
|
projectId: dbProject.id,
|
||||||
name: $app.stage,
|
name: $app.stage,
|
||||||
}).id : dbProject.defaultBranchId
|
}).id : dbProject.defaultBranchId
|
||||||
|
|
||||||
const dbEndpoint = new neon.Endpoint("NestriEndpoint", {
|
const dbEndpoint = new neon.Endpoint("NeonEndpoint", {
|
||||||
projectId: dbProject.id,
|
projectId: dbProject.id,
|
||||||
branchId: dbBranchId
|
branchId: dbBranchId,
|
||||||
|
poolerEnabled: true,
|
||||||
|
type: "read_write",
|
||||||
})
|
})
|
||||||
|
|
||||||
const dbRole = new neon.Role("AdminRole", {
|
const dbRole = new neon.Role("NeonRole", {
|
||||||
name: "admin",
|
name: "admin",
|
||||||
branchId: dbBranchId,
|
branchId: dbBranchId,
|
||||||
projectId: dbProject.id,
|
projectId: dbProject.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
const db = new neon.Database("NestriDatabase", {
|
const db = new neon.Database("NeonDatabase", {
|
||||||
branchId: dbBranchId,
|
branchId: dbBranchId,
|
||||||
projectId: dbProject.id,
|
projectId: dbProject.id,
|
||||||
ownerName: dbRole.name,
|
ownerName: dbRole.name,
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import { Resource } from "sst";
|
import { Resource } from "sst";
|
||||||
import { defineConfig } from "drizzle-kit";
|
import { defineConfig } from "drizzle-kit";
|
||||||
|
|
||||||
|
function addPoolerSuffix(original: string): string {
|
||||||
|
const firstDotIndex = original.indexOf('.');
|
||||||
|
if (firstDotIndex === -1) return original + '-pooler';
|
||||||
|
return original.slice(0, firstDotIndex) + '-pooler' + original.slice(firstDotIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dbHost = addPoolerSuffix(Resource.Database.host)
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
schema: "./src/**/*.sql.ts",
|
schema: "./src/**/*.sql.ts",
|
||||||
out: "./migrations",
|
out: "./migrations",
|
||||||
dialect: "postgresql",
|
dialect: "postgresql",
|
||||||
verbose: true,
|
verbose: true,
|
||||||
dbCredentials: {
|
dbCredentials: {
|
||||||
url: `postgresql://${Resource.Database.user}:${Resource.Database.password}@${Resource.Database.host}/${Resource.Database.name}?sslmode=require`,
|
url: `postgresql://${Resource.Database.user}:${Resource.Database.password}@${dbHost}/${Resource.Database.name}?sslmode=require`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -7,7 +7,15 @@ import { Pool, neonConfig } from "@neondatabase/serverless";
|
|||||||
|
|
||||||
neonConfig.webSocketConstructor = ws;
|
neonConfig.webSocketConstructor = ws;
|
||||||
|
|
||||||
const client = new Pool({ connectionString: `postgres://${Resource.Database.user}:${Resource.Database.password}@${Resource.Database.host}/${Resource.Database.name}?sslmode=require` })
|
function addPoolerSuffix(original: string): string {
|
||||||
|
const firstDotIndex = original.indexOf('.');
|
||||||
|
if (firstDotIndex === -1) return original + '-pooler';
|
||||||
|
return original.slice(0, firstDotIndex) + '-pooler' + original.slice(firstDotIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dbHost = addPoolerSuffix(Resource.Database.host)
|
||||||
|
|
||||||
|
const client = new Pool({ connectionString: `postgres://${Resource.Database.user}:${Resource.Database.password}@${dbHost}/${Resource.Database.name}?sslmode=require` })
|
||||||
|
|
||||||
export const db = neonDrizzle(client, {
|
export const db = neonDrizzle(client, {
|
||||||
logger:
|
logger:
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ const app = issuer({
|
|||||||
PasswordUI({
|
PasswordUI({
|
||||||
sendCode: async (email, code) => {
|
sendCode: async (email, code) => {
|
||||||
console.log("email & code:", email, code)
|
console.log("email & code:", email, code)
|
||||||
await Email.send(
|
// await Email.send(
|
||||||
"auth",
|
// "auth",
|
||||||
email,
|
// email,
|
||||||
`Nestri code: ${code}`,
|
// `Nestri code: ${code}`,
|
||||||
`Your Nestri login code is ${code}`,
|
// `Your Nestri login code is ${code}`,
|
||||||
)
|
// )
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user