cal.pub0.org/apps/docs/pages/developer/migrations.mdx

42 lines
2.2 KiB
Plaintext
Raw Normal View History

---
title: Migrations
---
Migrate docs to mono repo (#1814) * Initial commit Created from https://vercel.com/new * Update config * Homepage * Self-hosting * Integrations * More docs pages * Developer docs * Update billing.mdx * Update install.mdx * Fix install guide * More fixes * Adding CSS guide * Fix capitalisation on Microsoft page * Added delete account update * Added Zapier integration question * Added GMeet integration part * Added Delete Account to Settings * unnecessary question mark * Added a link to Settings * Added stuff in Billing * Added a link to cal.com/signup * Capitalization * Added language change * Added more stuff in Event Types * Added how to change email * Added FAQ page * Spelling mistake * Added a title to FAQ * Added more stuff to Billing * Availability multi-booking * Deleted from Availability added to FAQ * Added to FAQ * Removed the dot * Added stuff to FAQ * Add license warning to adding CSS page * Update docker.mdx * Add import instructions * removed readme until we have our own * updated favicon, added cal sans * added new cal sans * Create README.md * renamed all github links * renamed more github links * Added team's Event Types * Clarified the Google Meet integration * Spelling error * Added primary calendar tutorial * Removed tutorial * primary calendar selection * Moved to subdirectory * Matching configs * Shares eslint config between web and docs * Removes format-schemas * Updates env file location in turbo * [docs] updates monorepo intructions Co-authored-by: baileypumfleet <pumfleet@hey.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: milospuac <97884287+milospuac@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@richelsen.net>
2022-02-11 19:33:35 +00:00
# Database Migrations
As described in the [upgrade guide](https://docs.cal.com/self-hosting/upgrade), you should use the `yarn workspace @calcom/prisma db-migrate` or `yarn workspace @calcom/prisma db-deploy` command to update the database.
Migrate docs to mono repo (#1814) * Initial commit Created from https://vercel.com/new * Update config * Homepage * Self-hosting * Integrations * More docs pages * Developer docs * Update billing.mdx * Update install.mdx * Fix install guide * More fixes * Adding CSS guide * Fix capitalisation on Microsoft page * Added delete account update * Added Zapier integration question * Added GMeet integration part * Added Delete Account to Settings * unnecessary question mark * Added a link to Settings * Added stuff in Billing * Added a link to cal.com/signup * Capitalization * Added language change * Added more stuff in Event Types * Added how to change email * Added FAQ page * Spelling mistake * Added a title to FAQ * Added more stuff to Billing * Availability multi-booking * Deleted from Availability added to FAQ * Added to FAQ * Removed the dot * Added stuff to FAQ * Add license warning to adding CSS page * Update docker.mdx * Add import instructions * removed readme until we have our own * updated favicon, added cal sans * added new cal sans * Create README.md * renamed all github links * renamed more github links * Added team's Event Types * Clarified the Google Meet integration * Spelling error * Added primary calendar tutorial * Removed tutorial * primary calendar selection * Moved to subdirectory * Matching configs * Shares eslint config between web and docs * Removes format-schemas * Updates env file location in turbo * [docs] updates monorepo intructions Co-authored-by: baileypumfleet <pumfleet@hey.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: milospuac <97884287+milospuac@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@richelsen.net>
2022-02-11 19:33:35 +00:00
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:
```sh
yarn workspace @calcom/prisma db-migrate
Migrate docs to mono repo (#1814) * Initial commit Created from https://vercel.com/new * Update config * Homepage * Self-hosting * Integrations * More docs pages * Developer docs * Update billing.mdx * Update install.mdx * Fix install guide * More fixes * Adding CSS guide * Fix capitalisation on Microsoft page * Added delete account update * Added Zapier integration question * Added GMeet integration part * Added Delete Account to Settings * unnecessary question mark * Added a link to Settings * Added stuff in Billing * Added a link to cal.com/signup * Capitalization * Added language change * Added more stuff in Event Types * Added how to change email * Added FAQ page * Spelling mistake * Added a title to FAQ * Added more stuff to Billing * Availability multi-booking * Deleted from Availability added to FAQ * Added to FAQ * Removed the dot * Added stuff to FAQ * Add license warning to adding CSS page * Update docker.mdx * Add import instructions * removed readme until we have our own * updated favicon, added cal sans * added new cal sans * Create README.md * renamed all github links * renamed more github links * Added team's Event Types * Clarified the Google Meet integration * Spelling error * Added primary calendar tutorial * Removed tutorial * primary calendar selection * Moved to subdirectory * Matching configs * Shares eslint config between web and docs * Removes format-schemas * Updates env file location in turbo * [docs] updates monorepo intructions Co-authored-by: baileypumfleet <pumfleet@hey.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: milospuac <97884287+milospuac@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@richelsen.net>
2022-02-11 19:33:35 +00:00
```
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.
:::caution
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:
```text
Migrate docs to mono repo (#1814) * Initial commit Created from https://vercel.com/new * Update config * Homepage * Self-hosting * Integrations * More docs pages * Developer docs * Update billing.mdx * Update install.mdx * Fix install guide * More fixes * Adding CSS guide * Fix capitalisation on Microsoft page * Added delete account update * Added Zapier integration question * Added GMeet integration part * Added Delete Account to Settings * unnecessary question mark * Added a link to Settings * Added stuff in Billing * Added a link to cal.com/signup * Capitalization * Added language change * Added more stuff in Event Types * Added how to change email * Added FAQ page * Spelling mistake * Added a title to FAQ * Added more stuff to Billing * Availability multi-booking * Deleted from Availability added to FAQ * Added to FAQ * Removed the dot * Added stuff to FAQ * Add license warning to adding CSS page * Update docker.mdx * Add import instructions * removed readme until we have our own * updated favicon, added cal sans * added new cal sans * Create README.md * renamed all github links * renamed more github links * Added team's Event Types * Clarified the Google Meet integration * Spelling error * Added primary calendar tutorial * Removed tutorial * primary calendar selection * Moved to subdirectory * Matching configs * Shares eslint config between web and docs * Removes format-schemas * Updates env file location in turbo * [docs] updates monorepo intructions Co-authored-by: baileypumfleet <pumfleet@hey.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: milospuac <97884287+milospuac@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@richelsen.net>
2022-02-11 19:33:35 +00:00
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:
```sh
yarn prisma migrate resolve --applied migration_name
Migrate docs to mono repo (#1814) * Initial commit Created from https://vercel.com/new * Update config * Homepage * Self-hosting * Integrations * More docs pages * Developer docs * Update billing.mdx * Update install.mdx * Fix install guide * More fixes * Adding CSS guide * Fix capitalisation on Microsoft page * Added delete account update * Added Zapier integration question * Added GMeet integration part * Added Delete Account to Settings * unnecessary question mark * Added a link to Settings * Added stuff in Billing * Added a link to cal.com/signup * Capitalization * Added language change * Added more stuff in Event Types * Added how to change email * Added FAQ page * Spelling mistake * Added a title to FAQ * Added more stuff to Billing * Availability multi-booking * Deleted from Availability added to FAQ * Added to FAQ * Removed the dot * Added stuff to FAQ * Add license warning to adding CSS page * Update docker.mdx * Add import instructions * removed readme until we have our own * updated favicon, added cal sans * added new cal sans * Create README.md * renamed all github links * renamed more github links * Added team's Event Types * Clarified the Google Meet integration * Spelling error * Added primary calendar tutorial * Removed tutorial * primary calendar selection * Moved to subdirectory * Matching configs * Shares eslint config between web and docs * Removes format-schemas * Updates env file location in turbo * [docs] updates monorepo intructions Co-authored-by: baileypumfleet <pumfleet@hey.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: milospuac <97884287+milospuac@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@richelsen.net>
2022-02-11 19:33:35 +00:00
```
You will need to run the command for each migration that you want to mark as applied.