- Create organized migration folder structure: - database/ - Core schema changes and migrations - tests/ - Test scripts and verification queries - directus/ - Directus CMS configuration scripts - fixes/ - Database fixes and patches - archive/ - Historical and deprecated scripts - Move 60+ SQL files from root to appropriate folders - Add comprehensive README with usage guidelines - Consolidate old migrations_archive into new archive folder - Maintain clear separation of concerns for different script types Benefits: - Cleaner project root directory - Easier to find specific types of SQL scripts - Better organization for maintenance and development - Clear documentation for migration procedures - Proper separation of production vs development scripts |
||
|---|---|---|
| .. | ||
| archive | ||
| database | ||
| directus | ||
| fixes | ||
| tests | ||
| README.md | ||
Database Migrations & SQL Scripts
This directory contains all SQL scripts organized by purpose and category.
📁 Directory Structure
🗄️ database/
Core database schema changes and migration scripts that modify the database structure.
Files:
create_verification_tokens.sql- Creates email verification tokens tablefix_constraint.sql- Fixes database constraint syntax errorsupdate_user_status.sql- Updates user status enum with new moderation states
Usage:
# Apply database migrations
psql -d postgres -f migrations/database/create_verification_tokens.sql
🧪 tests/
Test scripts, verification queries, and diagnostic SQL used for testing and debugging.
Files:
check_*.sql- Various database inspection queriestest_*.sql- Test scripts for featurescount_*.sql- Count queries for verificationverify_*.sql- Verification scriptsfinal_*.sql- Final system tests
Usage:
# Run verification tests
psql -d postgres -f migrations/tests/check_tables.sql
psql -d postgres -f migrations/tests/test_moderation_integration.sql
🎨 directus/
Directus CMS configuration, collections, permissions, and UI setup scripts.
Files:
add_directus_*.sql- Directus collections and fieldsfix_directus_*.sql- Directus configuration fixesuse_existing_policy.sql- Directus policy setupfix_permissions_correct.sql- Permission fixes
Usage:
# Setup Directus collections
psql -d postgres -f migrations/directus/add_directus_collections.sql
🔧 fixes/
Database fixes, patches, and repair scripts for specific issues.
Files:
fix_collections_complete.sql- Complete Directus collections fixgrant_permissions.sql- Database permission grants
Usage:
# Apply database fixes
psql -d postgres -f migrations/fixes/fix_collections_complete.sql
📦 archive/
Historical scripts, temporary queries, and deprecated SQL files.
Files:
- All historical migration scripts
- Temporary diagnostic queries
- Deprecated or one-time scripts
- Original migrations_archive content
Usage:
# Archive scripts - for reference only
# Generally should not be run on production
🚀 Official Migrations
The official Go backend migrations are located in:
go-backend/internal/database/migrations/
These are timestamped migrations that are automatically applied by the Go application.
Current Official Migrations:
20260205000002_user_appeal_system_fixed.up.sql- User appeal system20260205000003_add_email_preferences.up.sql- Email preferences
📋 Usage Guidelines
🔴 Production
- Only use scripts from
database/and official Go migrations - Test thoroughly in staging first
- Always backup before applying
🟡 Staging
- Can use
tests/anddirectus/scripts - Verify functionality before production
🟢 Development
- All scripts available for testing
- Use
archive/for reference and experimentation
⚠️ Important Notes
- Always review scripts before running
- Check for dependencies between scripts
- Some scripts may be one-time use only
- Archive scripts may be outdated
🔄 Migration Order
For new deployments, follow this order:
- Database Schema (
database/) - Directus Setup (
directus/) - Apply Fixes (
fixes/) - Run Tests (
tests/) - Official Go Migrations (auto-applied)
📝 Adding New Scripts
When adding new SQL scripts:
- Choose appropriate folder based on purpose
- Use descriptive naming with date/prefix
- Add comments explaining purpose
- Test thoroughly before committing
- Update this README if adding new categories
Naming Convention:
YYYY-MM-DD_description.sqlfor migrationscheck_feature.sqlfor verification scriptstest_feature.sqlfor test scriptsfix_issue.sqlfor fix scripts
🛠️ Maintenance
- Review archive quarterly - remove outdated scripts
- Update documentation - keep README current
- Test migrations - ensure they work with current schema
- Backup before changes - always backup production data
Last Updated: 2026-02-05 Maintainer: Development Team