Database Migration
Database Migration allows you to apply changes to a database schema in a controlled and repeatable way.
Instead of manually modifying database structures, migrations record each schema change as a sequence of operations that can be reviewed, versioned, and executed consistently.
Using migrations helps keep development, staging, and production databases synchronized.
Before you begin
Before creating a migration, ensure that you have:
- Completed your database design
- Validated the database schema
- Connected to the target database (if deployment is required)
[!NOTE] Database Migrations modify the database structure. Always review migration scripts before applying them.
Why use migrations?
Database Migrations help you:
- Track schema changes
- Synchronize multiple environments
- Maintain version history
- Reduce deployment errors
- Collaborate with team members
Migration workflow
Modify Database Model
│
▼
Detect Schema Changes
│
▼
Generate Migration
│
▼
Review Migration
│
▼
Apply MigrationCreate a migration
To create a migration:
- Open Database Engineering.
- Select Database Migration.
- Compare the current schema with the target schema.
- Generate a migration.
- Review the generated operations.
- Save the migration.
Migration operations
A migration may contain operations such as:
| Operation | Description |
|---|---|
| Create Table | Create a new table |
| Drop Table | Remove an existing table |
| Add Column | Add a new column |
| Remove Column | Delete a column |
| Rename Column | Rename a column |
| Modify Column | Change a column definition |
| Add Constraint | Create a new constraint |
| Remove Constraint | Delete an existing constraint |
| Create Index | Create a new index |
| Drop Index | Remove an existing index |
Review before applying
Before applying a migration, review:
- Added objects
- Removed objects
- Modified columns
- Constraint changes
- Relationship updates
Carefully reviewing migrations helps prevent unintended database changes.
Apply a migration
After reviewing the migration:
- Select the target database.
- Confirm the migration.
- Apply the changes.
- Verify the updated database schema.
Once completed, the database structure reflects the new schema.
Migration history
Each migration should be stored as part of your project’s history.
Maintaining migration history allows you to:
- Understand previous database changes
- Review schema evolution
- Collaborate with team members
- Track deployment history
Validation
Before applying a migration, Qubase validates:
- Invalid operations
- Missing dependencies
- Broken relationships
- Constraint conflicts
- Unsupported modifications
Validation helps reduce migration failures.
Best practices
- Review every migration before applying it.
- Test migrations in a development environment first.
- Keep migration history under version control.
- Apply migrations in the correct order.
- Back up important databases before major schema updates.
[!WARNING] Applying migrations directly to production databases without testing may result in unexpected downtime or data loss.