Skip to content

Commit

Permalink
Merge pull request #28 from HackYourFuture-CPH/createSeeds
Browse files Browse the repository at this point in the history
Create seeds
  • Loading branch information
Aaron Moses committed Apr 19, 2024
2 parents 204f628 + 4bddea9 commit dfca56d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/server/migrations/20240416153144_drop_retro_id_column.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async (knex) => {
await knex.raw(
'ALTER TABLE `Questions` DROP CONSTRAINT questions_retro_id_foreign',
);
await knex.schema.alterTable('Questions', (table) => {
table.dropColumn('retro_id');
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async (knex) => {
await knex.schema.alterTable('Answers', (table) => {
table
.integer('retro_id')
.unsigned()
.notNullable()
.references('id')
.inTable('Retro');
});
};
14 changes: 14 additions & 0 deletions packages/server/seeds/development/questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.seed = function (knex) {
// Deletes all existing entries
return knex('Questions')
.del()
.then(() => {
// Inserts seed entries
return knex('Questions').insert([
{ id: 1, title: 'What went well?', color: 'green' },
{ id: 2, title: "What didn't go well?", color: 'red' },
{ id: 3, title: 'What can be improved?', color: 'yellow' },
{ id: 4, title: 'Any other comments?', color: 'blue' },
]);
});
};
14 changes: 14 additions & 0 deletions packages/server/seeds/development/teams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.seed = async function (knex) {
// Deletes ALL existing entries
await knex('Teams').insert([
{ team_name: 'Team A', team_code: 'A001' },
{ team_name: 'Team B', team_code: 'B002' },
{ team_name: 'Team C', team_code: 'C003' },
{ team_name: 'Team D', team_code: 'D004' },
{ team_name: 'Team E', team_code: 'E005' },
]);
};

0 comments on commit dfca56d

Please sign in to comment.