apps/docs/content/guides/getting-started/quickstarts/redwoodjs.mdx
<$Partial path="quickstart_create_project.mdx" />
Save your database password securely. You need it for the connection string.
Open the project Connect panel. This quickstart connects using the Transaction pooler and Session pooler mode. Transaction mode is used for application queries and Session mode is used for running migrations with Prisma.
To do this, set the connection mode to Transaction in the Database Settings page and copy the connection string and append ?pgbouncer=true&connection_limit=1. pgbouncer=true disables Prisma from generating prepared statements. This is required since our connection pooler does not support prepared statements in transaction mode yet. The connection_limit=1 parameter is only required if you are using Prisma from a serverless environment. This is the Transaction mode connection string.
To get the Session mode connection pooler string, change the port of the connection string from the dashboard to 5432.
You will need the Transaction mode connection string and the Session mode connection string to set up environment variables in Step 6.
<Admonition type="note">You can copy and paste these connection strings from the Supabase Dashboard when needed in later steps.
</Admonition>Create a RedwoodJS app with TypeScript.
<Admonition type="note">The yarn package manager 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.
yarn create redwood-app my-app --ts
Supabase's Agent Skills is a curated set of instructions that give your AI agent procedural knowledge about working with Supabase.
Install them so your AI coding agent can produce more accurate, reliable code using current Supabase patterns, such as authentication, server-side rendering, and database migrations, rather than relying solely on training data.
To install, run the following command in the root of your project:
npx skills add supabase/agent-skills
The Supabase MCP server connects AI assistants to Supabase, allowing you to interact with your projects on your behalf. Find out more on how to add it to your client in the MCP docs.
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 Session mode connection string you copied in Step 2.
# Transaction mode connection string — used by Prisma Client for app queries
DATABASE_URL="postgres://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-[REGION].pooler.supabase.com:6543/postgres?pgbouncer=true&connection_limit=1"
# Session mode connection string — used by Prisma Migrate
DIRECT_URL="postgres://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-[REGION].pooler.supabase.com:5432/postgres"
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 6.
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
Create the Instrument model in api/db/schema.prisma and then run yarn rw prisma migrate dev from your terminal to apply the migration.
model Instrument {
id Int @id @default(autoincrement())
name String @unique
}
Seed the database with a few instruments.
Update the file scripts/seed.ts to contain the following code:
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)
}
}
Run the seed database command to populate the Instrument table with the instruments you created.
The reset database command yarn rw prisma db reset recreates the tables and also runs the seed script.
yarn rw prisma db seed
Use RedwoodJS generators to scaffold a CRUD UI for the Instrument model.
yarn rw g scaffold instrument
Start the app via yarn rw dev. A browser will open to the RedwoodJS Splash page.
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.