Skip to content

Conversation

mohitb35
Copy link
Collaborator

@mohitb35 mohitb35 commented Jan 14, 2025

Updates trpc + prisma code used for my forest to use postgres instead of mysql

Tasks

  • update prisma schema and setup code
  • update trpc procedures to use postgres
    • projectList
    • contributions
    • leaderboard
    • fetching group profile data
  • Test MyForest with different accounts

Pending -

Copy link

vercel bot commented Jan 14, 2025

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

Name Status Preview Comments Updated (UTC)
planet-webapp-multi-tenancy-setup 🛑 Canceled (Inspect) 💬 Add feedback Jan 17, 2025 2:26pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
planet-webapp ⬜️ Ignored (Inspect) Jan 17, 2025 2:26pm
planet-webapp-temp ⬜️ Ignored (Inspect) Jan 17, 2025 2:26pm

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Caution

Review failed

The pull request is closed.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: eslint-config-airbnb@18.2.1
npm error Found: eslint@8.57.1
npm error node_modules/eslint
npm error dev eslint@"^8.26.0" from the root project
npm error peer eslint@"6 || 7 || 8" from @emotion/eslint-plugin@11.12.0
npm error node_modules/@emotion/eslint-plugin
npm error dev @emotion/eslint-plugin@"^11.12.0" from the root project
npm error 15 more (@eslint-community/eslint-utils, ...)
npm error
npm error Could not resolve dependency:
npm error peer eslint@"^5.16.0 || ^6.8.0 || ^7.2.0" from eslint-config-airbnb@18.2.1
npm error node_modules/eslint-config-airbnb
npm error dev eslint-config-airbnb@"^18.2.0" from the root project
npm error
npm error Conflicting peer dependency: eslint@7.32.0
npm error node_modules/eslint
npm error peer eslint@"^5.16.0 || ^6.8.0 || ^7.2.0" from eslint-config-airbnb@18.2.1
npm error node_modules/eslint-config-airbnb
npm error dev eslint-config-airbnb@"^18.2.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /root/.npm/_logs/2025-01-17T14_28_48_770Z-eresolve-report.txt
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-01-17T14_28_48_770Z-debug-0.log

Walkthrough

This pull request focuses on migrating the database from MySQL to PostgreSQL in the Prisma schema. The changes involve updating the database provider and modifying data types across multiple models, including contribution, profile, gift, and project. The SQL queries in various server-side procedures have been adjusted to align with PostgreSQL syntax, including case-sensitive identifier handling, JSON path modifications, and type casting for numerical calculations. Additionally, the database connection logic has been overhauled to utilize a new query execution method.

Changes

File Change Summary
prisma/schema.prisma - Switched database provider from MySQL to PostgreSQL
- Updated DateTime fields to use @db.Timestamp(0) in contribution, profile, and gift models
- Changed description and location fields in project model from @db.LongText to @db.Text
src/server/procedures/myForest/contributions.ts - Added double quotes for case-sensitive field names in SQL queries
- Updated field references in fetchContributions and fetchGifts functions
src/server/procedures/myForest/leaderboard.ts - Modified JSON path for giverName
- Updated quantity calculations using CAST(value AS NUMERIC)
- Adjusted GROUP BY and ORDER BY clauses
src/server/procedures/myForest/projectList.ts - Changed JSON path notation
- Updated boolean checks to use IS TRUE
- Modified column aliases
src/server/utils/fetchProfileGroupData.ts - Updated profileId column alias to use double quotes
pages/api/data-explorer/export.ts - Changed import from db to query
- Updated SQL query to use parameterized queries with $1, $2, etc.
pages/api/data-explorer/map/distinct-species/[projectId].ts - Changed import from db to query
- Updated SQL query to use parameterized queries
pages/api/data-explorer/map/plant-location/[plantLocationId].ts - Changed import from db to query
- Updated SQL query construction and execution
pages/api/data-explorer/map/plant-location/index.ts - Changed geometry type to `Point
pages/api/data-explorer/map/sites/[projectId].ts - Changed import from db to query
- Updated SQL query execution method
pages/api/data-explorer/species-planted.ts - Changed import from db to query
- Updated SQL query to use parameterized queries
pages/api/data-explorer/total-species-planted.ts - Changed import from db to query
- Updated SQL query to use parameterized queries
pages/api/data-explorer/total-trees-planted.ts - Changed import from db to query
- Updated SQL query to use parameterized queries
pages/api/data-explorer/trees-planted.ts - Changed import from db to query
- Updated SQL queries for time frames with CTEs
src/features/common/types/dataExplorer.d.ts - Updated geometry types in multiple interfaces to `Point
src/utils/connectDB.ts - Overhauled database connection logic to use serverless-postgres
- Introduced new interfaces for database configuration and query results

Sequence Diagram

sequenceDiagram
    participant Client
    participant Server
    participant PostgreSQL
    
    Client->>Server: Request data
    Server->>PostgreSQL: Execute modified SQL query
    PostgreSQL-->>Server: Return results with PostgreSQL-specific handling
    Server-->>Client: Respond with processed data
Loading

Possibly related PRs

Suggested Labels

MyForest 2.0, projects redesign

Suggested Reviewers

  • sunilsabatp
  • mariahosfeld

Poem

🐰 Hopping from MySQL to Postgres' embrace,
Timestamps dance with newfound grace.
Queries refined, data types align,
A database migration, simply divine!
Code hops forward, no looking back! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2646a5 and b2aba1e.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • package.json is excluded by !**/*.json
📒 Files selected for processing (12)
  • pages/api/data-explorer/export.ts (2 hunks)
  • pages/api/data-explorer/map/distinct-species/[projectId].ts (3 hunks)
  • pages/api/data-explorer/map/plant-location/[plantLocationId].ts (1 hunks)
  • pages/api/data-explorer/map/plant-location/index.ts (3 hunks)
  • pages/api/data-explorer/map/sites/[projectId].ts (3 hunks)
  • pages/api/data-explorer/species-planted.ts (3 hunks)
  • pages/api/data-explorer/total-species-planted.ts (3 hunks)
  • pages/api/data-explorer/total-trees-planted.ts (3 hunks)
  • pages/api/data-explorer/trees-planted.ts (3 hunks)
  • src/features/common/types/dataExplorer.d.ts (7 hunks)
  • src/features/user/TreeMapper/Analytics/components/TreePlanted/index.tsx (1 hunks)
  • src/utils/connectDB.ts (1 hunks)

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mohitb35 mohitb35 force-pushed the feature/db-postgres-adaptations branch from 07c1148 to 0b26415 Compare January 15, 2025 04:27
@mariahosfeld
Copy link
Contributor

Looking good so far for profiles.

- replace `serverless-mysql` with `serverless-postgres`
- set up `query` helper function with connection lifecycle management
- add TypeScript interfaces for database responses
- configure debug mode for local development

This changes how database connections are handled:
- explicit connect() before queries
- clean() after queries for proper resource cleanup
@mohitb35 mohitb35 marked this pull request as ready for review January 16, 2025 12:19
@mohitb35 mohitb35 changed the title Migrate database schema and procedures to PostgreSQL Migrate database schema and trpc procedures to PostgreSQL Jan 17, 2025
@mohitb35 mohitb35 merged commit 2b10701 into develop Jan 17, 2025
6 of 8 checks passed
@mohitb35 mohitb35 deleted the feature/db-postgres-adaptations branch January 17, 2025 14:26
@vercel vercel bot temporarily deployed to Preview – planet-webapp-multi-tenancy-setup January 17, 2025 14:26 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants