Skip to content

Commit 67e889b

Browse files
committed
Working with migrations and VERSIONs
1 parent 081676a commit 67e889b

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

README.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ rails server
7373
```
7474
Or in cloud9
7575
```
76-
rails s -b $IP -p $PORT -e c9development
76+
rails s -b $IP -p $PORT -e c9
7777
```
7878

7979
## Navigating this tutorial
@@ -150,7 +150,7 @@ rake db:schema:dump RAILS_ENV=production'
150150
```
151151
or for cloud9,
152152
```
153-
rake db:schema:dump RAILS_ENV=c9development'
153+
rake db:schema:dump RAILS_ENV=c9'
154154
```
155155

156156
## Migrations
@@ -167,7 +167,31 @@ rails generate model ModelName
167167
```
168168

169169
#### Running our migrations
170+
*For any of the `rake` commands in cloud9, append `RAILS_ENV=c9`.*
171+
Rake will create the tables we have specified in our migration files, and add entries for each of the migrations keyed by their timestamp.
170172
```
171-
rake db:migrate RAILS_ENV=c9development
173+
rake db:migrate
172174
```
173175

176+
View the migrations in the database under the schema_migrations table.
177+
``` sql
178+
SELECT * FROM schema_migrations;
179+
```
180+
181+
#### Taking down migrations
182+
This will take down all of your migrations.
183+
```
184+
rake db:migrate VERSION=0
185+
```
186+
#### Get the status of the migrations
187+
To see if migrations are up or down
188+
```
189+
rake db:migrate:status
190+
```
191+
192+
#### VERSIONs
193+
You can go through the migrations sequentially by using VERSION=<timestamp> of whatever version.
194+
So if you only wanted to run the Create users migration, you'd enter
195+
```
196+
rake db:migrate VERSION=20160917170621
197+
```

config/database.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ development:
2121
<<: *default
2222
database: simple_cms_development
2323

24-
c9development:
24+
c9:
2525
<<: *default
2626
adapter: mysql2
2727
encoding: utf8

config/secrets.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
development:
1414
secret_key_base: 418f74ba6ff80231c456be58a0b9174ce2c732466ec4bc9cd29d70f7f170114067f909c3d18aef1890ce720c7d29e5dc40c1cb58d946156e5aef083be7aade5c
1515

16-
c9development:
16+
c9:
1717
secret_key_base: 418f74ba6ff80231c456be58a0b9174ce2c732466ec4bc9cd29d70f7f170114067f909c3d18aef1890ce720c7d29e5dc40c1cb58d946156e5aef083be7aade5c
1818

1919

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class SecondMigration < ActiveRecord::Migration[5.0]
2+
def change
3+
end
4+
end

db/schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20160917170621) do
13+
ActiveRecord::Schema.define(version: 20160917190210) do
1414

1515
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t|
1616
t.string "first_name", limit: 25

0 commit comments

Comments
 (0)