0
0
Expressframework~10 mins

Migrations for schema changes in Express - Interactive Code Practice

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

Complete the code to import the migration tool in an Express project.

Express
const migrate = require('[1]');
Drag options to blanks, or click blank then click option'
Apg
Bexpress
Csequelize-cli
Dmigrate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of the migration tool.
Using 'pg' which is for PostgreSQL client, not migrations.
2fill in blank
medium

Complete the code to define a migration that creates a 'users' table.

Express
exports.up = function(knex) {
  return knex.schema.createTable('[1]', function(table) {
    table.increments('id').primary();
    table.string('name');
  });
};
Drag options to blanks, or click blank then click option'
Ausers
Baccounts
Cprofiles
Dcustomers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong table name like 'accounts' or 'customers'.
3fill in blank
hard

Fix the error in the migration rollback function to drop the 'users' table.

Express
exports.down = function(knex) {
  return knex.schema.[1]('users');
};
Drag options to blanks, or click blank then click option'
AdropTable
BdestroyTable
CdeleteTable
DremoveTable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'removeTable' or 'deleteTable' which do not exist in Knex.
4fill in blank
hard

Fill both blanks to add a new column 'email' of type string to the 'users' table.

Express
exports.up = function(knex) {
  return knex.schema.table('users', function(table) {
    table.[1]('[2]');
  });
};
Drag options to blanks, or click blank then click option'
Astring
Bemail
Cinteger
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'integer' instead of 'string' for the email column.
Using 'name' instead of 'email' as the column name.
5fill in blank
hard

Fill all three blanks to rename the column 'username' to 'user_name' in the 'users' table.

Express
exports.up = function(knex) {
  return knex.schema.table('[1]', function(table) {
    table.renameColumn('[2]', '[3]');
  });
};
Drag options to blanks, or click blank then click option'
Ausers
Busername
Cuser_name
Daccounts
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong table name like 'accounts'.
Swapping old and new column names.