Skip to content

🎯 Merge Request Overview#96

Merged
Santiago1010 merged 19 commits into
developfrom
feature/migrations-seeders
Jan 28, 2026
Merged

🎯 Merge Request Overview#96
Santiago1010 merged 19 commits into
developfrom
feature/migrations-seeders

Conversation

@Santiago1010
Copy link
Copy Markdown
Owner

This comprehensive database refactor implements a complete overhaul of the migration and seeding system, standardizes database schema conventions, and introduces production-ready database management tooling. The changes establish a robust foundation for internationalization, improve data integrity through proper foreign key management, and automate database setup processes.

📋 Changes Summary

Type: Feature, Refactor, Bugfix
Scope: Database migrations, seeders, configuration, and tooling
Breaking: Yes - Includes table renaming and column type changes

🔄 What's Changed

  • Added:

    • HTTP request logging table with comprehensive request/response tracking
    • Currencies table migration for international financial data
    • Automated migration and seeding scripts with Vault integration
    • Database setup npm scripts (db:setup, migrate:undo, seed)
    • Political divisions table with JSON-based multilingual support
  • Modified:

    • Standardized all timestamp columns from Sequelize.DATE to TIMESTAMP
    • Renamed geo_divisionsgeo_political_divisions table
    • Updated seed data structures for JSON-based internationalization
    • Reorganized foreign key constraints to parent table migrations
    • Improved seeder idempotency with updateOnDuplicate
  • Fixed:

    • Database name usage in migration/seeder scripts (now uses Vault secrets)
    • Foreign key constraint consistency across all tables
    • Column naming inconsistencies in language seeder (id_flagflag_id)
    • Duplicate migration files and constraint definitions
  • Removed:

    • Temporary sequelize configuration files
    • Unused data_types_identification table migration
    • Duplicate create-cities-table migration
    • Outdated scope junction table migrations (later re-added)

🏗️ Implementation Details

Architecture Changes

  • Consolidated Constraint Management: Moved foreign key constraints from junction tables to parent table migrations for better organization and maintainability
  • Internationalization Support: Converted country and language data to JSON structures for multilingual support
  • Automated Database Management: Created a unified tooling system for migrations and seeding with secure credential handling

Key Components Modified

  • migrations/ - Complete overhaul of 20+ migration files with standardized conventions
  • seeders/ - Updated all seed data with JSON structures and idempotent insertion
  • scripts/run-migrations.script.js - Vault-integrated migration runner with proper error handling
  • scripts/run-seeders.script.js - Parallel seeder script with the same security standards
  • package.json - Added db:setup, migrate:undo, and seed npm scripts
  • config/ - Removed temporary configuration files after script improvements

Dependencies

  • New dependencies added: xml2js for XML parsing
  • Dependencies updated: None
  • Dependencies removed: None

🧪 Quality Assurance

Testing Strategy

  • Unit Tests: All migrations validated through manual execution
  • Integration Tests: Full database setup tested end-to-end
  • E2E Tests: Migration rollback and re-application tested
  • Manual Testing: Complete database rebuild with new scripts

Testing Instructions

# Test the complete database setup process
npm run db:setup

# Test individual components
npm run migrate
npm run migrate:undo
npm run seed

# Verify data integrity
mysql -u root -p test_base -e "SELECT COUNT(*) FROM geo_political_divisions;"

📊 Performance Impact

  • Performance improved
  • No performance impact
  • Performance degraded
  • Performance analysis required

Metrics:

  • Reduced migration execution time through constraint reorganization
  • Improved seeder performance with batch processing and idempotent operations
  • Better query performance with proper indexing and foreign keys

🔒 Security Considerations

  • Security review required
  • New security measures implemented
  • No security implications
  • Vulnerability addressed

Security Enhancements:

  • Database credentials sourced from Vault instead of hardcoded values
  • Temporary configuration files automatically cleaned up after execution
  • Sensitive data (tokens, passwords) properly excluded from HTTP logs

🚀 Deployment Notes

Pre-deployment Requirements

  1. Ensure Vault is configured with database secrets under db path
  2. Verify target database server is accessible with proper permissions
  3. Backup existing database if performing migration on production

Post-deployment Actions

  1. Verify all tables were created with SHOW TABLES;
  2. Validate foreign key constraints with SHOW CREATE TABLE on key tables
  3. Test API endpoints that depend on new tables (HTTP logs, roles, etc.)

Rollback Plan

# Rollback to previous state
npm run migrate:undo

# Complete database reset (destructive)
mysql -u root -p -e "DROP DATABASE IF EXISTS test_base; CREATE DATABASE test_base;"

🔗 Related Work

✅ Definition of Done

  • Code meets acceptance criteria
  • Code reviewed and approved (self-reviewed due to nature)
  • Tests written and passing (manual testing completed)
  • Documentation updated (commit messages provide comprehensive docs)
  • Performance acceptable (improved through optimization)
  • Security considerations addressed (Vault integration)
  • Browser compatibility verified (N/A - backend only)
  • Mobile responsiveness checked (N/A - backend only)

👥 Review Assignment

Required Reviewers

  • @Database-Admin - Database schema and migration strategy
  • @security-lead - Vault integration and credential handling
  • @backend-lead - Overall architecture and implementation

Optional Reviewers

📝 Additional Context

Known Issues/Limitations

  1. birth_date column changed from DATEONLY to TIMESTAMP - requires application code updates
  2. Large seed files (divisions, countries) may require memory optimization for production
  3. Migration rollback may fail if dependent data exists (constraint violations)

