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

feat: add types to JSON columns in prisma schema #318

Merged
merged 12 commits into from
Jul 19, 2024

Conversation

karrui
Copy link
Contributor

@karrui karrui commented Jul 16, 2024

TL;DR

Added the prisma-json-types-generator module to the project and associated it with the JSON columns in the Prisma schema. This enables the usage of strongly typed JSON columns in the database.

What changed?

  • Added prisma-json-types-generator version ^3.0.4 to package.json and package-lock.json.
  • Updated schema.prisma to include a new generator for prisma-json-types-generator.
  • Added type annotations for JSON fields in various models.
  • Created a new types.ts file to define types for the JSON columns.
  • Updated various parts of the codebase to use the new strongly typed JSON fields.

How to test?

  1. Install the new dependencies by running npm install.
  2. Verify that the Prisma client is generated with the new JSON types by running npx prisma generate.
  3. Run the existing tests to ensure that no functionality is broken.
  4. Perform manual testing on forms that deal with JSON fields to ensure they are working correctly.

Why make this change?

This change enhances type safety and developer experience by enabling strongly typed JSON columns in the database. It also prepares the project for more advanced features that rely on typed JSON data.


Copy link

vercel bot commented Jul 16, 2024

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

Name Status Preview Comments Updated (UTC)
isomer-studio ❌ Failed (Inspect) Jul 19, 2024 7:51am

@karrui karrui changed the title fix: export types without type prefix from isomer-components feat: add types to JSON columns in prisma schema Jul 16, 2024
@karrui karrui marked this pull request as ready for review July 16, 2024 10:11
@karrui karrui requested a review from a team as a code owner July 16, 2024 10:11
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

lgtm, no real blockers on my end. not entirely sure if adding siteId to the query adds more value because it's a 1:N link atm but it does add more overhead now which i'm wary of

apps/studio/prisma/schema.prisma Show resolved Hide resolved
apps/studio/prisma/seed.ts Show resolved Hide resolved
Comment on lines +15 to +23
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace PrismaJson {
type SiteJsonConfig = _IsomerSiteConfigProps
type BlobJsonContent = _IsomerSchema
type NavbarJsonContent = _IsomerSiteWideComponentsProps["navBarItems"]
type FooterJsonContent = _IsomerSiteWideComponentsProps["footerItems"]
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i think @dcshzj had a point about how we had interfaces/types/schemas in our components codebase and

  1. interfaces were to only be used for our studio codebase to work w/ components
  2. types is a mix of schema and interfaces (i think???)
  3. schemas is what we guarantee on our end built site (is a contract between us and end user so we must alw sanitise w/ schema)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't get your point here in this comment. you missing the "so what" portion lol

apps/studio/src/schemas/page.ts Show resolved Hide resolved
@karrui
Copy link
Contributor Author

karrui commented Jul 17, 2024

lgtm, no real blockers on my end. not entirely sure if adding siteId to the query adds more value because it's a 1:N link atm but it does add more overhead now which i'm wary of

Huh, but you literally should query with siteId for correctness, no?

@karrui karrui force-pushed the add_types_to_prisma_schema branch from f693207 to 4817648 Compare July 19, 2024 07:49
@karrui karrui merged commit f169fec into main Jul 19, 2024
16 of 19 checks passed
@karrui karrui deleted the add_types_to_prisma_schema branch July 19, 2024 07:54
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