-
Notifications
You must be signed in to change notification settings - Fork 441
Data Migrations
In OBS codebase we differentiate migrations that only affect the database structure from migrations that modify the already existing data.
The first type are the common Rails migrations we all know.
The second type are what we call data migrations and they are occasionally needed to modify data that is already in the database. Something that shouldn't be mixed with the evolution of the database structure, so they are located in a different directory and are executed in a different way. We use the gem data-migrate to handle this kind of migrations.
Table comparing both:
Migration | Data Migration | |
---|---|---|
Location: | db/migrations/ | db/data/ |
Generating a new migration file: | rails g migration AddSomethingToSomewhere |
rails g data_migration ModifySomething |
Run the migration: | rake db:migrate |
rake data:migrate |
Last version tracking on: | db/structure.sql | db/data_schema.rb |
It is a good practice to carefully test data migrations before applying them on production databases. This is possible by adding rspec tests under spec/db/data/
.
The test should ...
- require the data migration file,
- include the flag
type: :migration
, - test the
up
method.
- Development Environment Overview
- Development Environment Tips & Tricks
- Spec-Tips
- Code Style
- Rubocop
- Testing with VCR
- Authentication
- Authorization
- Autocomplete
- BS Requests
- Events
- ProjectLog
- Notifications
- Feature Toggles
- Build Results
- Attrib classes
- Flags
- The BackendPackage Cache
- Maintenance classes
- Cloud uploader
- Delayed Jobs
- Staging Workflow
- StatusHistory
- OBS API
- Owner Search
- Search
- Links
- Distributions
- Repository
- Data Migrations
- next_rails
- Ruby Update
- Rails Profiling
- Installing a local LDAP-server
- Remote Pairing Setup Guide
- Factory Dashboard
- osc
- Setup an OBS Development Environment on macOS
- Run OpenQA smoketest locally
- Responsive Guidelines
- Importing database dumps
- Problem Statement & Solution
- Kickoff New Stuff
- New Swagger API doc
- Documentation and Communication
- GitHub Actions
- How to Introduce Software Design Patterns
- Query Objects
- Services
- View Components
- RFC: Core Components
- RFC: Decorator Pattern
- RFC: Backend models