Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Upgrade to Redwood v0.36.2 #8

Closed
wants to merge 9 commits into from
Closed

Upgrade to Redwood v0.36.2 #8

wants to merge 9 commits into from

Conversation

ajcwebdev
Copy link

@ajcwebdev ajcwebdev commented Sep 2, 2021

What type of PR is this? (check all applicable)

  • ♻️ Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 👷 Optimization
  • 📝 Documentation Update
  • 🔖 Release
  • 🚩 Other

Description

This PR updates the project from Redwood v0.24.0 to v0.36.2. Over the course of these releases we saw the following changes to the framework:

Related Tickets & Documents

Connection pooling with Supabase

In a serverless environment you need to set up connection pooling with a tool like PgBouncer because every function invocation may result in a new connection to the database. Supabase projects now support connection management using PgBouncer and are enabled by default. However, when running migrations you need to use the non pooled connection URL.

postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:5432/postgres

When deploying your app, you'll use the pooled connection URL and add the ?pgbouncer=true flag to the PostgreSQL connection URL.

postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:6543/postgres?pgbouncer=true

This is a problem for Prisma, as explained by Mahmoud Abdelwahab:

Prisma Migrate uses database transactions to check out the current state of the database and the migrations table. However, the Migration Engine is designed to use a single connection to the database, and does not support connection pooling with PgBouncer. If you attempt to run Prisma Migrate commands in any environment that uses PgBouncer for connection pooling, you might see the following error:

Error: undefined: Database error
Error querying the database: db error: ERROR: prepared statement "s0" already exists

There is an open issue for this on Prisma's GitHub and another issue explaining the problem in more detail.

Mobile & Desktop Screenshots/Recordings

Since PgBouncer was causing issues I tried disabling the Supabase client and connecting the project to a PostgreSQL database on Railway.

Screen Shot 2021-09-01 at 9 28 44 PM

Screen Shot 2021-09-01 at 9 29 43 PM

Screen Shot 2021-09-01 at 9 31 20 PM

Screen Shot 2021-09-01 at 9 31 59 PM

Added tests?

I am the one who tests.

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added to documentation?

These are all internal implementation details and from the perspective of an Open Sauced user there should be no change in the behavior of the application.

  • 📜 readme
  • 📜 contributing.md
  • 📓 docs
  • 📕 storybook
  • 🙅 no documentation needed

Are there any post-deployment tasks we need to perform?

Make sure you can connect to Supabase without any weird PgBouncer issues. See previous links for context and workarounds.

What gif best describes this PR or how it makes you feel?

spongebob-hard-days-work-at-the-krusty-krab

@netlify
Copy link

netlify bot commented Sep 2, 2021

👷 Deploy request for flava-flav accepted.

🔨 Explore the source changes: 848fa6d

🔍 Inspect the deploy log: https://app.netlify.com/sites/flava-flav/deploys/61305daee156f6000831f63d

@ajcwebdev
Copy link
Author

PR is currently in draft until Brian can test it out with his own db credentials and verify it works.

@ajcwebdev
Copy link
Author

ajcwebdev commented Sep 5, 2021

Instructions for setting up and testing a Supabase database

Create .env file

touch .env

You'll need the following variables

DATABASE_URL=
SUPABASE_URL=
SUPABASE_KEY=
SUPABASE_JWT_SECRET=

If you check the API tab under settings you'll see:

  • Project API keys which is SUPABASE_KEY
  • URL which is SUPABASE_URL
  • JWT Secret which is SUPABASE_JWT_SECRET

The following screenshots are from a project that has been deleted and all keys are invalid

Screen Shot 2021-09-04 at 5 33 44 PM

You can find a connection string under the Connection Pooling tab, and this is where I hit an error.

Screen Shot 2021-09-04 at 5 35 19 PM

If you take the connection string provided you need to append ?sslmode=require&pgbouncer=true like so:

postgresql://postgres:mydb.supabase.co:6543/postgres?sslmode=require&pgbouncer=true

But that leads to the Prisma Migration errors I mentioned when I originally opened the PR. According to the Redwood docs currently being written about this, we want something like:

postgresql://postgres:mydb.supabase.co:5432/postgres?sslmode=require

Once all the variables are provided you will run the following Prisma Migrate command after installing dependencies:

yarn
yarn rw prisma migrate dev --name i-want-pizza

Start the development server

yarn rw dev

Go to localhost:8911/graphql and run the following mutation

mutation CreateRepositoryMutation($input: CreateRepositoryInput!) {
  createRepository(input: $input) {
    id
  }
}

With the following query variables

{
  "input": {
    "githubId": 1,
    "fullName": "test"
  }
}

Return to localhost:8910 to see the results.

@ajcwebdev ajcwebdev marked this pull request as ready for review September 8, 2021 22:10
@bdougie
Copy link
Member

bdougie commented Sep 8, 2021

Checked out on the stream. I think this is good, barring the weird dashboard error.

@ajcwebdev
Copy link
Author

ajcwebdev commented Sep 8, 2021

Netlify build error

9:43:31 AM: ────────────────────────────────────────────────────────────────
9:43:31 AM:   1. build.command from netlify.toml                            
9:43:31 AM: ────────────────────────────────────────────────────────────────
9:43:31 AM: ​
9:43:31 AM: $ yarn rw deploy netlify
9:43:31 AM: yarn run v1.22.4
9:43:31 AM: $ /opt/build/repo/node_modules/.bin/rw deploy netlify
9:43:32 AM: internal/modules/cjs/loader.js:892
9:43:32 AM:   throw err;
9:43:32 AM:   ^
9:43:32 AM: Error: Cannot find module '@ardatan/aggregate-error'
9:43:32 AM: Require stack:
9:43:32 AM: - /opt/build/repo/node_modules/@graphql-tools/schema/node_modules/@graphql-tools/utils/index.cjs.js
9:43:32 AM: - /opt/build/repo/node_modules/@graphql-tools/schema/index.js
9:43:32 AM: - /opt/build/repo/node_modules/@graphql-tools/load/index.js
9:43:32 AM: - /opt/build/repo/node_modules/graphql-config/index.js
9:43:32 AM: - /opt/build/repo/node_modules/@graphql-codegen/cli/index.cjs.js
9:43:32 AM: - /opt/build/repo/node_modules/@redwoodjs/internal/dist/generate/graphqlSchema.js
9:43:32 AM: - /opt/build/repo/node_modules/@redwoodjs/internal/dist/generate/generate.js
9:43:32 AM: - /opt/build/repo/node_modules/@redwoodjs/internal/dist/index.js
9:43:32 AM: - /opt/build/repo/node_modules/@redwoodjs/cli/dist/index.js
9:43:32 AM:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
9:43:32 AM:     at Function.Module._load (internal/modules/cjs/loader.js:745:27)
9:43:32 AM:     at Module.require (internal/modules/cjs/loader.js:961:19)
9:43:32 AM:     at require (internal/modules/cjs/helpers.js:92:18)
9:43:32 AM:     at Object.<anonymous> (/opt/build/repo/node_modules/@graphql-tools/schema/node_modules/@graphql-tools/utils/index.cjs.js:8:40)
9:43:32 AM:     at Module._compile (internal/modules/cjs/loader.js:1072:14)
9:43:32 AM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
9:43:32 AM:     at Module.load (internal/modules/cjs/loader.js:937:32)
9:43:32 AM:     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
9:43:32 AM:     at Module.require (internal/modules/cjs/loader.js:961:19) {
9:43:32 AM:   code: 'MODULE_NOT_FOUND',
9:43:32 AM:   requireStack: [
9:43:32 AM:     '/opt/build/repo/node_modules/@graphql-tools/schema/node_modules/@graphql-tools/utils/index.cjs.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@graphql-tools/schema/index.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@graphql-tools/load/index.js',
9:43:32 AM:     '/opt/build/repo/node_modules/graphql-config/index.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@graphql-codegen/cli/index.cjs.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@redwoodjs/internal/dist/generate/graphqlSchema.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@redwoodjs/internal/dist/generate/generate.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@redwoodjs/internal/dist/index.js',
9:43:32 AM:     '/opt/build/repo/node_modules/@redwoodjs/cli/dist/index.js'
9:43:32 AM:   ]
9:43:32 AM: }
9:43:32 AM: error Command failed with exit code 1.
9:43:32 AM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
9:43:32 AM: ​
9:43:32 AM: ────────────────────────────────────────────────────────────────
9:43:32 AM:   "build.command" failed                                        
9:43:32 AM: ────────────────────────────────────────────────────────────────
9:43:32 AM: ​
9:43:32 AM:   Error message
9:43:32 AM:   Command failed with exit code 1: yarn rw deploy netlify
9:43:32 AM: ​
9:43:32 AM:   Error location
9:43:32 AM:   In build.command from netlify.toml:
9:43:32 AM:   yarn rw deploy netlify
9:43:32 AM: ​
9:43:32 AM:   Resolved config
9:43:32 AM:   build:
9:43:32 AM:     command: yarn rw deploy netlify
9:43:32 AM:     commandOrigin: config
9:43:32 AM:     environment:
9:43:32 AM:       - DATABASE_URL
9:43:32 AM:       - REVIEW_ID
9:43:32 AM:       - SUPABASE_JWT_SECRET
9:43:32 AM:       - SUPABASE_KEY
9:43:32 AM:       - SUPABASE_URL
9:43:32 AM:     publish: /opt/build/repo/web/dist
9:43:32 AM:     publishOrigin: config
9:43:32 AM:   functionsDirectory: /opt/build/repo/api/dist/functions
9:43:32 AM:   redirects:
9:43:33 AM:     - from: /*
      status: 200
      to: /index.html
  redirectsOrigin: config
Caching artifacts

Looks like the same error we got on stream when we needed to delete and reinstall node_modules. Clearing the build cache should work.

@ajcwebdev
Copy link
Author

12:54:51 PM: $ /opt/build/repo/node_modules/.bin/rw prisma migrate deploy
12:54:54 PM: Running Prisma CLI...
12:54:54 PM: $ yarn prisma migrate deploy --schema "/opt/build/repo/api/db/schema.prisma"
12:54:55 PM: Prisma schema loaded from api/db/schema.prisma
12:54:55 PM: Datasource "DS": PostgreSQL database "postgres", schema "public" at "db.yndwjtnickdixvlpvjnn.supabase.co:5432"
12:54:55 PM: Error: P1000: Authentication failed against database server at `db.yndwjtnickdixvlpvjnn.supabase.co`, the provided database credentials for `postgres` are not valid.
12:54:55 PM: Please make sure to provide valid database credentials for the database server at `db.yndwjtnickdixvlpvjnn.supabase.co`.
12:54:56 PM: error Command failed with exit code 1.
12:54:56 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:54:56 PM: rw deploy netlify [...commands]
12:54:56 PM: Build command for Netlify deploy
12:54:56 PM: Options:
12:54:56 PM:   --help                Show help                                      [boolean]
12:54:56 PM:   --version             Show version number                            [boolean]
12:54:56 PM:   --cwd                 Working directory to use (where `redwood.toml` is
12:54:56 PM:                         located.)
12:54:56 PM:   --build               Build for production         [boolean] [default: "true"]
12:54:56 PM:   --prisma              Apply database migrations    [boolean] [default: "true"]
12:54:56 PM:   --data-migrate, --dm  Migrate the data in your database
12:54:56 PM:                                                      [boolean] [default: "true"]
12:54:56 PM: For more commands, options, and examples, see Redwood CLI Reference
12:54:56 PM: (​https://redwoodjs.com/docs/cli-commands#deploy​)
12:54:56 PM: Error: Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up
12:54:56 PM:     at makeError (/opt/build/repo/node_modules/execa/lib/error.js:60:11)
12:54:56 PM:     at handlePromise (/opt/build/repo/node_modules/execa/index.js:118:26)
12:54:56 PM:     at processTicksAndRejections (internal/process/task_queues.js:95:5) {
12:54:56 PM:   shortMessage: 'Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up',
12:54:56 PM:   command: 'yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up',
12:54:56 PM:   escapedCommand: '"yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up"',
12:54:56 PM:   exitCode: 1,
12:54:56 PM:   signal: undefined,
12:54:56 PM:   signalDescription: undefined,
12:54:56 PM:   stdout: undefined,
12:54:56 PM:   stderr: undefined,
12:54:56 PM:   failed: true,
12:54:56 PM:   timedOut: false,
12:54:56 PM:   isCanceled: false,
12:54:56 PM:   killed: false
12:54:56 PM: }
12:54:56 PM: error Command failed with exit code 1.
12:54:56 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:54:56 PM: ​
12:54:56 PM: ────────────────────────────────────────────────────────────────
12:54:56 PM:   "build.command" failed                                        
12:54:56 PM: ────────────────────────────────────────────────────────────────
12:54:56 PM: ​
12:54:56 PM:   Error message
12:54:56 PM:   Command failed with exit code 1: yarn rw deploy netlify
12:54:56 PM: ​
12:54:56 PM:   Error location
12:54:56 PM:   In build.command from netlify.toml:
12:54:56 PM:   yarn rw deploy netlify
12:54:56 PM: ​
12:54:56 PM:   Resolved config
12:54:56 PM:   build:
12:54:56 PM:     command: yarn rw deploy netlify
12:54:56 PM:     commandOrigin: config
12:54:56 PM:     environment:
12:54:56 PM:       - DATABASE_URL
12:54:56 PM:       - REVIEW_ID
12:54:56 PM:       - SUPABASE_JWT_SECRET
12:54:56 PM:       - SUPABASE_KEY
12:54:56 PM:       - SUPABASE_URL
12:54:56 PM:     publish: /opt/build/repo/web/dist
12:54:56 PM:     publishOrigin: config
12:54:56 PM:   functionsDirectory: /opt/build/repo/api/dist/functions
12:54:56 PM:   redirects:
12:54:56 PM:     - from: /*
      status: 200
      to: /index.html
  redirectsOrigin: config

Supabase error this time, will want to check environment variables.

@ajcwebdev
Copy link
Author

Had another Redwood dev reach out about this bug cause they were running into it as well. Said they figured it out in the netlify.toml:

command = "DATABASE_URL=$MIGRATE_DB_URL yarn rw deploy netlify"

$MIGRATE_DB_URL is an environment variable on netlify MIGRATE_DB_URL.

@ajcwebdev
Copy link
Author

ajcwebdev commented Mar 3, 2022

Gonna close this issue out. Redwood's up to v0.47 and it sounds like we're gonna be rethinking what we want to do with Redwood anyway. At this point it would make the most sense to create a new Redwood app in a month or two that's using v1 or if we want to start building before then we can pin to v1-rc. If there's any major functionality here that we want to preserve I can migrate it over to the new app manually.

@ajcwebdev ajcwebdev closed this Mar 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants