Difference between revisions of "Rails:Migrations"

From Klenwell Wiki
Jump to navigation Jump to search
(Official Documentation)
(Schema Migrations)
 
Line 13: Line 13:
 
<pre># rails g migration <name>
 
<pre># rails g migration <name>
 
rails g migration CreateCruds</pre>
 
rails g migration CreateCruds</pre>
 +
 +
=== Run the Migration ===
 +
<pre># Run new migrations
 +
rails db:migrate
 +
 +
# Don't forget to test rollbacks on new migrations
 +
rails db:rollback STEP=1</pre>
  
 
== Data Migrations ==
 
== Data Migrations ==

Latest revision as of 17:29, 27 October 2019

Official Documentation

Database Types

For list of (postgres) column types, see:

Schema Migrations

Generate a Migration

Generic

# rails g migration <name>
rails g migration CreateCruds

Run the Migration

# Run new migrations
rails db:migrate

# Don't forget to test rollbacks on new migrations
rails db:rollback STEP=1

Data Migrations

What if you need to do a data migration or data fix on existing data?