Files
dbis_core/MIGRATION_READY.md

164 lines
4.0 KiB
Markdown
Raw Permalink Normal View History

# Chart of Accounts Migration - Ready to Run
## ✅ Status: All Files Prepared
The Chart of Accounts migration and initialization scripts are ready. You need to provide database connection information to proceed.
---
## 📋 What's Ready
1.**Prisma Model**: `ChartOfAccount` added to schema
2.**Migration Script**: `scripts/run-chart-of-accounts-migration.sh`
3.**Initialization Script**: `scripts/initialize-chart-of-accounts.ts`
4.**Prisma Client**: Generated (includes ChartOfAccount model)
---
## 🚀 To Run Migration
### Option 1: Set DATABASE_URL Environment Variable
```bash
cd /home/intlc/projects/proxmox/dbis_core
# Set DATABASE_URL (replace with your actual connection string)
export DATABASE_URL="postgresql://user:password@host:port/database"
# Run the migration script
./scripts/run-chart-of-accounts-migration.sh
```
### Option 2: Create .env File
```bash
cd /home/intlc/projects/proxmox/dbis_core
# Create .env file
cat > .env << EOF
DATABASE_URL=postgresql://user:password@host:port/database
EOF
# Run the migration script
./scripts/run-chart-of-accounts-migration.sh
```
### Option 3: Manual Steps
```bash
cd /home/intlc/projects/proxmox/dbis_core
# 1. Set DATABASE_URL
export DATABASE_URL="postgresql://user:password@host:port/database"
# 2. Generate Prisma client (already done, but can re-run)
npx prisma generate
# 3. Create and apply migration
npx prisma migrate dev --name add_chart_of_accounts
# 4. Initialize accounts
ts-node scripts/initialize-chart-of-accounts.ts
```
---
## 🔗 Database Connection Examples
### Local Development
```bash
export DATABASE_URL="postgresql://postgres:password@localhost:5432/dbis_core"
```
### Production (Based on Deployment Docs)
```bash
export DATABASE_URL="postgresql://dbis:8cba649443f97436db43b34ab2c0e75b5cf15611bef9c099cee6fb22cc3d7771@192.168.11.100:5432/dbis_core"
```
---
## ✅ What the Script Does
1. **Generates Prisma Client** - Updates client with ChartOfAccount model
2. **Creates Migration** - Creates SQL migration file for `chart_of_accounts` table
3. **Applies Migration** - Runs the migration against your database
4. **Initializes Accounts** - Creates 50+ standard accounts with USGAAP/IFRS classifications
---
## 📊 Expected Output
After successful run, you should see:
```
==========================================
Chart of Accounts Migration & Setup
==========================================
Step 1: Generating Prisma client...
✔ Generated Prisma Client
Step 2: Creating migration...
✔ Migration created and applied
Step 3: Initializing Chart of Accounts...
Initializing Chart of Accounts...
✅ Chart of Accounts initialized successfully!
✅ Total accounts created: 50+
📊 Account Summary:
Assets: 15+
Liabilities: 8+
Equity: 6+
Revenue: 5+
Expenses: 8+
==========================================
✅ Chart of Accounts setup complete!
==========================================
```
---
## 🔍 Verification
After migration, verify accounts were created:
```bash
# Via Prisma Studio (GUI)
npx prisma studio
# Via SQL
psql $DATABASE_URL -c "SELECT COUNT(*) FROM chart_of_accounts;"
psql $DATABASE_URL -c "SELECT account_code, account_name, category FROM chart_of_accounts WHERE level = 1 ORDER BY account_code;"
```
---
## ⚠️ Important Notes
1. **Database Must Exist**: Ensure the database exists before running migration
2. **Connection Required**: You need network access to the database
3. **Permissions**: Database user needs CREATE TABLE and INSERT permissions
4. **Backup**: Consider backing up database before migration (if production)
---
## 🐛 Troubleshooting
### "DATABASE_URL not found"
- Set `export DATABASE_URL="..."` or create `.env` file
### "Migration already exists"
- If partially applied: `npx prisma migrate resolve --applied add_chart_of_accounts`
- Or reset (⚠️ deletes data): `npx prisma migrate reset`
### "Cannot connect to database"
- Check database is running
- Verify connection string is correct
- Check network/firewall settings
---
**Ready to run!** Just provide the `DATABASE_URL` and execute the script.