0
0
Ruby on Railsframework~10 mins

Why migrations version the database in Ruby on Rails - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a migration that adds a new column.

Ruby on Rails
class AddAgeToUsers < ActiveRecord::Migration[6.0]
  def change
    add_column :users, :age, :[1]
  end
end
Drag options to blanks, or click blank then click option'
Ainteger
Bstring
Cboolean
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string type for age
Forgetting to specify the data type
2fill in blank
medium

Complete the code to run all pending migrations.

Ruby on Rails
rails [1]
Drag options to blanks, or click blank then click option'
Adb:create
Bdb:rollback
Cdb:migrate
Ddb:seed
Attempts:
3 left
💡 Hint
Common Mistakes
Using db:create which only creates the database
Using db:seed which loads data
3fill in blank
hard

Fix the error in the migration version declaration.

Ruby on Rails
class CreateProducts < ActiveRecord::Migration[1]
  def change
    create_table :products do |t|
      t.string :name
    end
  end
end
Drag options to blanks, or click blank then click option'
A6.0
B[5.2]
C(6.0)
D[6.0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of brackets
Omitting brackets entirely
4fill in blank
hard

Fill both blanks to define a migration that removes a column.

Ruby on Rails
class RemoveEmailFromUsers < ActiveRecord::Migration[1]
  def change
    remove_column :users, :email, :[2]
  end
end
Drag options to blanks, or click blank then click option'
A[6.1]
Bstring
Cinteger
D[5.0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong migration version
Wrong data type for email column
5fill in blank
hard

Fill all three blanks to create a migration that renames a column.

Ruby on Rails
class RenameUsernameToLogin < ActiveRecord::Migration[1]
  def change
    rename_column :users, :[2], :[3]
  end
end
Drag options to blanks, or click blank then click option'
A[7.0]
Busername
Clogin
D[6.0]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping old and new column names
Using wrong migration version