Skip to content

andibde/pocketbase_migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

PocketBase Collection Migration

This project contains a simple Python script for migrating all records from one PocketBase collection to the same collection in another PocketBase database.

The script assumes both PocketBase databases already contain the same collection with the same fields.

What It Does

  • Prompts for a source PocketBase URL
  • Prompts for a destination PocketBase URL
  • Prompts for the collection name to migrate
  • Prompts for superuser credentials for both PocketBase databases
  • Fetches all records from the source collection
  • Creates those records in the destination collection
  • Does not delete or overwrite existing destination records

Requirements

  • Python 3
  • Superuser or admin access to both PocketBase databases
  • The collection must already exist in both databases
  • The collection schema should be the same in both databases

No extra Python packages are required.

Prepare The Destination Collection

Before running the migration script, make sure the destination PocketBase database has the same collection schema as the source database.

You can copy the collection structure through the PocketBase admin UI:

  1. Open the source PocketBase admin dashboard.
  2. Go to Settings.
  3. Click Export Collections.
  4. Select the collection/table you want to migrate.
  5. Copy the exported JSON.
  6. Open the destination PocketBase admin dashboard.
  7. Go to Settings.
  8. Click Import Collections.
  9. Paste the copied JSON.
  10. Click Review.
  11. Import the collection from there.

After the collection exists in the destination database, run the migration script to copy the records.

Run The Script

From the project folder, run:

python3 migrate_collection.py

Example Walkthrough

This is an anonymized example showing what a successful migration looks like.

user@MacBook PB_Migration % python3 migrate_collection.py
PocketBase collection migration
This creates records in the destination collection; it does not delete existing records.
File upload fields are not migrated by this simple script.

Source PocketBase URL: https://source-pocketbase.example.com/
Destination PocketBase URL: https://destination-pocketbase.example.com/
Collection name to migrate: domains

Source superuser credentials
Email: source-admin@example.com
Password:

Destination superuser credentials
Email: destination-admin@example.com
Password:
Preserve source record IDs [Y/n]: y

Authenticating...
Fetching source records...
Found 21 record(s).
Press Enter to start migration...
Migrated 21/21
Migration complete: 21 record(s) migrated in 2.8s.

Notes

  • Password input is hidden while typing.
  • Choosing y for Preserve source record IDs keeps the same record IDs in the destination database.
  • If the destination database already contains records with the same IDs, PocketBase may reject those records.
  • File upload fields are not migrated by this simple script.
  • Existing records in the destination collection are not removed.

About

Migrate a table from a old pocketbase instance to a new one

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages