Skip to content

Commit bf70aa1

Browse files
AllesandriaAllesandria
authored andcommitted
All 4 tables built
1 parent bafb7c2 commit bf70aa1

File tree

5 files changed

+58
-32
lines changed

5 files changed

+58
-32
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ Add `"start"`. `"server"`, `"migrate"` and `"rollback"` scripts to the `package.
4141

4242
Build the migration(s) in Knex inside the `data/migrations` folder using appropriate data types and constraints. **You must use the table names and the column names described below.** To give a primary key a name different than `id`, do `table.increments("project_id")` instead of `table.increments()`.
4343

44-
- [ ] A **project** is what needs to be done and is stored in a `projects` table with the following columns:
44+
- [X ] A **project** is what needs to be done and is stored in a `projects` table with the following columns:
4545

46-
- [ ] `project_id` - primary key - table.increments("project_id")
47-
- [ ] `project_name` - required - varchar -notNullable()
48-
- [ ] `project_description` - optional - varchar
49-
- [ ] `project_completed` - the database defaults it to `false` (integer 0) if not provided - boolean - false(0)
46+
- [X ] `project_id` - primary key - table.increments("project_id")
47+
- [ X] `project_name` - required - varchar -notNullable()
48+
- [X ] `project_description` - optional - varchar
49+
- [ X] `project_completed` - the database defaults it to `false` (integer 0) if not provided - boolean - false(0)
5050

51-
- [ ] A **resource** is anything needed to complete a project and is stored in a `resources` table with the following columns:
51+
- [ X] A **resource** is anything needed to complete a project and is stored in a `resources` table with the following columns:
5252

53-
- [ ] `resource_id` - primary key - table.increments("resource_id")
54-
- [ ] `resource_name` - required and unique - notNullable - varchar
53+
- [ X] `resource_id` - primary key - table.increments("resource_id")
54+
- [ X] `resource_name` - required and unique - notNullable - varchar
5555
- [ ] `resource_description` - optional - varchar
5656

5757
- [ ] A **task** is one of the steps needed to complete a project and is stored in a `tasks` table with the following columns:

data/migrations/20220819053947_projects_table.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
exports.up = function(knex) {
2+
exports.up = function (knex) {
33
return knex.schema.createTable('projects', tbl => {
4-
tbl.increments('project_id');
5-
tbl.varchar('project_name').notNullable();
6-
tbl.varchar('project_description');
7-
tbl.boolean('project_completed');
4+
tbl.increments('project_id');
5+
tbl.varchar('project_name').notNullable();
6+
tbl.varchar('project_description');
7+
tbl.boolean('project_completed');
88
});
99

1010
};
1111

1212

13-
exports.down = function(knex) {
13+
exports.down = function (knex) {
1414
return knex.schema.dropTableIfExists('projects')
1515

1616

data/migrations/20220820052811_resources_table.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

2-
exports.up = function(knex) {
2+
exports.up = function (knex) {
33
return knex.schema.createTable('resources', tbl => {
44
tbl.increments('resource_id');
55
tbl.varchar('resource_name').notNullable().unique();
66
tbl.varchar('resource_description');
77
})
8-
8+
99

1010

1111
};
1212

1313

14-
exports.down = function(knex) {
14+
exports.down = function (knex) {
1515
return knex.schema.dropTableIfExists('resources')
1616

1717

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11

2-
exports.up = function(knex) {
3-
return knex.schema.createTable('tasks', tbl => {
4-
tbl.increments('task_id');
5-
tbl.varchar('task_description').notNullable();
6-
tbl.varchar('task_notes');
7-
tbl.boolean('task_completed');
8-
tbl.integer('project_id')
9-
.notNullable()
10-
.references('project_id')
11-
.inTable('projects')
12-
13-
14-
})
2+
exports.up = function (knex) {
3+
return knex.schema.createTable('tasks', tbl => {
4+
tbl.increments('task_id');
5+
tbl.varchar('task_description').notNullable();
6+
tbl.varchar('task_notes');
7+
tbl.boolean('task_completed');
8+
tbl.integer('project_id')
9+
.notNullable()
10+
.references('project_id')
11+
.inTable('projects')
12+
13+
14+
})
1515

1616

1717
};
1818

1919

20-
exports.down = function(knex) {
21-
return knex.schema.dropTableIfExists('tasks')
20+
exports.down = function (knex) {
21+
return knex.schema.dropTableIfExists('tasks')
2222

2323

2424
};
25+
26+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
exports.up = function (knex) {
3+
return knex.schema.createTable('project_resources', tbl => {
4+
tbl.integer('project_id')
5+
.references('project_id')
6+
.inTable('projects')
7+
.notNullable();
8+
tbl.varchar('project_name')
9+
.references('project_name')
10+
.inTable('projects')
11+
12+
tbl.integer('resource_id')
13+
.references('resource_id')
14+
.inTable('resources')
15+
.notNullable();
16+
})
17+
18+
19+
};
20+
21+
22+
exports.down = function (knex) {
23+
return knex.schema.dropTableIfExists('project_resources')
24+
};

0 commit comments

Comments
 (0)