mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Adds internal cross-links to docs guides ## Testing - Prettier passes on the changed lines. - Docs build passes (`pnpm build --filter=docs`). - Docs link e2e run locally against the production build for every changed page across this PR. --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
169 lines
6.0 KiB
Plaintext
169 lines
6.0 KiB
Plaintext
---
|
|
title: 'Use Supabase with RedwoodJS'
|
|
subtitle: 'Learn how to create a Supabase project, add some sample data to your database using Prisma migration and seeds, and query the data from a RedwoodJS app.'
|
|
breadcrumb: 'Framework Quickstarts'
|
|
---
|
|
|
|
<AiPrompt id="redwoodjs" />
|
|
|
|
<$Partial path="quickstart_create_project.mdx" />
|
|
|
|
Save your database password securely. You need it for the connection string.
|
|
|
|
<Admonition type="note">
|
|
|
|
This quickstart uses Prisma migrations against your Postgres database. Use a **dedicated Supabase project** (or an empty database) so Prisma does not try to reconcile tables created by other apps or quickstarts.
|
|
|
|
</Admonition>
|
|
|
|
## 2. Gather database connection strings
|
|
|
|
Open the project [**Connect** panel](/dashboard/project/_?showConnect=true&connectTab=direct). This quickstart uses two connection strings. The [**Transaction pooler**](/dashboard/project/_?showConnect=true&connectTab=direct&method=transaction) string is for application queries, and the [**Direct connection**](/dashboard/project/_?showConnect=true&connectTab=direct) string is for running migrations with Prisma. If your network doesn't support IPv6 and you don't have the [IPv4 add-on](/docs/guides/platform/ipv4-address), use the [**Session pooler**](/dashboard/project/_?showConnect=true&connectTab=direct&method=session) string for migrations instead.
|
|
|
|
Copy the Transaction [pooler](/docs/guides/database/connecting-to-postgres/pooling-and-limits) connection string and append `?pgbouncer=true&connection_limit=1`. `pgbouncer=true` stops Prisma from generating [prepared statements](/kb/troubleshooting/disabling-prepared-statements-qL8lEL), which the shared pooler doesn't support in transaction mode. The `connection_limit=1` parameter is only required if you are using Prisma from a serverless environment.
|
|
You will need both connection strings to set up environment variables in Step 5.
|
|
|
|
<Admonition type="note">
|
|
|
|
You can copy and paste these connection strings from the Supabase Dashboard when needed in later steps.
|
|
|
|
</Admonition>
|
|
|
|
## 3. Create a RedwoodJS app
|
|
|
|
Create a RedwoodJS app with TypeScript.
|
|
|
|
<Admonition type="note">
|
|
|
|
The [`yarn` package manager](https://yarnpkg.com) is required to create a RedwoodJS app. You will use it to run RedwoodJS commands later.
|
|
|
|
While TypeScript is recommended, if you want a JavaScript app, omit the `--ts` flag.
|
|
|
|
RedwoodJS 8.x officially supports Node `20.x`. On Node 22 or later, `create-redwood-app` may prompt you to override the version check. Select **Override error and continue install**, or switch to Node 20 with a version manager such as [`nvm`](https://github.com/nvm-sh/nvm).
|
|
|
|
</Admonition>
|
|
|
|
```bash
|
|
yarn create redwood-app my-app --ts --git-init false
|
|
```
|
|
|
|
## 4. Set up AI tooling (optional)
|
|
|
|
<$Partial path="quickstart_ai_tooling.mdx" />
|
|
|
|
## 5. Configure environment variables
|
|
|
|
In your `.env` file, add the following environment variables for your database connection:
|
|
|
|
- The `DATABASE_URL` should use the Transaction mode connection string you copied in Step 2.
|
|
|
|
- The `DIRECT_URL` should use the direct connection string you copied in Step 2.
|
|
|
|
```bash name=.env
|
|
# Transaction mode connection string for Prisma Client app queries
|
|
DATABASE_URL="postgres://postgres.[PROJECT-REF]:[YOUR-DATABASE-PASSWORD]@[POOLER-HOST]:6543/postgres?pgbouncer=true&connection_limit=1"
|
|
|
|
# Direct connection string for Prisma Migrate
|
|
DIRECT_URL="postgres://postgres:[YOUR-DATABASE-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres"
|
|
```
|
|
|
|
## 6. Update your Prisma schema
|
|
|
|
By default, RedwoodJS ships with a SQLite database, but we want to use Postgres.
|
|
|
|
Update your Prisma schema file `api/db/schema.prisma` to use your Supabase Postgres database connection environment variables you set up in Step 5.
|
|
|
|
```prisma name=api/db/schema.prisma
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
directUrl = env("DIRECT_URL")
|
|
}
|
|
```
|
|
|
|
## 7. Create the instrument model and apply a schema migration
|
|
|
|
Create the Instrument model in `api/db/schema.prisma` and then run `yarn rw prisma migrate dev` from your terminal to apply the migration.
|
|
|
|
<Admonition type="note">
|
|
|
|
`yarn rw prisma migrate dev` requires an interactive terminal. It prompts for a migration name and cannot run in fully non-interactive CI shells.
|
|
|
|
</Admonition>
|
|
|
|
```prisma name=api/db/schema.prisma
|
|
model Instrument {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
}
|
|
```
|
|
|
|
## 8. Update seed script
|
|
|
|
Seed the database with a few instruments.
|
|
|
|
Update the file `scripts/seed.ts` to contain the following code:
|
|
|
|
```ts name=scripts/seed.ts
|
|
import type { Prisma } from '@prisma/client'
|
|
import { db } from 'api/src/lib/db'
|
|
|
|
export default async () => {
|
|
try {
|
|
const data: Prisma.InstrumentCreateArgs['data'][] = [
|
|
{ name: 'dulcimer' },
|
|
{ name: 'harp' },
|
|
{ name: 'guitar' },
|
|
]
|
|
|
|
console.log('Seeding instruments ...')
|
|
|
|
const instruments = await db.instrument.createMany({ data })
|
|
|
|
console.log('Done.', instruments)
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
}
|
|
```
|
|
|
|
## 9. Seed your database
|
|
|
|
Run the seed database command to populate the `Instrument` table with the instruments you created.
|
|
|
|
<Admonition type="note">
|
|
|
|
The reset database command `yarn rw prisma db reset` recreates the tables and also runs the seed script.
|
|
|
|
</Admonition>
|
|
|
|
```bash
|
|
yarn rw prisma db seed
|
|
```
|
|
|
|
## 10. Scaffold the instrument UI
|
|
|
|
Use RedwoodJS generators to scaffold a CRUD UI for the `Instrument` model.
|
|
|
|
```bash
|
|
yarn rw g scaffold instrument
|
|
```
|
|
|
|
## 11. Start the app
|
|
|
|
Start the app via `yarn rw dev`. A browser will open to the RedwoodJS Splash page.
|
|
|
|
## 12. View instruments UI
|
|
|
|
Click on `/instruments` to visit http://localhost:8910/instruments where should see the list of instruments.
|
|
|
|
You may now edit, delete, and add new instruments using the scaffolded UI.
|
|
|
|
<$Partial path="quickstart_going_to_production.mdx" />
|
|
|
|
## Next steps
|
|
|
|
- Set up [Auth](/docs/guides/auth) for your app
|
|
- [Insert more data](/docs/guides/database/import-data) into your database
|
|
- Upload and serve static files using [Storage](/docs/guides/storage)
|