Balaji Vajjala's Blog

A DevOps Blog from Trenches

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

  1. Rollback changes that were previously applied to a database.

    cd /var/www/rails

    sudo rake db:rollback

  2. 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

    “`

  3. The example below is using a tool called Liquibase for database change management.

    “`

    “`