Data migration failing when deploying to Netlify

Hi, I’m trying to deploy a data migration to Netlify, and it’s failing for no reason that I can discern. The data migration is empty, so it’s not an error there. It also works perfectly when I run yarn rw data-migrate up locally.

5:14:31 PM: Running Prisma CLI...
5:14:31 PM: $ yarn prisma migrate deploy --schema /opt/build/repo/api/db/schema.prisma
5:14:31 PM: Prisma schema loaded from api/db/schema.prisma
5:14:31 PM: Datasource "db": PostgreSQL database "postgres", schema "public" at ...
5:14:32 PM: 2 migrations found in prisma/migrations
5:14:34 PM: No pending migrations to apply.
5:14:38 PM: rw deploy netlify [...commands]
5:14:38 PM: Build command for Netlify deploy
5:14:38 PM: Options:
5:14:38 PM:   --help                Show help                                      [boolean]
5:14:38 PM:   --version             Show version number                            [boolean]
5:14:38 PM:   --cwd                 Working directory to use (where `redwood.toml` is
5:14:38 PM:                         located)
5:14:38 PM:   --build               Build for production         [boolean] [default: "true"]
5:14:38 PM:   --prisma              Apply database migrations    [boolean] [default: "true"]
5:14:38 PM:   --data-migrate, --dm  Migrate the data in your database
5:14:38 PM:                                                      [boolean] [default: "true"]
5:14:38 PM: For more commands, options, and examples, see Redwood CLI Reference
5:14:38 PM: Error: Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up (https://ntl.fyi/exit-code-1)
5:14:38 PM:     at makeError (/opt/build/repo/node_modules/execa/lib/error.js:60:11)
5:14:38 PM:     at handlePromise (/opt/build/repo/node_modules/execa/index.js:118:26)
5:14:38 PM:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
5:14:38 PM:   shortMessage: 'Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up', (https://ntl.fyi/exit-code-1)

The lines that start with rw deploy netlify [...commands] seem suspicious. There’s something simple that I’m missing, but I can’t figure out what it is. Anyone have any ideas? Thanks for your help!

I had the same thing, I removed the Data Migrations folder entirely since I did not need to use it yet, and then the deployment worked.
I have not tried again yet, but am not totally sure what will happen when I do have a migration to do.
Will test it out soon and see

Well so far I am finding the same thing, my migration failed on Netlify but worked locally.
I created a new optional field
deployed that change
created a data migration and populated that optional field
ran that successfully locally
pushed to main and it failed

9:02:11 AM: Build command for Netlify deploy
9:02:11 AM: Options:
9:02:11 AM:   --help                Show help                                      [boolean]
9:02:11 AM:   --version             Show version number                            [boolean]
9:02:11 AM:   --cwd                 Working directory to use (where `redwood.toml` is
9:02:11 AM:                         located)
9:02:11 AM:   --build               Build for production         [boolean] [default: "true"]
9:02:11 AM:   --prisma              Apply database migrations    [boolean] [default: "true"]
9:02:11 AM:   --data-migrate, --dm  Migrate the data in your database
9:02:11 AM:                                                      [boolean] [default: "true"]
9:02:11 AM: For more commands, options, and examples, see Redwood CLI Reference
9:02:11 AM: Error: Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up (https://ntl.fyi/exit-code-1)
9:02:11 AM:     at makeError (/opt/build/repo/node_modules/execa/lib/error.js:60:11)
9:02:11 AM:     at handlePromise (/opt/build/repo/node_modules/execa/index.js:118:26)
9:02:11 AM:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
9:02:12 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:02:11 AM:   shortMessage: 'Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up', (https://ntl.fyi/exit-code-1)
9:02:11 AM:   command: 'yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up',
9:02:11 AM:   escapedCommand: '"yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up"',
9:02:11 AM:   exitCode: 1,
9:02:11 AM:   signal: undefined,
9:02:11 AM:   signalDescription: undefined,
9:02:11 AM:   stdout: undefined,
9:02:11 AM:   stderr: undefined,
9:02:11 AM:   failed: true,
9:02:11 AM:   timedOut: false,
9:02:11 AM:   isCanceled: false,
9:02:11 AM:   killed: false
9:02:11 AM: }
9:02:11 AM: ​
9:02:11 AM:   "build.command" failed                                        
9:02:11 AM: ────────────────────────────────────────────────────────────────
9:02:11 AM: ​
9:02:11 AM:   Error message
9:02:11 AM:   Command failed with exit code 1: yarn rw deploy netlify (https://ntl.fyi/exit-code-1)
9:02:11 AM: ​
9:02:11 AM:   Error location
9:02:11 AM:   In build.command from netlify.toml:
9:02:11 AM:   yarn rw deploy netlify
9:02:11 AM: ​
9:02:11 AM:   Resolved config
9:02:11 AM:   build:
9:02:11 AM:     command: yarn rw deploy netlify
9:02:11 AM:     commandOrigin: config
9:02:11 AM:     environment:
9:02:11 AM:       - DATABASE_URL
9:02:11 AM:       - SESSION_SECRET
9:02:11 AM:       - SHADOW_DATABASE_URL
9:02:11 AM:     publish: /opt/build/repo/web/dist
9:02:11 AM:     publishOrigin: config
9:02:11 AM:   functionsDirectory: /opt/build/repo/api/dist/functions
9:02:11 AM:   redirects:
type or paste code here

If it makes any difference my DB is on Supabase and there is that thing going on at the moment where I had to manually create and specify a shadow db on supabase to get Prisma to work.

Hmmm, definitely something to do with running the data migration from Netlify.
I messed about with my local .env file to point at my prod db and ran yarn rw data-migrate up from the terminal on my laptop, which completed successfully and applied the changes to my prod db.

I don’t really want to have to do that each time I need to do a data migration though, I’ll mess it up at some point and wreck my prod db.

Any additional logs to help debug what’s happening here?

I can’t tell what’s going wrong here at all - but please note there is a distinction between Prisma migrations (e.g. modifying your database columns) and data migrations (i.e. modifying your data in your db).

@mfosker once you did the migration manually locally, does Netlify deploy?
@andykuo did you make sure your DATABASE_URL env var is correctly set?


I’ve double checked that our CI deployment project is working correctly - so my suggestions here would be:

  1. Ensure that your DATABASE_URL env var is set in the netlify dashboard
  2. Perhaps try deploying without migrations (if you have done the migrations manually) - to isolate whether the issue is genuinely prisma/migration related or something else in your project. To do this you can go to your project settings https://app.netlify.com/sites/<YOUR_PROJECT_NAME>/settings/deploys#continuous-deployment and change the default yarn rw deploy netlify to yarn rw deploy netlify --no-prisma --no-data-migrate - please remember to change this back :wink:
  3. What database and database provider are you using?

It would be helpful to include details about your Redwood versions too!

Thanks @danny,
I am able to run migrations fine from Netlify, it is just data migrations that are tripping up.

When I pointed my local .env at my Prod db (which is on Supabase) I was able to run the data migration successfully from my command line, and checked via the Supabase UI that the data was updated.

I then deployed like normal, thinking that since the data migration was done, and the data migrations table in prod had a record of that, it would all work. However I hit the same issue at the same point.
Deleting my data migration folder, committing and pushing that change meant I was able to deploy my code fine.

I’ll paste the failing deploy log from Netlify in it’s entirety below, are there any other logs it would be useful to see?

I have a couple of environment variables set for the DB on Netlify:
DATABASE_URL : postgresql://postgres:@db..supabase.co:5432/****
SHADOW_DATABASE_URL: postgresql://postgres:@db..supabase.co:5432/****

This is due to an issue with running on Prisma migrations on Supabase, and having to create the shadow db manually (Running `prisma migrate dev` against a Supabase database times out (without the existence of a pre-existing explicit shadow database) · Issue #17160 · prisma/prisma · GitHub) Might be related to the issue?

The data migration itself is super simple, I’m just setting a default value in a column that I added with a regular migration, I could achieve the same result by setting a default value in my schema, but I am specifically trying to get data migration to work so that I know how to do it when I really need it.

Here’s a dummy one I tried to repro the issue, based on the example in the data migration docs.

import type { PrismaClient, PaymentType } from '@prisma/client'

const asyncForEach = async (array, callback) => {
  for (let index = 0; index < array.length; index++) {
    await callback(array[index], index, array)
  }
}

export default async ({ db }: { db: PrismaClient }) => {
  const sessions = await db.hireSession.findMany()

  const paymentType: PaymentType = 'CASH'

  asyncForEach(sessions, async (session) => {
    const id = session.id
    await db.hireSession.update({
      data: { paymentType },
      where: { id },
    })
  })
}

This failed to deploy, as before.

I then changed the build command as you suggested, in the Netlify UI and in the Netlify .toml file, which built and deployed successfully.

The data base is Postgres on Supabase
I’m on Redwood 3.8.0

Supabase is on PostgreSQL 15.1
Locally Postgres is on 11.5 ( guess I should update that even if it isn’t the issue :smiley: )

Failing Netlify deploy log:

9:35:48 PM: build-image version: ada486d80800a9a84b567366a5bfe2beab07892e (focal)
9:35:48 PM: buildbot version: ada486d80800a9a84b567366a5bfe2beab07892e
9:35:48 PM: Fetching cached dependencies
9:35:48 PM: Starting to download cache of 299.9MB
9:35:51 PM: Finished downloading cache in 2.323s
9:35:51 PM: Starting to extract cache
9:35:54 PM: Finished extracting cache in 3.392s
9:35:54 PM: Finished fetching cache in 5.776s
9:35:54 PM: Starting to prepare the repo for build
9:35:54 PM: Preparing Git Reference refs/heads/main
9:35:55 PM: Parsing package.json dependencies
9:35:56 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'yarn rw deploy netlify' versus 'rw deploy netlify' in the Netlify UI
9:35:56 PM: Starting build script
9:35:56 PM: Installing dependencies
9:35:56 PM: Python version set to 2.7
9:35:56 PM: Started restoring cached Node.js version
9:35:57 PM: Finished restoring cached Node.js version
9:35:57 PM: Attempting Node.js version 'lts/*' from .nvmrc
9:35:57 PM: v18.13.0 is already installed.
9:35:58 PM: Now using node v18.13.0 (npm v8.19.3)
9:35:58 PM: Enabling Node.js Corepack
9:35:58 PM: Started restoring cached build plugins
9:35:58 PM: Finished restoring cached build plugins
9:35:58 PM: Attempting Ruby version 2.7.2, read from environment
9:35:58 PM: Using Ruby version 2.7.2
9:35:59 PM: Using PHP version 8.0
9:35:59 PM: Started restoring cached corepack dependencies
9:35:59 PM: mv: cannot move '/opt/build/cache/.node/corepack' to '/opt/buildhome/.node/corepack': No such file or directory
9:35:59 PM: Finished restoring cached corepack dependencies
9:35:59 PM: Started restoring cached yarn cache
9:35:59 PM: Finished restoring cached yarn cache
9:35:59 PM: Installing Yarn version 1.22.19
9:35:59 PM: Preparing yarn@1.22.19 for immediate activation...
9:35:59 PM: yarn workspaces detected
9:35:59 PM: Started restoring workspace root node modules
9:35:59 PM: Finished restoring workspace root node modules
9:35:59 PM: Installing npm packages using Yarn version 3.3.0
9:36:00 PM: ➤ YN0050: The cache-folder option has been deprecated; use rc settings instead
9:36:00 PM: ➤ YN0000: ┌ Resolution step
9:36:00 PM: ➤ YN0002: │ @graphql-codegen/cli@npm:2.16.1 [80bd5] doesn't provide @types/node (p6d237), requested by cosmiconfig-typescript-loader➤ YN0002: │ @graphql-codegen/cli@npm:2.16.1 [80bd5] doesn't provide ts-node (p88b70), requested by cosmiconfig-typescript-loader➤ YN0002: │ @graphql-codegen/cli@npm:2.16.1 [80bd5] doesn't provide typescript (pdb5fc), requested by cosmiconfig-typescript-loader➤ YN0002: │ @graphql-tools/graphql-tag-pluck@npm:7.4.2 [15b43] doesn't provide @babel/core (p9330e), requested by @babel/plugin-syntax-import-assertions➤ YN0002: │ @redwoodjs/api-server@npm:3.8.0 doesn't provide @babel/core (pdeadb), requested by @babel/plugin-transform-runtime➤ YN0002: │ @redwoodjs/cli@npm:3.8.0 doesn't provide react (p97e51), requested by @redwoodjs/prerender➤ YN0002: │ @redwoodjs/cli@npm:3.8.0 doesn't provide react-dom (p79525), requested by @redwoodjs/prerender➤ YN0002: │ @redwoodjs/core@npm:3.8.0 doesn't provide @babel/eslint-parser (p016c9), requested by @babel/eslint-plugin➤ YN0002: │ @redwoodjs/core@npm:3.8.0 doesn't provide eslint (pdef12), requested by @babel/eslint-plugin➤ YN0002: │ @redwoodjs/eslint-config@npm:3.8.0 doesn't provide babel-plugin-module-resolver (p11ff9), requested by eslint-import-resolver-babel-module➤ YN0002: │ @redwoodjs/graphql-server@npm:3.8.0 doesn't provide @envelop/core (p99ea1), requested by @envelop/depth-limit➤ YN0002: │ @redwoodjs/graphql-server@npm:3.8.0 doesn't provide @envelop/core (p0756b), requested by @envelop/disable-introspection➤ YN0002: │ @redwoodjs/graphql-server@npm:3.8.0 doesn't provide @envelop/core (pc77b1), requested by @envelop/filter-operation-type➤ YN0002: │ @redwoodjs/graphql-server@npm:3.8.0 doesn't provide @envelop/core (p664cb), requested by @envelop/parser-cache➤ YN0002: │ @redwoodjs/graphql-server@npm:3.8.0 doesn't provide @envelop/core (pd8be9), requested by @envelop/validation-cache➤ YN0002: │ @redwoodjs/internal@npm:3.8.0 doesn't provide @babel/core (pa924a), requested by @babel/plugin-transform-typescript➤ YN0002: │ @redwoodjs/internal@npm:3.8.0 doesn't provide @babel/core (pa7af6), requested by @babel/register➤ YN0002: │ @redwoodjs/internal@npm:3.8.0 doesn't provide @babel/core (p39898), requested by babel-plugin-graphql-tag➤ YN0002: │ @redwoodjs/internal@npm:3.8.0 doesn't provide graphql-tag (pae2c4), requested by @graphql-codegen/typescript-react-apollo➤ YN0002: │ @redwoodjs/internal@npm:3.8.0 doesn't provide graphql-tag (p1da23), requested by babel-plugin-graphql-tag➤ YN0002: │ @redwoodjs/prerender@npm:3.8.0 [6a219] doesn't provide prop-types (p29771), requested by @redwoodjs/web➤ YN0002: │ @redwoodjs/router@npm:3.8.0 doesn't provide react (p36be0), requested by @reach/skip-nav➤ YN0002: │ @redwoodjs/router@npm:3.8.0 doesn't provide react-dom (pbb35c), requested by @reach/skip-nav➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide @babel/core (pfc3cf), requested by @storybook/addon-essentials➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide @babel/core (p7609e), requested by babel-jest➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide @babel/core (p64188), requested by babel-plugin-inline-react-svg➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide @testing-library/dom (pe08f0), requested by @testing-library/user-event➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide prop-types (p06197), requested by @redwoodjs/web➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react (p3d95a), requested by @redwoodjs/web➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react (pffbcd), requested by @storybook/builder-webpack5➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react (pb3ea4), requested by @storybook/manager-webpack5➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react (p34410), requested by @storybook/react➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react (p29902), requested by @testing-library/react-hooks➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react (pffbe3), requested by @testing-library/react➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react-dom (p3ae15), requested by @redwoodjs/web➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react-dom (p7e5ec), requested by @storybook/builder-webpack5➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react-dom (pf321d), requested by @storybook/manager-webpack5➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react-dom (p06326), requested by @storybook/react➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide react-dom (p1fbf7), requested by @testing-library/react➤ YN0002: │ @redwoodjs/testing@npm:3.8.0 doesn't provide require-from-string (p8a73f), requested by @storybook/react➤ YN0002: │ @storybook/addon-docs@npm:6.5.14 [a4b4c] doesn't provide @babel/core (pf13db), requested by @babel/preset-env➤ YN0002: │ @storybook/addon-docs@npm:6.5.14 [a4b4c] doesn't provide @babel/core (p866f8), requested by @babel/plugin-transform-react-jsx➤ YN0002: │ @storybook/addon-docs@npm:6.5.14 [a4b4c] doesn't provide @babel/core (p75ec0), requested by babel-loader➤ YN0002: │ @storybook/addon-docs@npm:6.5.14 [a4b4c] doesn't provide webpack (p89ce8), requested by babel-loader➤ YN0002: │ @storybook/docs-tools@npm:6.5.14 doesn't provide react (pf97f7), requested by @storybook/store➤ YN0002: │ @storybook/docs-tools@npm:6.5.14 doesn't provide react-dom (pa1b49), requested by @storybook/store➤ YN0002: │ @storybook/mdx1-csf@npm:0.0.1 doesn't provide @babel/core (p44796), requested by @babel/preset-env➤ YN0002: │ @storybook/telemetry@npm:6.5.14 doesn't provide react (p780dd), requested by @storybook/core-common➤ YN0002: │ @storybook/telemetry@npm:6.5.14 doesn't provide react-dom (p7d9d6), requested by @storybook/core-common➤ YN0002: │ graphql-config@npm:4.3.6 [a9dff] doesn't provide @types/node (p9ad2a), requested by cosmiconfig-typescript-loader➤ YN0002: │ graphql-config@npm:4.3.6 [a9dff] doesn't provide @types/node (p2f181), requested by ts-node➤ YN0002: │ graphql-config@npm:4.3.6 [a9dff] doesn't provide typescript (p506b0), requested by cosmiconfig-typescript-loader➤ YN0002: │ graphql-config@npm:4.3.6 [a9dff] doesn't provide typescript (pe0c17), requested by ts-node➤ YN0002: │ react-hot-toast@npm:2.4.0 [2f189] doesn't provide csstype (p79ee8), requested by goober➤ YN0002: │ react-hot-toast@npm:2.4.0 [73d2e] doesn't provide csstype (pf28f8), requested by goober➤ YN0002: │ react-hot-toast@npm:2.4.0 [751da] doesn't provide csstype (pcba5f), requested by goober➤ YN0002: │ root-workspace-0b6124@workspace:. doesn't provide prettier (pf39c6), requested by prettier-plugin-tailwindcss➤ YN0002: │ web@workspace:web doesn't provide graphql (p9a713), requested by @redwoodjs/forms➤ YN0002: │ web@workspace:web doesn't provide webpack (pbf39d), requested by postcss-loader➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
9:36:00 PM: ➤ YN0000: └ Completed in 0s 304ms
9:36:00 PM: ➤ YN0000: ┌ Fetch step
9:36:11 PM: ➤ YN0013: │ 26 packages were already cached, 2274 had to be fetched
9:36:11 PM: ➤ YN0000: └ Completed in 10s 578ms
9:36:11 PM: ➤ YN0000: ┌ Link step
9:36:13 PM: ➤ YN0007: │ core-js@npm:3.26.1 must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ core-js@npm:3.27.1 must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ esbuild@npm:0.16.3 must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ core-js-pure@npm:3.27.1 must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ @fortawesome/fontawesome-free@npm:5.15.4 must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ msw@npm:0.49.2 [a4b4c] must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ @prisma/client@npm:4.7.1 [f7b04] must be built because it never has been before or the last one failed
9:36:13 PM: ➤ YN0007: │ @prisma/engines@npm:4.7.1 must be built because it never has been before or the last one failed
9:36:16 PM: ➤ YN0000: │ @fortawesome/fontawesome-free@npm:5.15.4 STDOUT Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com
9:36:16 PM: ➤ YN0000: │ @fortawesome/fontawesome-free@npm:5.15.4 STDOUT License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
9:36:16 PM: ➤ YN0000: │ @fortawesome/fontawesome-free@npm:5.15.4 STDOUT
9:36:17 PM: ➤ YN0000: │ @prisma/client@npm:4.7.1 [f7b04] STDERR prisma:warn The postinstall script automatically ran `prisma generate` and did not find your `prisma/schema.prisma`.
9:36:17 PM: ➤ YN0000: │ @prisma/client@npm:4.7.1 [f7b04] STDERR If you have a Prisma schema file in a custom path, you will need to run
9:36:17 PM: ➤ YN0000: │ @prisma/client@npm:4.7.1 [f7b04] STDERR `prisma generate --schema=./path/to/your/schema.prisma` to generate Prisma Client.
9:36:17 PM: ➤ YN0000: │ @prisma/client@npm:4.7.1 [f7b04] STDERR If you do not have a Prisma schema file yet, you can ignore this message.
9:36:17 PM: ➤ YN0000: │ @prisma/client@npm:4.7.1 [f7b04] STDOUT
9:36:18 PM: ➤ YN0007: │ prisma@npm:4.7.1 must be built because it never has been before or the last one failed
9:36:19 PM: ➤ YN0000: └ Completed in 8s 5ms
9:36:19 PM: ➤ YN0000: Done with warnings in 19s 328ms
9:36:19 PM: npm packages installed using Yarn
9:36:20 PM: Started restoring cached go cache
9:36:20 PM: Finished restoring cached go cache
9:36:20 PM: go version go1.19.5 linux/amd64
9:36:20 PM: Detected 1 framework(s)
9:36:20 PM: "redwoodjs" at version "3.8.0"
9:36:20 PM: Installing missing commands
9:36:20 PM: Verify run directory
9:36:20 PM: Section completed: initializing
9:36:22 PM: ​
9:36:22 PM:   Netlify Build                                                 
9:36:22 PM: ────────────────────────────────────────────────────────────────
9:36:22 PM: ​
9:36:22 PM: ❯ Version
9:36:22 PM:   @netlify/build 29.5.3
9:36:22 PM: ​
9:36:22 PM: ❯ Flags
9:36:22 PM:   baseRelDir: true
9:36:22 PM:   buildId: 63dadb2fc528dd0008712a48
9:36:22 PM:   deployId: 63dadb2fc528dd0008712a4a
9:36:22 PM: ​
9:36:22 PM: ❯ Current directory
9:36:22 PM:   /opt/build/repo
9:36:22 PM: ​
9:36:22 PM: ❯ Config file
9:36:22 PM:   /opt/build/repo/netlify.toml
9:36:22 PM: ​
9:36:22 PM: ❯ Context
9:36:22 PM:   production
9:36:22 PM: ​
9:36:22 PM:   1. build.command from netlify.toml                            
9:36:22 PM: ────────────────────────────────────────────────────────────────
9:36:22 PM: ​
9:36:22 PM: $ yarn rw deploy netlify
9:36:23 PM: 
9:36:23 PM: Running:
9:36:23 PM: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up
9:36:25 PM: [STARTED] Generating Prisma Client...
9:36:26 PM: Prisma schema loaded from db/schema.prisma
9:36:26 PM: ✔ Generated Prisma Client (4.7.1 | library) to ./../node_modules/@prisma/client in 65ms
9:36:26 PM: You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
9:36:26 PM: ```import { PrismaClient } from '@prisma/client'const prisma = new PrismaClient()```
9:36:26 PM: [SUCCESS] Generating Prisma Client...
9:36:26 PM: [STARTED] Verifying graphql schema...
9:36:26 PM: [SUCCESS] Verifying graphql schema...
9:36:26 PM: [STARTED] Building API...
9:36:27 PM: [SUCCESS] Building API...
9:36:27 PM: [STARTED] Cleaning Web...
9:36:27 PM: [SUCCESS] Cleaning Web...
9:36:27 PM: [STARTED] Building Web...
9:36:40 PM: assets by path static/ 931 KiB
9:36:40 PM:   assets by path static/js/*.js 683 KiB 10 assets  assets by path static/media/ 177 KiB 5 assets  asset static/css/app.3c31cc47.css 69.8 KiB [emitted] [immutable] [minimized] (name: app)assets by path fonts/ 256 KiB 9 assetsassets by path css/*.css 114 KiB  asset css/soft-ui-dashboard-tailwind.css 52.3 KiB [emitted] [from: public/css/soft-ui-dashboard-tailwind.css] [copied] [minimized]  asset css/soft-ui-dashboard-tailwind.min.css 52.3 KiB [emitted] [from: public/css/soft-ui-dashboard-tailwind.min.css] [copied] [minimized]  asset css/nucleo-icons.css 6.34 KiB [emitted] [from: public/css/nucleo-icons.css] [copied] [minimized]  asset css/perfect-scrollbar.css 1.61 KiB [emitted] [from: public/css/perfect-scrollbar.css] [copied] [minimized]  + 2 assetsasset build-manifest.json 2 KiB [emitted]asset favicon.png 1.7 KiB [emitted] [from: public/favicon.png] [copied]asset index.html 561 bytes [emitted]asset robots.txt 24 bytes [emitted] [from: public/robots.txt] [copied]Entrypoint app [big] 570 KiB (177 KiB) = static/js/runtime-app.9773b635.js 3.94 KiB static/css/app.3c31cc47.css 69.8 KiB static/js/app.0447af81.js 496 KiB 5 auxiliary assetsorphan modules 981 KiB (javascript) 177 KiB (asset) 12.5 KiB (runtime) [orphan] 274 modulesruntime modules 10.3 KiB 15 modulesmodules by path ../node_modules/ 1.48 MiB 712 modulesmodules by path ./src/ 44.7 KiB (javascript) 106 KiB (css/mini-extract)  javascript modules 44.7 KiB    modules by path ./src/pages/ 26.8 KiB 6 modules    ./src/App.tsx + 7 modules 4.45 KiB [built] [code generated]    ./src/components/HireSession/HireSessionForm/HireSessionForm.tsx 11.9 KiB [built] [code generated]    ./src/lib/formatters.tsx 1.6 KiB [built] [code generated]  css modules 106 KiB    modules by path ./src/css/*.css 79.4 KiB 3 modules    modules by path ./src/*.css 27 KiB      css ../node_modules/@redwoodjs/core/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[3].use[1]!../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[3].use[2]!./src/scaffold.css 11.1 KiB [built] [code generated]      css ../node_modules/@redwoodjs/core/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[3].use[1]!../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[3].use[2]!./src/index.css 16 KiB [built] [code generated]WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).This can impact web performance.Assets:   static/js/app.0447af81.js (496 KiB)WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.Entrypoints:  app (570 KiB)      static/js/runtime-app.9773b635.js      static/css/app.3c31cc47.css      static/js/app.0447af81.jswebpack 5.75.0 compiled with 2 warnings in 10064 msCreating 200.html...
9:36:40 PM: [SUCCESS] Building Web...
9:36:40 PM: Starting prerendering...
9:36:40 PM: You have not marked any routes to "prerender" in your Routes.
9:36:42 PM: Skipping prerender...
9:36:42 PM: You have not marked any routes with a path as `prerender` in `Routes.{js,tsx}` 
9:36:42 PM: 
9:36:44 PM: Running Prisma CLI...
9:36:44 PM: $ yarn prisma migrate deploy --schema /opt/build/repo/api/db/schema.prisma
9:36:44 PM: Prisma schema loaded from api/db/schema.prisma
9:36:44 PM: Datasource "db": PostgreSQL database "postgres", schema "public" at "db.fcwgmcjdlgypbezgyybq.supabase.co:5432"
9:36:45 PM: 5 migrations found in prisma/migrations
9:36:48 PM: Applying migration `20230201212706_create_data_migrations`
9:36:49 PM: The following migration have been applied:
9:36:49 PM: migrations/
9:36:49 PM:   └─ 20230201212706_create_data_migrations/
9:36:49 PM:     └─ migration.sql
9:36:49 PM: All migrations have been successfully applied.
9:36:52 PM: rw deploy netlify [...commands]
9:36:52 PM: Build command for Netlify deploy
9:36:52 PM: Options:
9:36:52 PM:   --help                Show help                                      [boolean]
9:36:52 PM:   --version             Show version number                            [boolean]
9:36:52 PM:   --cwd                 Working directory to use (where `redwood.toml` is
9:36:52 PM:                         located)
9:36:52 PM:   --build               Build for production         [boolean] [default: "true"]
9:36:52 PM:   --prisma              Apply database migrations    [boolean] [default: "true"]
9:36:52 PM:   --data-migrate, --dm  Migrate the data in your database
9:36:52 PM:                                                      [boolean] [default: "true"]
9:36:52 PM: For more commands, options, and examples, see Redwood CLI Reference
9:36:52 PM: Error: Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up (https://ntl.fyi/exit-code-1)
9:36:52 PM:     at makeError (/opt/build/repo/node_modules/execa/lib/error.js:60:11)
9:36:52 PM:     at handlePromise (/opt/build/repo/node_modules/execa/index.js:118:26)
9:36:52 PM:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
9:36:52 PM:   shortMessage: 'Command failed with exit code 1: yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up', (https://ntl.fyi/exit-code-1)
9:36:52 PM:   command: 'yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up',
9:36:53 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:36:52 PM:   escapedCommand: '"yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up"',
9:36:52 PM:   exitCode: 1,
9:36:52 PM:   signal: undefined,
9:36:52 PM:   signalDescription: undefined,
9:36:52 PM:   stdout: undefined,
9:36:52 PM:   stderr: undefined,
9:36:52 PM:   failed: true,
9:36:52 PM:   timedOut: false,
9:36:52 PM:   isCanceled: false,
9:36:52 PM:   killed: false
9:36:52 PM: }
9:36:52 PM: ​
9:36:52 PM:   "build.command" failed                                        
9:36:52 PM: ────────────────────────────────────────────────────────────────
9:36:52 PM: ​
9:36:52 PM:   Error message
9:36:52 PM:   Command failed with exit code 1: yarn rw deploy netlify (https://ntl.fyi/exit-code-1)
9:36:52 PM: ​
9:36:52 PM:   Error location
9:36:52 PM:   In build.command from netlify.toml:
9:36:52 PM:   yarn rw deploy netlify
9:36:52 PM: ​
9:36:52 PM:   Resolved config
9:36:52 PM:   build:
9:36:52 PM:     command: yarn rw deploy netlify
9:36:52 PM:     commandOrigin: config
9:36:52 PM:     environment:
9:36:52 PM:       - DATABASE_URL
9:36:52 PM:       - MIGRATION_DATABASE
9:36:52 PM:       - SESSION_SECRET
9:36:52 PM:       - SHADOW_DATABASE_URL
9:36:52 PM:     publish: /opt/build/repo/web/dist
9:36:52 PM:     publishOrigin: config
9:36:52 PM:   functionsDirectory: /opt/build/repo/api/dist/functions
9:36:52 PM:   redirects:
9:36:52 PM:     - from: /*      status: 200      to: /200.html  redirectsOrigin: configCaching artifacts
9:36:52 PM: Started saving workspace root node modules
9:36:52 PM: Finished saving workspace root node modules
9:36:52 PM: Started saving build plugins
9:36:52 PM: Finished saving build plugins
9:36:52 PM: Started saving yarn cache
9:36:52 PM: Finished saving yarn cache
9:36:52 PM: Started saving pip cache
9:36:52 PM: Finished saving pip cache
9:36:52 PM: Started saving emacs cask dependencies
9:36:52 PM: Finished saving emacs cask dependencies
9:36:52 PM: Started saving maven dependencies
9:36:52 PM: Finished saving maven dependencies
9:36:52 PM: Started saving boot dependencies
9:36:52 PM: Finished saving boot dependencies
9:36:52 PM: Started saving rust rustup cache
9:36:52 PM: Finished saving rust rustup cache
9:36:52 PM: Started saving go dependencies
9:36:52 PM: Finished saving go dependencies
9:36:52 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:36:52 PM: Failing build: Failed to build site
9:36:53 PM: Finished processing build request in 1m4.628s

FWIW I am going to have a go at seeing if I can reproduce this with a fresh RW 4.0 app a contrived basic schema and data migration and a new Supabase DB (now that they appear to have resolved the shadow db issue above).

Will update either way on whether that works.

Well, as far as I can tell, starting from a fresh Redwood 4.0.1 I am seeing the same issue :frowning:

Everything works, including schema migrations, but as soon as I deploy a simple data migration I get the same errors on netlify.

When I first saw the issue, I didn’t even have a data migration created, but had installed the package. with yarn rw data-migrate install just deploying after doing that caused the same issue.


If there is anything I can add in / change about the setup to improve the logging and help track down the issue then let me know.
I’m not very familiar with how redwood is structured behind the scenes ( I can’t even figure out where the build commands are :man_shrugging: ) so assume I know nothing.