Download presentation
Presentation is loading. Please wait.
Published byBethanie Young Modified over 9 years ago
1
1 Migration
2
2 What’s 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
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 ActiveRecord::Migration The up method moves it forward The down method moves it backward
4
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
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
6 Creating a Migration We will play with Migrations for an Alumni application Creates a file 001_create_degree.rb
7
7 Let’s take it for a drive
8
8 Creating Table and Initializing
9
9 Making a Change
10
10 Change related… For irreversible options (like data deleted in move up) you can throw IrreversibleMigration exception
11
11 Some Extras What is you already have a schema that you’ve 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.