Shipped
HomeContacts
  • Get started
  • 📚Tutorials
    • Make a waiting list
    • Launch a pre-sale
    • Build a SaaS
    • Create your store on Lemon Squeezy
  • 🟩Features
    • AI Services
    • Affiliate Program
    • Analytics
    • Authentication
      • MailChimp
      • Loops
      • AWS SES
      • SendGrid
      • Supabase Auth
        • Supabase Authentication Flow
        • Supabase Magic Link
        • Supabase Email & Password
        • Supabase Login with Google
    • API endpoints
      • 🛡️Authenticated API
    • Blog
    • Customer support
    • Chrome Extension
    • Dark mode
    • Database
      • Update your database
      • MongoDB
    • Emails
    • Error pages
    • Icons
    • Onboarding
    • Payments
      • Lemon Squeezy
        • Subscriptions
        • One-time purchase
        • Test mode
      • Stripe
    • Private pages
    • SEO
    • shadcn/ui
    • Supabase
    • Workspace / Organizations
  • 📦Components
    • AccountMenu
    • CtaBox
    • DarkModeSwitch
    • Explainer video
    • FAQ
    • Features
    • Footer
    • Header
    • Hero
    • Lifetime
    • Pricing
    • Sales Notification
    • Secondary Sidebar Pages
    • Sidebar
    • Tabs
    • Testimonials
    • Waitlist
    • WebAppPage
  • 🚀Deployment
  • ✅Other
    • Configuration
    • Changelog widget
    • Favicon
    • Google Fonts
    • Sitemap
    • Theme
  • Updates
  • GitHub Repository
  • Support
Powered by GitBook
On this page
  • Add a new table
  • Add column
  • Apply the schema to your database

Was this helpful?

  1. Features
  2. Database

Update your database

To add new tables or columns to your database we use Prisma. Prisma is a TypeScript ORM, and it helps you apply changes to your database, and interact with it in a type-safe way., and without using SQL.

Add a new table

To add a new table, open the file prisma/schema.prisma and add a new model.

For instance, to add a new table called Orders, add this

prisma/schema.prisma
model Order {
  id                  Int       @id @default(autoincrement())
  email               String
  orderId             String
  createdAt           DateTime  @default(now())
  updatedAt           DateTime  @updatedAt
}

Add column

To add a column to a table, simply add a new property to a model.

To add a new column, called validUntil to the previous Orders table, simply add line 5:

prisma/schema.prisma
model Order {
  id                  Int       @id @default(autoincrement())
  email               String
  orderId             String
  validUntil          DateTime?
  createdAt           DateTime  @default(now())
  updatedAt           DateTime  @updatedAt
}

It's a good idea to add a new column to existing tables, with a nullable value. You do it by appending a question mark (?)at the end of the column type.

It means that, as soon as the new column is created, it's value will be NULL.

Alternatively, assign a default value, using the @default() decorator.

Apply the schema to your database

To do that, run this command:

Terminal
npx prisma db push

With this command, prisma will apply the schema defined into prisma/schema.prisma to the database defined in the .env file, using the connection string defined in the environment variable DATABASE_URL.

PreviousDatabaseNextMongoDB

Last updated 1 year ago

Was this helpful?

For more details about Prisma, check the

🟩
official documentation of Prisma.