Custom Firestore Database Deployment Guide
This Help Desk application is configured to use a custom Firestore database named rclhelpdb instead of the default database. This document provides instructions for deploying with this custom database configuration.
Prerequisites
- Ensure you have created a Firestore database named
rclhelpdbin your Firebase project - Firebase CLI installed and logged in
- The project has been properly set up with the necessary permissions (see fix-functions-permissions.md)
Environment Variables
Update your .env.local file to include the database name:
NEXT_PUBLIC_FIREBASE_DATABASE_ID=rclhelpdbSetup Configuration
Before deploying the resources, you need to configure Firebase Functions to use the custom database:
cd functionschmod +x setup-database.sh./setup-database.shThis script will:
- Configure Firebase Functions environment variables
- Set the custom database ID in Firebase Functions configuration
- Deploy the functions with the proper configuration
Deploy Firebase Resources
-
Deploy Firestore Rules
The rules have been updated to target the
rclhelpdbdatabase:Terminal window firebase deploy --only firestore:rules -
Deploy Firestore Indexes
Deploy the indexes to the custom database:
Terminal window firebase deploy --only firestore:indexes -
Deploy Storage Rules
Terminal window firebase deploy --only storage -
Deploy Functions (Alternative Method)
If the setup script doesnβt work, you can manually configure and deploy:
Terminal window # Set environment variablesfirebase functions:config:set firestore.database_id=rclhelpdb# Deploy the functionsfirebase deploy --only functions
Troubleshooting
Functions Deployment Issues
If you encounter issues with deploying functions:
- Make sure the database exists in your Firebase project
- Check that the service account has the proper permissions (see fix-functions-permissions.md)
- Verify in the Firebase Console that your custom database is properly set up
Client Connection Issues
If the client application cannot connect to the custom database:
- Make sure your
.env.localfile contains the correct database ID - Verify the Firestore rules are properly deployed to the custom database
- Check the browser console for any connection errors
Database Management
Accessing the Custom Database in Firebase Console
- Go to the Firebase Console
- Select your project
- Navigate to Firestore Database
- Use the database selector at the top of the page to switch to
rclhelpdb
Backup and Restore
When using a custom database, youβll need to specify the database ID in any export/import commands:
gcloud firestore export gs://your-backup-bucket/path --database=rclhelpdbMigration
If you need to migrate data from another database to rclhelpdb, you can use the Firebase Admin SDK in a script or Cloud Function:
const admin = require('firebase-admin');admin.initializeApp();
async function migrateData() { // Source database (default or another custom database) const sourceDb = admin.firestore().database('sourceDb');
// Target database (rclhelpdb) const targetDb = admin.firestore().database('rclhelpdb');
// Get data from source const usersSnapshot = await sourceDb.collection('users').get();
// Write to target const batch = targetDb.batch(); usersSnapshot.forEach(doc => { batch.set(targetDb.collection('users').doc(doc.id), doc.data()); });
await batch.commit();}