Possible to deploy without a database?

Does Redwood support deployment without configuring a database? I’m experimenting with a simple app that initially just enables searching/filtering on an Airtable dataset (eventually there will probably be a SQL database). I’m following the “Using a Third Party API” cookbook and it all works locally, but I get build errors related to the database when deploying to Netlify, and 502 errors when viewing the deploy preview.

Should I remove everything from the prisma.schema file? Remove references to the database in the netlify.toml file? Or should I just set up a dummy database somewhere for now?

Thanks for any guidance! I’m loving Redwood so far!

2 Likes

cc: @rob (our master of the deploy)

Hi @bennett First off, to this day I still think Tygra should have been calling the shots. And definitely had a childhood crush on Cheetara. Ok, moving on…

Yes, Redwood was designed for you to be able to deploy without connecting/configuring a database. But we haven’t exactly created that option in the yarn rw build command, which is what Netlify is using when you deploy. (We definitely need to provide this option, for the record.) So if you’re willing and able, let’s figure this out together.

You should just delete the “api/prisma” directory. But now the API build is going to fail. You can check this locally with yarn rw build.

Here’s the code behind the build command. The line that’s breaking things is L25 where the Prisma Client is generated automatically. (Oops – what I think we’ll need to modify in the future is adding a flag, e.g. --no-prisma, which will allow Apps to build without the Prisma Client.) For now, take a look at line 31, specifically:

yarn cross-env NODE_ENV=production babel src --out-dir dist

Ignoring the yarn cross-env part, in your “api/package.json” add the following:

  "scripts": {
    "build": "NODE_ENV=production babel src --out-dir dist"
  }

This should successfully build your API. You can test it with yarn workspace api build.

I think it might be easiest if you also port the yarn rw build web command to “web/package.json”. Using L35-36 from the source code, add this:

  "scripts": {
    "build": "webpack --config ../node_modules/@redwoodjs/core/config/webpack.production.js
  }

That should run correctly with the command yarn workspace web build. Does it?

Assuming both of those are working, you can now run them together using the following command:
yarn workspaces run build

Your next step will be to set up Netlify (or hosting of your choice) to use that command for building the API and Web sides. The “api/dist” folder should be deployed to Netlify Lambdas and “web/dist” to the Netlify CDN.

Do you think that’s enough for you to take it from here and check back in with a progress report?

Hi @thedavid - thanks for helping!

This was definitely the right path. Here are all of the things that I had to do to make it work:

  • Delete the api/prisma directory
  • Comment out (or delete) everything in the api/src/lib/db.js file
  • Add the build scripts you specified to the api and web package.json files
  • Update the build command in the netlify.toml file to be command = "yarn workspaces run build"
  • Delete everything in the [[plugins]] section of the netlify.toml file

The first version of the app seems to be working on Netlify now. I’ll share it once it’s a bit further along.

By the way - I’m excited to try the integrated auth solution once there’s something to check out! I’ve got a separate app I’m working on where I’m manually integrating Auth0. It would be so nice if that Just Worked™!

1 Like

:rocket:

Thanks for the update. And nice work configuring the Netlify deploy!

re: Auth
Keep a lookout for information about this coming soon. To be clear, implementation is in process and stage 1 won’t be completed. But we have some thorough design and roadmap documentation that will be immediately available. The goal is to allow for both community discussion/feedback as well as a reference for people adding their own Auth now – you’ll be able to align current implementation with the RW roadmap. In your case, do know we’re focused on Auth0 support out of the gate.

If you aren’t following along already, here’s the GitHub tracking Issue with the latest info.

Yep already subscribed. Thanks!

1 Like

Could also just link to a db with no table as a temporary hack.

I follow the steps in this post. After I removed db.js, I got an error in graphql.js.

import { db } from ‘src/lib/db’

There’s another dependency here. @thedavid any suggestion on how to disable this?

Ah, yes, you will NOT need any reference to db import or object.

In graphql.js, you can removed:

  1. import { db } from 'src/lib/db'
  2. db, (in my file, this is line 18 included at the end of export const handler)

@thedavid thanks. That works. My app can run locally.

1 Like