Migration - PowerPoint PPT Presentation

About This Presentation
Title:

Migration

Description:

You run the rake migrate to migrate database. Ruby code tells what to do ... rake db_schema_dump can to get a Migration file created for your existing schema ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 12
Provided by: venkatsub
Learn more at: https://www2.cs.uh.edu
Category:
Tags: migration | rake

less

Transcript and Presenter's Notes

Title: Migration


1
Migration
2
Whats Migration?
  • Migration
  • Isolates database differences
  • Allows you to write schema updates without
    worries about differences
  • Helps you keep up with changes not only to code,
    but to database schema in an iterative/agile
    development
  • Not only allows you to move forward, but also to
    roll back changes as well

3
How does it work?
  • You run the rake migrate to migrate database
  • Ruby code tells what to do
  • You write a class (or generate and edit it) that
    inherits from ActiveRecordMigration
  • The up method moves it forward
  • The down method moves it backward

4
But, how does it how where to go?
  • Database has a special table with one column and
    one row of the version number
  • Based on the current version, it knows to move
    forward by how many versions, one after another

5
Operations in Migration
  • You can perform any of the following
  • create_table
  • drop_table
  • rename_table
  • add_column
  • rename_column
  • change_column
  • remove_column
  • add_index
  • remove_index

6
Creating a Migration
  • We will play with Migrations for an Alumni
    application
  • Creates a file 001_create_degree.rb

7
Lets take it for a drive
8
Creating Table and Initializing
9
Making a Change
10
Change related
  • For irreversible options (like data deleted in
    move up) you can throw IrreversibleMigration
    exception

11
Some Extras
  • What is you already have a schema that youve
    developed along the way without migration?
  • rake db_schema_dump can to get a Migration file
    created for your existing schema
  • rake db_schema_import can import schema file into
    the current database
Write a Comment
User Comments (0)
About PowerShow.com