# PocketBase Data Management Guide ## For SvelteKit Projects ### Overview This guide explains how to properly manage PocketBase (PB) data in different environments of your SvelteKit project. ### Important: Never Commit pb_data The `pb_data` folder contains sensitive information including: - User accounts - Authentication data - File uploads - Database content 🚫 **Always add `pb_data/` to your `.gitignore`** ### Environment Setup #### 1. Development Environment Each developer works with their own local PocketBase instance: ```bash # .gitignore pb_data/ .env.* !.env.example ``` Local development workflow: 1. Clone the repository 2. Start PocketBase locally 3. Create your own admin account 4. Work with your own test data #### 2. Testing Environment - Shared testing instance - Common test data - Usually hosted (e.g., on staging server) - Reset periodically #### 3. Production Environment - Separate production instance - Real user data - Regular backups - Strict security measures ### Project Structure ``` ├── src/ ├── pb_migrations/ # ✅ Version controlled │ ├── 1234_initial.js │ └── 5678_add_users.js ├── pb_hooks/ # ✅ Version controlled ├── scripts/ # ✅ Version controlled │ ├── seed-test.ts │ └── init-dev.ts ├── pb_data/ # ❌ NOT version controlled └── .gitignore ``` ### Environment-Specific Data Handling #### Development ```bash # Local development npm run dev # Reset local database when needed npm run init-dev ``` #### Testing ```bash # Seed test environment with common test data npm run seed-test ``` #### Production - Never manually modify production data - Use migrations for schema changes - Implement automated backups - Monitor database size ### Best Practices 1. **Version Control** - ✅ DO commit: migrations, hooks, schemas - ❌ DON'T commit: pb_data, .env files 2. **Data Management** - Use migrations for schema changes - Create seed scripts for test data - Document setup procedures 3. **Security** - Use different admin credentials per environment - Implement proper backup strategies - Monitor access logs ### Quick Setup Guide 1. **Initial Setup** ```bash git clone your-project cp .env.example .env # Edit .env with your settings npm install ``` 2. **Start Development** ```bash ./pocketbase serve npm run dev ``` 3. **Reset Development Database** ```bash npm run init-dev ``` ### Common Issues and Solutions 1. **pb_data in Git** - If accidentally committed: ```bash git rm -r --cached pb_data git commit -m "Remove pb_data from git" ``` 2. **Different Data Per Environment** - Use environment-specific .env files - Create separate backup strategies - Use different admin credentials ### Additional Resources - [PocketBase Documentation](https://pocketbase.io/docs/) - [SvelteKit Documentation](https://kit.svelte.dev/docs) - Project-specific setup guide (create in your repo's README.md) ### Support For issues: 1. Check project documentation 2. Review PocketBase logs 3. Contact project maintainers --- Remember: The key is to keep sensitive data out of version control while maintaining reproducible environments for development, testing, and production.