Difference between revisions of "Rails:Migrations"
Jump to navigation
Jump to search
(Created page with "== Official Documentation == * https://guides.rubyonrails.org/active_record_migrations.html == Schema Migrations == === Generate a Migration === ==== Add a Column ==== == Da...") |
(→Schema Migrations) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Official Documentation == | == Official Documentation == | ||
* https://guides.rubyonrails.org/active_record_migrations.html | * https://guides.rubyonrails.org/active_record_migrations.html | ||
+ | |||
+ | == Database Types == | ||
+ | For list of (postgres) column types, see: | ||
+ | |||
+ | * https://stackoverflow.com/q/17918117/1093087 | ||
+ | * https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb (See <tt>NATIVE_DATABASE_TYPES</tt>) | ||
== Schema Migrations == | == Schema Migrations == | ||
=== Generate a Migration === | === Generate a Migration === | ||
− | ==== | + | ==== Generic ==== |
+ | <pre># rails g migration <name> | ||
+ | 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
Contents
Official Documentation
Database Types
For list of (postgres) column types, see:
- https://stackoverflow.com/q/17918117/1093087
- https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb (See NATIVE_DATABASE_TYPES)
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?