From 8da17b1d11fea371585844250fb935c9a93d9da0 Mon Sep 17 00:00:00 2001 From: Shifnasiddik Date: Wed, 10 Jun 2026 15:56:38 +0530 Subject: [PATCH 1/2] Task 4 --- task4db/ER_DIAGRAM.md | 25 ++++++++++++++++ task4db/README.md | 27 ++++++++++++++++++ task4db/database.sqlite | Bin 0 -> 32768 bytes task4db/knexfile.js | 15 ++++++++++ task4db/package.json | 18 ++++++++++++ task4db/src/config/db.js | 11 +++++++ .../migrations/20260610095832_create_users.js | 20 +++++++++++++ .../20260610095848_create_projects.js | 25 ++++++++++++++++ .../20260610095858_create_project_events.js | 25 ++++++++++++++++ task4db/src/seeds/sample_data.js | 22 ++++++++++++++ 10 files changed, 188 insertions(+) create mode 100644 task4db/ER_DIAGRAM.md create mode 100644 task4db/README.md create mode 100644 task4db/database.sqlite create mode 100644 task4db/knexfile.js create mode 100644 task4db/package.json create mode 100644 task4db/src/config/db.js create mode 100644 task4db/src/migrations/20260610095832_create_users.js create mode 100644 task4db/src/migrations/20260610095848_create_projects.js create mode 100644 task4db/src/migrations/20260610095858_create_project_events.js create mode 100644 task4db/src/seeds/sample_data.js diff --git a/task4db/ER_DIAGRAM.md b/task4db/ER_DIAGRAM.md new file mode 100644 index 0000000..3e0ea90 --- /dev/null +++ b/task4db/ER_DIAGRAM.md @@ -0,0 +1,25 @@ +# ER Diagram - Shipyard Task 4 + +## Users +- id (PK) +- name +- email +- role + +## Projects +- id (PK) +- name +- description +- status +- owner_id (FK -> Users.id) + +## Project_Events +- id (PK) +- project_id (FK -> Projects.id) +- event_type +- description +- created_at + +### Relationships +- Users (1) ----< Projects +- Projects (1) ----< Project_Events diff --git a/task4db/README.md b/task4db/README.md new file mode 100644 index 0000000..3f32d7f --- /dev/null +++ b/task4db/README.md @@ -0,0 +1,27 @@ +# Shipyard Technical Evaluation - Task 4 + +## Tech Stack +- Express.js +- SQLite +- Knex + +## Installation + +```bash +npm install + +## Run Migrations + +```bash +npx knex migrate:latest + +## Run Seeds + +```bash +npx knex seed:run + +## Schema + +Users -> Projects -> Project Events +See ER_DIAGRAM.md for details + diff --git a/task4db/database.sqlite b/task4db/database.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..eb9a493db78e1abfb21fd83b76510be4d5ab1120 GIT binary patch literal 32768 zcmeI*-*4MQ00;1M+{DdBXV5fR6Dph#NHuBNG$mCx@vzcGsMA)uCY6TvVBeB!D+l>Gw}Jo7q~RtrJnxMcB>n&-;OzWp?G*`7rLE|DiXHpze7^hG_i!gC zZrr`?2u`-C*#5iC3uNx`%PEw)bR!1;UV<{LH(ZV(r)N@EIg!p{E)Jq2pqo^ za!-~%dtAhc17&P-Zc7|?xlQ+3*y^xwrdq3+GO5j@R_Jtv6Zke2{2(qw7RLl{TTIxr zEw_Z@aoXnFtmg{4y0y7kUvFB?wLA4jbLGy)Y&ps9dTV{{?pB?yt>3KQqxP$rZ5sH) z_!uN9$2R-Z6PjTd%F)$CG&w9;<uR|drUOSO-vET-oME>5V^qo}B; zs)mw`>~oiMYDvjFSs)YDS}_xuJdzQQ{}ugrB0mTafB*y_009U<00Izz00bZa0SNs6 z1XM*OlkxaJr#~h7OSwXT00bZa0SG_<0uX=z1Rwwb2teQs6Zla6B*2(|zrjM*iQ?4_ ze!#r0%ja5w*Oq?@;s#wFz9)YQaHVYA3OfF-Tu$a;ZO`%JKl#h)KNI~|xk7*d1Rwwb z2tWV=5P$##AOHafK;Rq+Tv6whSLOtAm(_AHI|(p&{{IEhU!0@np{fvo00bZa0SG_< z0uX=z1Rwwb2#}AJ0x6qUi;a%cJ!D~ } + */ +exports.up = function(knex) { + return knex.schema.createTable("users", (table) => { + table.increments("id").primary(); + table.string("name"); + table.string("email").unique(); + table.string("role"); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function(knex) { + return knex.schema.dropTable("users"); +}; diff --git a/task4db/src/migrations/20260610095848_create_projects.js b/task4db/src/migrations/20260610095848_create_projects.js new file mode 100644 index 0000000..89c3f89 --- /dev/null +++ b/task4db/src/migrations/20260610095848_create_projects.js @@ -0,0 +1,25 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function(knex) { + return knex.schema.createTable("projects", (table) => { + table.increments("id").primary(); + table.string("name"); + table.text("description"); + table.string("status"); + table + .integer("owner_id") + .unsigned() + .references("id") + .inTable("users"); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function(knex) { + return knex.schema.dropTable("projects"); +}; diff --git a/task4db/src/migrations/20260610095858_create_project_events.js b/task4db/src/migrations/20260610095858_create_project_events.js new file mode 100644 index 0000000..e5c4e79 --- /dev/null +++ b/task4db/src/migrations/20260610095858_create_project_events.js @@ -0,0 +1,25 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function(knex) { + return knex.schema.createTable("project_events", (table) => { + table.increments("id").primary(); + table + .integer("project_id") + .unsigned() + .references("id") + .inTable("projects"); + table.string("event_type"); + table.text("description"); + table.timestamp("created_at").defaultTo(knex.fn.now()); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function(knex) { + return knex.schema.dropTable("project_events"); +}; diff --git a/task4db/src/seeds/sample_data.js b/task4db/src/seeds/sample_data.js new file mode 100644 index 0000000..54cc21c --- /dev/null +++ b/task4db/src/seeds/sample_data.js @@ -0,0 +1,22 @@ +exports.seed = async function (knex) { + // Deletes ALL existing entries + await knex("project_events").del(); + await knex("projects").del(); + await knex("users").del(); + + // Insert sample users + await knex("users").insert([ + { id: 1, name: "John", email: "john@example.com", role: "admin" }, + { id: 2, name: "Sarah", email: "sarah@example.com", role: "developer" } + ]); + + // Insert sample projects + await knex("projects").insert([ + { id: 1, name: "Shipyard Project", description: "Sample Project", status: "active", owner_id: 1 } + ]); + + // Insert sample project events + await knex("project_events").insert([ + { id: 1, project_id: 1, event_type: "Created", description: "Project created" } + ]); +}; From 0c578afed37bb4ac809f4644e2de5a5709598518 Mon Sep 17 00:00:00 2001 From: Shifnasiddik Date: Wed, 10 Jun 2026 17:59:36 +0530 Subject: [PATCH 2/2] add documentation --- documentation.md | 86 +++++++++++++++++- .../ER_DIAGRAM.md | 0 {task4db => task-4-database-schema}/README.md | 0 .../database.sqlite | Bin task-4-database-schema/documentation.md | 0 .../knexfile.js | 0 .../package.json | 0 .../src/config/db.js | 0 .../migrations/20260610095832_create_users.js | 0 .../20260610095848_create_projects.js | 0 .../20260610095858_create_project_events.js | 0 .../src/seeds/seed_initial_data.js | 0 12 files changed, 85 insertions(+), 1 deletion(-) rename {task4db => task-4-database-schema}/ER_DIAGRAM.md (100%) rename {task4db => task-4-database-schema}/README.md (100%) rename {task4db => task-4-database-schema}/database.sqlite (100%) create mode 100644 task-4-database-schema/documentation.md rename {task4db => task-4-database-schema}/knexfile.js (100%) rename {task4db => task-4-database-schema}/package.json (100%) rename {task4db => task-4-database-schema}/src/config/db.js (100%) rename {task4db => task-4-database-schema}/src/migrations/20260610095832_create_users.js (100%) rename {task4db => task-4-database-schema}/src/migrations/20260610095848_create_projects.js (100%) rename {task4db => task-4-database-schema}/src/migrations/20260610095858_create_project_events.js (100%) rename task4db/src/seeds/sample_data.js => task-4-database-schema/src/seeds/seed_initial_data.js (100%) diff --git a/documentation.md b/documentation.md index d1e8d04..d0a477b 100644 --- a/documentation.md +++ b/documentation.md @@ -1 +1,85 @@ -# documentation file +# Database Schema & Migration Module + +## Overview + +This module implements the database layer for a project management system using SQLite and Knex.js. + +Includes: +- Database configuration +- migrations +- Seed data +- ER diagram + +### Backend + +- Node.js +- Knex.js + +### Database + +- SQLite + +## Project Structure +text +task-4-database-schema/ +├── src/ +│ ├── config/ +│ │ └── db.js +│ ├── migrations/ +│ │ ├── create_users.js +│ │ ├── create_projects.js +│ │ └── create_project_events.js +│ └── seeds/ +│ └── seed_initial_data.js +├── database.sqlite +├── knexfile.js +├── README.md +├── ER_DIAGRAM.md +└── documentation.md + +## Database Schema + +### Users +- id (Primary Key) +- name +- email (Unique) +- role + +### Projects +- id (Primary Key) +- name +- description +- status +- owner_id (Foreign Key → Users.id) + +### Project Events +- id (Primary Key) +- project_id (Foreign Key → Projects.id) +- event_type +- description +- created_at + +## Relationships +- One User can own multiple Projects. +- One Project can contain multiple Project Events. + +### Install + +```bash +npm install + +### Run Migrations + +```bash +npx knex migrate:latest + +### Run Seed Data + +```bash +npx knex seed:run + +## Features +- Normalized database schema +- Foreign key relationships +- Migration-based schema management +- Seed data for testing diff --git a/task4db/ER_DIAGRAM.md b/task-4-database-schema/ER_DIAGRAM.md similarity index 100% rename from task4db/ER_DIAGRAM.md rename to task-4-database-schema/ER_DIAGRAM.md diff --git a/task4db/README.md b/task-4-database-schema/README.md similarity index 100% rename from task4db/README.md rename to task-4-database-schema/README.md diff --git a/task4db/database.sqlite b/task-4-database-schema/database.sqlite similarity index 100% rename from task4db/database.sqlite rename to task-4-database-schema/database.sqlite diff --git a/task-4-database-schema/documentation.md b/task-4-database-schema/documentation.md new file mode 100644 index 0000000..e69de29 diff --git a/task4db/knexfile.js b/task-4-database-schema/knexfile.js similarity index 100% rename from task4db/knexfile.js rename to task-4-database-schema/knexfile.js diff --git a/task4db/package.json b/task-4-database-schema/package.json similarity index 100% rename from task4db/package.json rename to task-4-database-schema/package.json diff --git a/task4db/src/config/db.js b/task-4-database-schema/src/config/db.js similarity index 100% rename from task4db/src/config/db.js rename to task-4-database-schema/src/config/db.js diff --git a/task4db/src/migrations/20260610095832_create_users.js b/task-4-database-schema/src/migrations/20260610095832_create_users.js similarity index 100% rename from task4db/src/migrations/20260610095832_create_users.js rename to task-4-database-schema/src/migrations/20260610095832_create_users.js diff --git a/task4db/src/migrations/20260610095848_create_projects.js b/task-4-database-schema/src/migrations/20260610095848_create_projects.js similarity index 100% rename from task4db/src/migrations/20260610095848_create_projects.js rename to task-4-database-schema/src/migrations/20260610095848_create_projects.js diff --git a/task4db/src/migrations/20260610095858_create_project_events.js b/task-4-database-schema/src/migrations/20260610095858_create_project_events.js similarity index 100% rename from task4db/src/migrations/20260610095858_create_project_events.js rename to task-4-database-schema/src/migrations/20260610095858_create_project_events.js diff --git a/task4db/src/seeds/sample_data.js b/task-4-database-schema/src/seeds/seed_initial_data.js similarity index 100% rename from task4db/src/seeds/sample_data.js rename to task-4-database-schema/src/seeds/seed_initial_data.js