Future Improvements

  1. Implement migration versioning and state tracking
  2. Add validation scripts to verify data integrity post-migration
  3. Create automated backup/restore procedures for production deployments
  4. Implement database performance monitoring for new tables
  5. Add schema documentation generation from migration files

Critical Changes Requiring Attention

  1. BREAKING: geo_divisions table renamed to geo_political_divisions
  2. BREAKING: birth_date column type changed (requires code updates)
  3. BREAKING: All timestamp columns standardized to TIMESTAMP
  4. BREAKING: Country abbreviations now stored as JSON strings

Migration Path: Run npm run db:setup on development first, then coordinate application code updates before production deployment.

- Change field names from 'flatd_2d'/'flatd_3d' to 'flat_2d'/'flat_3d' for consistency
- Remove leading '/flags/' prefix from image paths and country emojis
- Update country names and add new entries (e.g., aland, d_r_congo, western_sahara)
- Reorder and adjust country list sequence, increasing total from 247 to 250 entries
- Add new 'data_flags' table for storing country flag information
- Add new 'geo_cities' table with proper foreign key constraints
- Rename 'geo_sub_divisions' table to 'geo_divisions' across all references
- Remove 'surface_area' column from 'geo_countries' table
- Update Sequelize config path from 'index.js' to 'sequelize.config.js'
- Add placeholder seeder for country-language relationships
- Update CHANGELOG.md to reflect table name changes
- Populate geo_countries_has_languages table with 291 country-language relationships
- Implement batch insertion for better performance during seeding
- Include proper up/down migration methods for data integrity
- Add sequelize Op dependency for bulk delete operations
- Mark principal languages for each country relationship
- Remove 'surface_area' column from geo_continents migration and seeder
- Refactor seeders to use direct data arrays instead of get() methods
- Add down migration methods with Op.or conditions for proper rollback
- Include sequelize Op dependency for bulk delete operations
- Update seeders for continents, dial codes, and country-currencies
Refactor seeders to use direct data arrays instead of get() methods
Add seed data for default roles (admin, technical_support, customer) including security levels and target assignments.
- Rename `geo_divisions` table to `geo_political_divisions`
- Remove and re-add foreign key constraints for capitals
- Fix seeder table references
- Remove unused endpoints/pages scope junction tables
- Update seeders to use `updateOnDuplicate`

BREAKING CHANGE: `geo_divisions` table renamed to `geo_political_divisions`. Update queries and models accordingly.
Add the 0.Project_info folder to the biome.json ignore list to prevent linting on project documentation files.
Re-create config_endpoints_has_required_scopes and config_pages_has_required_scopes tables. Move scope foreign key constraints from junction tables to the scopes table migration. Remove duplicate constraint from roles-scopes table.
- Add logs_http_requests table to track HTTP requests, responses, and errors.
- Includes foreign keys to accesses, pages, and endpoints.
- Implements table partitioning by date for performance.
- Move foreign key constraints to parent table migrations for better organization.
- Remove duplicate create-cities migration and data_types_identification table.
- Add currencies table migration and run-migrations script.
- Update TINYTEXT columns to TEXT('tiny') for compatibility.
- Add npm script 'migrate' for running migrations with Vault credentials.
- Move foreign key constraints to parent table migrations for better organization.
- Remove duplicate create-cities migration and data_types_identification table.
- Add currencies table migration and run-migrations script.
- Update TINYTEXT columns to TEXT('tiny') for compatibility.
- Add npm script 'migrate' for running migrations with Vault credentials.
- Change Sequelize.DATE to 'TIMESTAMP' for better MySQL compatibility.
- Remove temporary sequelize config file and table partitioning from logs.
- Move user foreign key constraint to users table migration.
- Fix flag index names to indicate uniqueness consistently.
- Add temporary sequelize config and run-seeders script.
- Create npm scripts: 'seed', 'migrate:undo', and 'db:setup' for database management.
- Change political divisions name column to JSON for multilingual support.
- Convert country abbreviation to JSON string in seed data.
- Add updateOnDuplicate options to seeder for better idempotency.
- Remove geonameId comment from divisions seeder.
- Remove temporary sequelize config file after migration script improvements.
- Update languages seeder: rename 'id_flag' to 'flag_id' and 'public' to 'is_public'.
- Fix roles seeder: correct security_level_id values and insert array format.
- Clean up column names for consistency with database schema.
Update migration and seeder scripts to use the database name from Vault secrets instead of hardcoded 'test_base' value.
@Santiago1010 Santiago1010 added documentation Improvements or additions to documentation enhancement New feature or request automation Code automation and/or deployment tasks. labels Jan 28, 2026
@Santiago1010 Santiago1010 self-assigned this Jan 28, 2026
  Auto-generated by GitHub Actions workflow
  PR: #96
  Workflow: Auto Version & Changelog
  Run ID: 21458401750
@github-actions
Copy link
Copy Markdown

🚀 Auto-versioning complete!

📦 New version: 1.24.0
📋 CHANGELOG.md and package.json updated
👤 Author: Santiago1010
✅ Approved by: DiegoAlejandroNino

This PR is ready for merging.

@Santiago1010 Santiago1010 merged commit b36b1d0 into develop Jan 28, 2026
@Santiago1010 Santiago1010 deleted the feature/migrations-seeders branch January 28, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Code automation and/or deployment tasks. documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants