Skip to content

Commit

Permalink
add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasvanrijsse committed Jun 23, 2020
1 parent 85f25b1 commit 2ad7597
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Week2/QA-session-content/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ module.exports = {
host : '127.0.0.1',
user : 'root',
password : '',
database : 'epic_todolist'
database : 'db_qa_session'
},
seeds: {
directory: __dirname + '/seeds'
},
migrations: {
directory: __dirname + '/migrations'
}
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

exports.up = async (knex) => {
return knex.schema.createTable('projects', function (table) {
table.increments();
table.string('name').notNullable();
table.date('start_date');
table.date('end_date');
table.string('code').unique();
table.timestamps();
})
};

exports.down = async (knex) => {
return knex.schema.dropTableIfExists('projects')
};
13 changes: 13 additions & 0 deletions Week2/QA-session-content/migrations/20200623130141_create_users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

exports.up = async (knex) => {
return knex.schema.createTable('users', function (table) {
table.increments();
table.string('first_name').notNullable();
table.string('last_name').notNullable();
table.timestamps();
})
};

exports.down = async (knex) => {
return knex.schema.dropTableIfExists('users')
};
20 changes: 20 additions & 0 deletions Week2/QA-session-content/migrations/20200623130146_create_tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

exports.up = async (knex) => {
return knex.schema.createTable('tasks', function (table) {
table.increments();
table.string('name');
table.integer('assigned_to')
.unsigned()
.references('id')
.inTable('users');
table.integer('project_id')
.unsigned()
.references('id')
.inTable('projects');
table.timestamps();
})
};

exports.down = async (knex) => {
return knex.schema.dropTableIfExists('tasks')
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

exports.up = async (knex) => {
return knex.schema.createTable('project_users', function (table) {
table.integer('user_id')
.unsigned()
.references('id')
.inTable('users');
table.integer('project_id')
.unsigned()
.references('id')
.inTable('projects');
})
};

exports.down = async (knex) => {
return knex.schema.dropTableIfExists('project_users')
};
4 changes: 2 additions & 2 deletions Week2/QA-session-content/seeds/2-addUsers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const faker = require('faker');

const createFakeuser = () => ({
firstname: faker.name.firstName(),
lastname: faker.name.lastName()
first_name: faker.name.firstName(),
last_name: faker.name.lastName()
})

exports.seed = async function(knex, Promise) {
Expand Down
2 changes: 1 addition & 1 deletion Week2/QA-session-content/seeds/3-addTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const faker = require('faker');
const createTask = () => ({
name: faker.name.jobDescriptor(),
project_id: Math.ceil(Math.random() * 20),
user_id: Math.ceil(Math.random() * 10),
assigned_to: Math.ceil(Math.random() * 10),
})

exports.seed = async function(knex) {
Expand Down

0 comments on commit 2ad7597

Please sign in to comment.