SQL Schema and migrations for ManageIQ.
See the section on plugins in the ManageIQ Developer Setup
For quick local setup run bin/setup, which will clone the core ManageIQ repository under the spec directory and setup necessary config files. If you have already cloned it, you can run bin/update to bring the core ManageIQ code up to date.
This repository contains customizations to the default Rails schema dumper. When adding support for a new Rails version, verify that both versions produce identical schemas — both on the Ruby/Rails side (schema.rb) and at the PostgreSQL level. For each Rails version, two outputs are captured: one from running migrations (migrate) and one from loading the dumped schema into a fresh database (load). Comparing all four outputs confirms the dumper round-trips correctly (schema.rb), and that the actual database structures match at the SQL level (pgAdmin schema diff).
Set these once in your shell before running any commands below.
OLD='80'
NEW='81'The script below drops and recreates the database, runs migrations (saving the resulting schema.rb as .migrate), then loads that schema into a fresh database and redumps it (saving the result as .load). Run it twice: first with VER="${OLD}", then with VER="${NEW}":
rm -f spec/dummy/db/schema.rb
DATABASE_URL=postgres://localhost/dummy_test_${VER}_migrate \
REGION=0 TEST_RAILS_VERSION="${VER:0:1}.${VER:1}" RAILS_ENV=test \
bundle exec rake app:db:drop app:db:create app:db:migrate
cp spec/dummy/db/schema.rb spec/dummy/db/schema.rb.${VER}.migrate
cp spec/dummy/db/schema.rb.${VER}.migrate spec/dummy/db/schema.rb
DATABASE_URL=postgres://localhost/dummy_test_${VER}_load \
REGION=0 TEST_RAILS_VERSION="${VER:0:1}.${VER:1}" RAILS_ENV=test \
bundle exec rake app:db:drop app:db:create app:db:schema:load app:db:schema:dump
cp spec/dummy/db/schema.rb spec/dummy/db/schema.rb.${VER}.loadTEST_RAILS_VERSION switches Rails versions without a bundle update. The rm -f before the migrate run is required — if a schema.rb from a different Rails version is present, the migrate task will fail with an Unknown migration version error.
git diff --no-index spec/dummy/db/schema.rb.${OLD}.migrate spec/dummy/db/schema.rb.${OLD}.load
git diff --no-index spec/dummy/db/schema.rb.${NEW}.migrate spec/dummy/db/schema.rb.${NEW}.load
git diff --no-index spec/dummy/db/schema.rb.${OLD}.migrate spec/dummy/db/schema.rb.${NEW}.migrate
git diff --no-index spec/dummy/db/schema.rb.${OLD}.load spec/dummy/db/schema.rb.${NEW}.loadUse pgAdmin's schema diff tool (Tools → Schema Diff) to compare each pair of databases:
dummy_test_${OLD}_migratevsdummy_test_${OLD}_loaddummy_test_${NEW}_migratevsdummy_test_${NEW}_loaddummy_test_${OLD}_migratevsdummy_test_${NEW}_migratedummy_test_${OLD}_loadvsdummy_test_${NEW}_load
| Comparison | Expected |
|---|---|
${OLD}.migrate vs ${OLD}.load |
Identical |
${NEW}.migrate vs ${NEW}.load |
Identical |
${OLD}.migrate vs ${NEW}.migrate |
Identical (schema version comment may differ) |
${OLD}.load vs ${NEW}.load |
Identical (schema version comment may differ) |
rm spec/dummy/db/schema.rb.${OLD}.migrate spec/dummy/db/schema.rb.${OLD}.load \
spec/dummy/db/schema.rb.${NEW}.migrate spec/dummy/db/schema.rb.${NEW}.loadAfter verifying the schema dumper in this repository, repeat the same process in the application that consumes manageiq-schema (e.g. manageiq). The Rails version there is set by the rails gem pin in the Gemfile. Note that db:setup and db:reset are blocked in manageiq — always use db:drop db:create db:migrate directly.
For each version, set up the appropriate branch and update the rails gem (bundle update rails), then run the script below. Run it twice: first with VER="${OLD}", then with VER="${NEW}":
rm -f db/schema.rb
DATABASE_URL=postgres://localhost/vmdb_test_${VER}_migrate \
REGION=0 RAILS_ENV=test \
bundle exec rake db:drop db:create db:migrate
cp db/schema.rb db/schema.rb.${VER}.migrate
cp db/schema.rb.${VER}.migrate db/schema.rb
DATABASE_URL=postgres://localhost/vmdb_test_${VER}_load \
REGION=0 RAILS_ENV=test \
bundle exec rake db:drop db:create db:schema:load db:schema:dump
cp db/schema.rb db/schema.rb.${VER}.loadgit diff --no-index db/schema.rb.${OLD}.migrate db/schema.rb.${OLD}.load
git diff --no-index db/schema.rb.${NEW}.migrate db/schema.rb.${NEW}.load
git diff --no-index db/schema.rb.${OLD}.migrate db/schema.rb.${NEW}.migrate
git diff --no-index db/schema.rb.${OLD}.load db/schema.rb.${NEW}.loadThen use pgAdmin's schema diff tool (Tools → Schema Diff) to compare the same four pairs of databases (vmdb_test_*). See Expected results above — the same criteria apply.
rm db/schema.rb.${OLD}.migrate db/schema.rb.${OLD}.load \
db/schema.rb.${NEW}.migrate db/schema.rb.${NEW}.loadUnlike other ManageIQ plugins, the schema plugin uses a dummy application in spec/dummy instead of the usual spec/manageiq. This ensures that schema migrations are not dependent on any models or files in ManageIQ core.
To run the tests:
- If necessary, copy
spec/dummy/config/database.tmpl.ymltospec/dummy/config/database.ymland modify it to access your local database - Run:
bin/setup- Copies
spec/dummy/config/database.tmpl.ymltospec/dummy/config/database.ymlif it doesn't exist - Performs
bundle update - Generates random database region number
- Creates/resets
dummy_testdatabase
- Copies
- Run:
rspec spec/migrations/<spec_file>orrake(Run all migration tests)
The gem is available as open source under the terms of the Apache License 2.0.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request