class DontUseConstraintForZipcodeValidationMigration < ActiveRecord::Migrationdef changerevert do# copy-pasted code from CreateBlockreversible do |dir|dir.up do# add a CHECK constraintexecute <<-SQLALTER TABLE distributorsADD CONSTRAINT zipchkCHECK (char_length(zipcode) = 5);SQLenddir.down doexecute <<-SQLALTER TABLE distributorsDROP CONSTRAINT zipchkSQLendend
# The rest of the migration was okendendend
(... some older migrations ...)up 20181001002039 Some migration descriptionup 20181002222222 Some migration descriptionup 20181003171932 Some migration descriptionup 20181004211151 Some migration descriptionup 20181005151403 Some migration description
运行:
rake db:migrate VERSION=20181002222222
将导致:
(... some older migrations ...)up 20181001002039 Some migration descriptionup 20181002222222 Some migration descriptiondown 20181003171932 Some migration descriptiondown 20181004211151 Some migration descriptiondown 20181005151403 Some migration description