Complete the code to import the migration tool in an Express project.
const migrate = require('[1]');
The migration tool is usually imported with the name 'migrate' or similar. Here, 'migrate' is the correct module to require for schema migrations.
Complete the code to define a migration that creates a 'users' table.
exports.up = function(knex) {
return knex.schema.createTable('[1]', function(table) {
table.increments('id').primary();
table.string('name');
});
};The migration creates a table named 'users'. So the table name must be 'users'.
Fix the error in the migration rollback function to drop the 'users' table.
exports.down = function(knex) {
return knex.schema.[1]('users');
};The correct method to drop a table in Knex migrations is 'dropTable'.
Fill both blanks to add a new column 'email' of type string to the 'users' table.
exports.up = function(knex) {
return knex.schema.table('users', function(table) {
table.[1]('[2]');
});
};To add a string column named 'email', use table.string('email').
Fill all three blanks to rename the column 'username' to 'user_name' in the 'users' table.
exports.up = function(knex) {
return knex.schema.table('[1]', function(table) {
table.renameColumn('[2]', '[3]');
});
};The table is 'users'. The old column is 'username'. The new column is 'user_name'.