08
- 8.2 Script the upgrade and downgrade of a database
- Learning Objectives
- Apply database changes
8.2 Script the upgrade and downgrade of a database
Learning Objectives
By the end of this lesson you will be able to:
- Upgrade and downgrade the database through a script.
Apply database changes
Rollback changes that were previously applied to a database.
cd /var/www/rails
sudo rake db:rollback
The example below is part of the sample application for Ruby on Rails Tutorial: Learn Rails by Example by Michael Hartl. You can also define the database schema in a script.
“`
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :name t.string :email
t.timestamps
end end
def self.down drop_table :users end end
“`
The example below is using a tool called Liquibase for database change management.
“`
“`