-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[recnet-api] Connect environment to rds database and generate DB schema #160
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
a8a7fa8
to
7306579
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add down migration file down.sql
for each up migration?
Docs: https://www.prisma.io/docs/orm/prisma-migrate/workflows/generating-down-migrations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, I will create another PR to add it.
const postgresConfig = { | ||
host: process.env.RDS_HOSTNAME, | ||
port: parseInt(process.env.RDS_PORT, 10), | ||
database: process.env.RDS_DB_NAME, | ||
username: process.env.RDS_USERNAME, | ||
password: process.env.RDS_PASSWORD, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]: you can use zod
to parse the process.env. For example:
import { z } from "zod"
const PostgreConfigSchema = z.object({
host: z.string(),
port: z.number(),
database: z.string(),
username: z.string(),
password: z.string(),
})
const postgresConfig = PostgreConfigSchema.parse(process.env)
The error message would be better since zod
would tell you which field exactly is invalid or unexpected, instead of error like this PrismaClientInitializationError: The provided database string is invalid. Error parsing connection string: invalid port number in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
It makes it easier to debug if any env var is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing apply to process.env.DB_MIGRATE
& process.env.PRISMA_SCHEMA
. Personally, I always use zod
to parse the whole env variables, use EnvSchema
or something to prevent me directly accessing the process.env
, it's error-prone and easy to have typos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to use the config service provided by nestJS to deal with these configs. I will create another PR to enhance the configuration management and will consider to take in this advice.
Description
GET /user/:handle
just for dev testing purposes.Related Issue
Notes
N/A
TODO