Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

docs: add prisma migration documentation

Marc Seitz468f3faf0b23
diff --git a/prisma/README.md b/prisma/README.md
new file mode 100644
index 00000000..8dd9a268
--- /dev/null
+++ b/prisma/README.md
@@ -0,0 +1,42 @@
+## Create migrations after changes in schema.prisma
+
+So you have made changes to the schema.prisma file and you want to apply those changes to the database.
+
+Chances are you are getting this error from Prisma after running `npx prisma migrate dev`:
+
+```txt
+Drift detected: Your database schema is not in sync with your migration history.
+...
+Do you want to continue? All data will be lost.
+```
+
+### Requirements
+
+1. Local prisma
+
+```bash
+npm install -g prisma
+# npx prisma won't work
+```
+
+2. shadow database, otherwise you overwrite your local db
+
+### Steps
+
+- Create a new migration folder
+
+```bash
+mkdir -p prisma/migrations/20240408000000_add_model
+```
+
+- Generate the migration
+
+```bash
+prisma migrate diff --from-migrations prisma/migrations --to-schema-datamodel prisma/schema.prisma --shadow-database-url "postgresql://<USER>@localhost:5432/papermark-shadow-db" --script > prisma/migrations/20240408000000_add_model/migration.sql
+```
+
+- Apply the migration
+
+```bash
+prisma migrate resolve --applied 20240408000000_add_model
+```