Troubleshooting
This guide covers common issues you might encounter while using Astroladb and how to resolve them.
Installation Issues
Section titled “Installation Issues”Command Not Found After Installation
Section titled “Command Not Found After Installation”Problem: Running alab returns “command not found”
Solutions:
-
Check if binary is installed:
Terminal window which alab -
Verify PATH includes install location:
Terminal window echo $PATH | grep -o '/usr/local/bin' -
Add to PATH if needed:
Terminal window # Add to ~/.bashrc or ~/.zshrcexport PATH=$PATH:/usr/local/bin# Reload shell configurationsource ~/.bashrc # or source ~/.zshrc -
For Go install users:
Terminal window # Ensure GOPATH/bin is in PATHexport PATH=$PATH:$(go env GOPATH)/bin
Permission Denied on Linux/macOS
Section titled “Permission Denied on Linux/macOS”Problem: Install script fails with permission errors
Solution:
# Run with sudocurl -fsSL https://raw.githubusercontent.com/hlop3z/astroladb/main/install.sh | sudo sh
# Or manually download and installcurl -fsSL https://raw.githubusercontent.com/hlop3z/astroladb/main/install.sh -o install.shchmod +x install.shsudo ./install.shConfiguration Issues
Section titled “Configuration Issues”Database Connection Failures
Section titled “Database Connection Failures”Problem: alab migrate fails with connection errors
Diagnosis:
# Check if PostgreSQL is runningpg_isready -h localhost -p 5432
# Test connection manuallypsql "postgres://user:pass@localhost:5432/mydb"Common Causes:
-
Database not running
Terminal window # Start PostgreSQL (varies by system)sudo systemctl start postgresql # Linux systemdbrew services start postgresql # macOS Homebrew -
Wrong credentials in alab.yaml
database:url: postgres://correctuser:correctpass@localhost:5432/mydb -
Database doesn’t exist
Terminal window # Create database firstcreatedb mydb# orpsql -c "CREATE DATABASE mydb;" -
Port mismatch
Terminal window # Check PostgreSQL portpg_isready -h localhost -p 5432# Update alab.yaml with correct port
File Path Issues
Section titled “File Path Issues”Problem: alab init or schema files not found
Solution:
-
Ensure you’re in project root:
Terminal window pwd # Should show your project directoryls alab.yaml # Should exist after init -
Check schema path in config:
schemas: ./schemas # Relative to alab.yaml location -
Verify directory structure:
Terminal window tree -L 2# Should show:# ├── alab.yaml# ├── schemas/# └── migrations/
Schema Definition Issues
Section titled “Schema Definition Issues”Namespace Missing Errors
Section titled “Namespace Missing Errors”Problem: Error: “belongs_to requires namespace (use ‘namespace.table’)”
Solution:
Always use fully qualified references with namespace:
// ❌ Wrong - missing namespaceauthor: col.belongs_to("user")
// ✅ Correct - includes namespaceauthor: col.belongs_to("auth.user")String Length Required Error
Section titled “String Length Required Error”Problem: Error: “string() requires a positive length”
Solution:
Always specify length for col.string():
// ❌ Wrongname: col.string()
// ✅ Correctname: col.string(100)
// Or use semantic types (recommended)name: col.name() // Automatically uses string(100)Invalid Enum Values
Section titled “Invalid Enum Values”Problem: Enum validation fails during migration
Solution:
Ensure enum values are strings, not numbers:
// ❌ Wrong - numbers not allowedstatus: col.enum([1, 2, 3])
// ✅ Correct - use stringsstatus: col.enum(["pending", "approved", "rejected"])Circular Relationship Dependencies
Section titled “Circular Relationship Dependencies”Problem: Can’t create tables due to circular foreign keys
Solution:
-
Make one relationship optional:
// In user.jsexport default table({id: col.id(),primary_team: col.belongs_to("team.team").optional(),});// In team.jsexport default table({id: col.id(),owner: col.belongs_to("auth.user"),}); -
Or create relationships in a second migration after both tables exist.
Migration Issues
Section titled “Migration Issues”Migration Already Applied
Section titled “Migration Already Applied”Problem: “Migration 001_create_users.sql already applied”
This is normal. Astroladb tracks which migrations have run. If you need to re-run:
# Rollback last migrationalab rollback
# Then apply againalab migrateMigration Failed Mid-Execution
Section titled “Migration Failed Mid-Execution”Problem: Migration partially applied, database in inconsistent state
Solution:
-
Check migration status:
Terminal window alab status -
Manually fix the database:
Terminal window # Connect to databasepsql "postgres://user:pass@localhost:5432/mydb"# Check what was created\dt # List tables# Manually drop partial tables if neededDROP TABLE IF EXISTS incomplete_table; -
Mark migration as not applied:
Terminal window # If migration status is stuck, you may need to manually# update the migration tracking table -
Re-run migration:
Terminal window alab migrate
Foreign Key Constraint Violations
Section titled “Foreign Key Constraint Violations”Problem: Migration fails with FK constraint error
Solution:
-
Check that referenced table exists:
// Make sure auth.user exists before referencing itauthor: col.belongs_to("auth.user") -
Ensure migrations run in correct order:
- Migrations run in alphabetical/timestamp order
- Create parent tables before child tables
- Use
alab statusto see execution order
Rollback Not Working
Section titled “Rollback Not Working”Problem: alab rollback doesn’t work or corrupts data
Note: Rollbacks are still experimental. Always:
-
Backup before rolling back:
Terminal window # PostgreSQLpg_dump mydb > backup.sql# SQLitecp ./dev.db ./dev.db.backup -
Use dry run first:
Terminal window alab rollback --dry -
For production, prefer forward migrations:
- Create a new migration to fix issues
- Don’t rollback in production
Export Issues
Section titled “Export Issues”Types Not Generating
Section titled “Types Not Generating”Problem: alab export runs but files not created
Diagnosis:
-
Check export output directory:
Terminal window ls -la generated/ -
Verify format specified:
Terminal window # Must specify formatalab export -f typescript# oralab export -f all -
Check for schema errors:
Terminal window alab check # Validate schemas first
Type Mismatches
Section titled “Type Mismatches”Problem: Generated types don’t match database
Solution:
-
Ensure migrations are applied:
Terminal window alab migrate -
Re-export:
Terminal window alab export -f all -
Check for hidden fields:
col.password_hash()is automatically hidden- Won’t appear in generated types
Performance Issues
Section titled “Performance Issues”Slow Schema Parsing
Section titled “Slow Schema Parsing”Problem: alab commands are slow
Possible causes:
- Very large number of schema files - Consider splitting into modules
- Complex relationships - Simplify if possible
- File system issues - Check disk I/O
Migration Takes Too Long
Section titled “Migration Takes Too Long”Problem: Migration hangs or runs very slowly
Diagnosis:
-
Check what SQL is running:
Terminal window alab migrate --dry # Preview SQL -
Look for expensive operations:
- Creating indexes on large tables (expected to be slow)
- Backfilling millions of rows
- Complex CHECK constraints
Solutions:
- Split into smaller migrations
- Add indexes separately after data is loaded
- Use database-specific optimizations
Getting Help
Section titled “Getting Help”If you can’t resolve your issue:
-
Check the documentation - Search for specific error messages
-
Validate your schema:
Terminal window alab check -
Enable verbose logging (if available):
Terminal window alab --verbose migrate -
File a GitHub issue with:
- Astroladb version (
alab --version) - Database type and version
- Relevant schema code
- Full error message
- Steps to reproduce
- Astroladb version (
Common Error Messages
Section titled “Common Error Messages”| Error | Cause | Solution |
|---|---|---|
| ”namespace required” | Missing namespace in reference | Use "ns.table" format |
| ”length required” | No length for string() | Add length: col.string(100) |
| ”migration already applied” | Trying to re-run migration | Use alab rollback first |
| ”table not found” | Migration order issue | Check dependencies |
| ”connection refused” | Database not running | Start database service |
| ”command not found” | alab not in PATH | Add to PATH |
Best Practices to Avoid Issues
Section titled “Best Practices to Avoid Issues”- Always use semantic types when possible - They have sensible defaults
- Use
--dryflag - Preview changes before applying - Run
alab check- Validate before migrating - Backup before migrations - Especially in production
- Version control everything - Commit schemas and migrations
- Test locally first - Don’t migrate production directly
- Use environment variables - Keep credentials out of config files