diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e76b2c14e..ee7cf0290 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -101,6 +101,46 @@ We use [Weblate](https://jellyseerr.borgcube.de/projects/jellyseerr/jellyseerr-f Translation status +## Migrations + +If you are adding a new feature that requires a database migration, you will need to create 2 migrations: one for SQLite and one for PostgreSQL. Here is how you could do it: + +1. Create a PostgreSQL database or use an existing one: + +```bash +sudo docker run --name postgres-jellyseerr -e POSTGRES_PASSWORD=postgres -d -p 127.0.0.1:5432:5432/tcp postgres:latest +``` + +2. Reset the SQLite database and the PostgreSQL database: + +```bash +rm config/db/db.* +rm config/settings.* +PGPASSWORD=postgres sudo docker exec -it postgres-jellyseerr /usr/bin/psql -h 127.0.0.1 -U postgres -c "DROP DATABASE IF EXISTS jellyseerr;" +PGPASSWORD=postgres sudo docker exec -it postgres-jellyseerr /usr/bin/psql -h 127.0.0.1 -U postgres -c "CREATE DATABASE jellyseerr;" +``` + +3. Checkout the `develop` branch and create the original database for SQLite and PostgreSQL so that TypeORM can automatically generate the migrations: + +```bash +git checkout develop +pnpm i +rm -r .next dist; pnpm build +pnpm start +DB_TYPE="postgres" DB_USER=postgres DB_PASS=postgres pnpm start +``` + +(You can shutdown the server once the message "Server ready on 5055" appears) + +4. Let TypeORM generate the migrations: + +```bash +git checkout -b your-feature-branch +pnpm i +pnpm migration:generate server/migration/sqlite/YourMigrationName +DB_TYPE="postgres" DB_USER=postgres DB_PASS=postgres pnpm migration:generate server/migration/postgres/YourMigrationName +``` + ## Attribution This contribution guide was inspired by the [Next.js](https://github.com/vercel/next.js), [Radarr](https://github.com/Radarr/Radarr), and [Overseerr](https://github.com/sct/Overseerr) contribution guides.