LogoLogo
Log in
  • Introduction
    • Welcome
    • Quick Start
      • Sign up for a Cal.com account
      • Complete your onboarding
      • Self-hosting
        • Installation
          • Ultimate
          • Platform
            • Get access to the API
            • API submodule
        • Install apps
          • Google
          • Microsoft
          • Zoom
          • Daily
          • HubSpot
          • Stripe
          • Sendgrid
          • Twilio
        • E2E testing
        • Upgrading
        • Docker
        • Vercel
        • Database migrations
        • SSO setup
  • Core Features
    • Event types
      • Secret events
      • Location of the event
      • Availability schedule
      • Multiple durations
      • Event buffer
      • Custom time-slot intervals
      • Custom event name in the booking
      • Minimum notice
      • Booking frequency
      • Limit future bookings
      • Add events to calendar
      • Additional inputs
      • Requires confirmation
      • Hide notes in calendar
      • Require additional notes
      • Booking success URL
      • Single use private links
      • Offer seats
      • Recurring events
      • Disable guests
    • Bookings
      • Paid bookings
    • Availability
      • Multiple time slots per day
      • Date overrides
      • Multiple schedules
    • App Store
      • Apps
        • Calendar apps
        • Video apps
        • Payment apps
        • Workflow apps
        • Analytics apps
        • Web3 apps
        • Miscellaneous apps
    • Webhooks
    • Embed
      • Install with JavaScript
      • Install with React
      • Set up your embed
    • New Docs Embed
      • Adding embed to your webpage
      • Embed Snippet Generator
      • Embed events
      • Embed instructions
      • Adding slots to your email
    • Dynamic group links
    • Customization
    • i18n Internationalization
  • Enterprise Features
    • Teams
      • Team workflows
      • Round-robin scheduling
      • Collective events
      • Advanced routing forms
    • Workflows
    • API
      • Quick start
        • Testing API locally
        • Hosted API through Cal.com
      • Authentication
      • Errors
      • Rate limits
      • Versioning
      • Types
      • API reference
        • Attendees
        • Availabilities
        • Booking References
        • Bookings
        • Custom inputs
        • Destination calendars
        • Event types
        • Memberships
        • Payments
        • Schedules
        • Selected calendars
        • Teams
        • Users
        • Webhooks
    • Admin
  • Knowledgebase
    • Glossary
  • How To Guides
    • Acquire and manage a license key
    • Adding your first app
    • Creating a secret event type
    • Creating your first event type
    • How to add a location to your event type
    • How to add custom CSS
    • How to build an app
      • Build a greeter app
    • How to connect apple calendar with calcom
    • How to troubleshoot symbolic link issues on Windows
    • How to set buffer time
    • How to set up requires confirmation
    • How to set time-slot intervals
    • How to set up an event type to receive payments
    • How to test API in a local instance
    • How to use open-source scheduling infrastructure with HubSpot
    • How to white label the self hosted instance
    • Setting up your availability
      • Adding date override
    • Quick actions using command bar
Powered by GitBook
LogoLogo

Solutions

  • Individual
  • Teams
  • Ultimate
  • Platform

Follow us

  • Twitter
  • LinkedIn

Copyright 2023 Cal.com, Inc. All rights reserved.

On this page
  • Creating migrations
  • Error: The database schema is not empty
  • Resetting Prisma migrate

Was this helpful?

  1. Introduction
  2. Quick Start
  3. Self-hosting

Database migrations

PreviousVercelNextSSO setup

Last updated 2 years ago

Was this helpful?

As described in the , you should use the yarn workspace @calcom/prisma db-migrateor yarn workspace @calcom/prisma db-deploy command to update the database.

We use database migrations in order to handle changes to the database schema in a more secure and stable way. This is actually very common. The thing is that when just changing the schema in schema.prisma without creating migrations, the update to the newer database schema can damage or delete all data in production mode, since the system sometimes doesn't know how to transform the data from A to B. Using migrations, each step is reproducable, transparent and can be undone in a simple way.

Creating migrations

If you are modifying the codebase and make a change to the schema.prisma file, you must create a migration.

To create a migration for your previously changed schema.prisma, simply run the following:

yarn workspace @calcom/prisma db-migrate

Now, you must create a short name for your migration to describe what changed (for example, "user_add_email_verified"). Then just add and commit it with the corresponding code that uses your new database schema.

Always keep an eye on what migrations Prisma is generating. Prisma often happily will drop entire columns of data because it can't figure out what to do.

Error: The database schema is not empty

Prisma uses a database called _prisma_migrations to keep track of which migrations have been applied and which haven't. If your local migrations database doesn't match up with what's in the actual database, then Prisma will throw the following error:

Error: P3005

The database schema for `localhost:5432` is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline

In order to fix this, we need to tell Prisma which migrations have already been applied.

This can be done by running the following command, replacing migration_name with each migration that you have already applied:

yarn prisma migrate resolve --applied migration_name

You will need to run the command for each migration that you want to mark as applied.

Resetting Prisma migrate

When your local Prisma database runs out of sync with migrations on local and you are tearing your hair out, I’ve been there, so you don’t have to:

PostgreSQL

DELETE FROM "_prisma_migrations";

Quickly re-index

# Run the following to easily apply all migrations in the prisma/migrations directory
ls -1a prisma/migrations/ | grep 2021 | xargs -I{} prisma migrate resolve --applied {}
upgrade guide