Skip to content

Commit

Permalink
Updated migrations and added seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Claro614 committed Oct 27, 2019
1 parent e5e7621 commit 02fa839
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 6 deletions.
4 changes: 2 additions & 2 deletions migrations/02-Question.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ exports.up = function(knex, Promise) {
return knex.schema.createTable('Question', (table) => {
table.increments('id');
table.integer('user_id');
table.foreign('user_id').references('_User.id');
table.foreign('user_id').references('_User.id').onDelete('CASCADE');
table.integer('view_count').defaultTo(0);
table.string('title', 50).notNullable();
table.string('title', 70).notNullable();
table.text('body').notNullable();
});
};
Expand Down
4 changes: 2 additions & 2 deletions migrations/03-Answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ exports.up = function(knex, Promise) {
table.float('rating');
table.integer('user_id');
table.integer('question_id');
table.foreign('user_id').references('_User.id');
table.foreign('question_id').references('Question.id');
table.foreign('user_id').references('_User.id').onDelete('CASCADE');
table.foreign('question_id').references('Question.id').onDelete('CASCADE');
table.boolean('isBest').defaultTo(false);
});
};
Expand Down
4 changes: 2 additions & 2 deletions migrations/05-QuestionTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ exports.up = function(knex, Promise) {
return knex.schema.createTable('Question_Tags', (table) => {
table.string('tag_name', 100).notNullable();
table.integer('question_id').notNullable();
table.foreign('tag_name').references('Tag.name');
table.foreign('question_id').references('Question.id');
table.foreign('tag_name').references('Tag.name').onDelete('CASCADE');
table.foreign('question_id').references('Question.id').onDelete('CASCADE');
});
};

Expand Down
8 changes: 8 additions & 0 deletions seeds/01_Users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const users = require('../data/users.json');

exports.seed = function(knex) {
return knex('_User').del()
.then(function() {
return knex('_User').insert(users);
});
}
8 changes: 8 additions & 0 deletions seeds/02_Question.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const questions = require('../data/questions.json');

exports.seed = function(knex) {
return knex('Question').del()
.then(function() {
return knex('Question').insert(questions);
});
}
8 changes: 8 additions & 0 deletions seeds/03_Answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const answers = require('../data/answers.json');

exports.seed = function(knex) {
return knex('Answer').del()
.then(function() {
return knex('Answer').insert(answers);
});
}
8 changes: 8 additions & 0 deletions seeds/04_Tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const tag = require('../data/tag.json');

exports.seed = function(knex) {
return knex('Tag').del()
.then(function() {
return knex('Tag').insert(tag);
});
}
8 changes: 8 additions & 0 deletions seeds/05_QuestionTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const question_tags = require('../data/question_tags.json');

exports.seed = function(knex) {
return knex('Question_Tags').del()
.then(function() {
return knex('Question_Tags').insert(question_tags);
});
}
8 changes: 8 additions & 0 deletions seeds/06_Comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const comments = require('../data/comments.json');

exports.seed = function(knex) {
return knex('_Comment').del()
.then(function() {
return knex('_Comment').insert(comments);
});
}

0 comments on commit 02fa839

Please sign in to comment.