Skip to content
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

Merged
merged 14 commits into from
Mar 10, 2024

Conversation

joannechen1223
Copy link
Collaborator

@joannechen1223 joannechen1223 commented Mar 6, 2024

Description

  1. Create a Postgres RDS database in the dev elastic beanstalk environment.
  2. Introduce prisma to recnet-api as our db orm.
  3. Create db schema by prisma migration based on DB schema doc.
  4. Move buildspec.yml to the repository.
  5. Create an API GET /user/:handle just for dev testing purposes.
  6. Create a shared postman workspace.

Related Issue

Notes

N/A

TODO

  • Create development guide for how to do prisma migration

@joannechen1223 joannechen1223 requested a review from swh00tw March 6, 2024 05:21
Copy link

vercel bot commented Mar 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
rec-net ⬜️ Ignored (Inspect) Visit Preview Mar 8, 2024 5:12am

@swh00tw
Copy link
Collaborator

swh00tw commented Mar 8, 2024

I kinda fixed the nx-ignore script lol. See Canceled by Ignored Build Step. Now, it won't rebuild RecNet when there's no change to it.
Screenshot 2024-03-07 at 11 08 38 PM

Copy link
Collaborator

@swh00tw swh00tw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Comment on lines +6 to +12
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,
};
Copy link
Collaborator

@swh00tw swh00tw Mar 8, 2024

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@joannechen1223 joannechen1223 merged commit 2165f30 into recnet-api-dev Mar 10, 2024
3 checks passed
@joannechen1223 joannechen1223 deleted the connect-rds branch March 10, 2024 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants