Skip to content
Snippets Groups Projects
Commit 87053ac6 authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Added a initial database model

parent 05bc7477
No related branches found
No related tags found
1 merge request!2WIP: Using react
......@@ -10,3 +10,7 @@
# production
/build
# database
*.db
*.sqlite3
module.exports = {
development: {
client: "sqlite3",
connection: {
filename: "./dev.sqlite3"
}
},
staging: {
client: "postgresql",
connection: {
database: "my_db",
user: "username",
password: "password"
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
},
production: {
client: "postgresql",
connection: {
database: "my_db",
user: "username",
password: "password"
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
}
};
import { Knex } from "knex";
export async function up(database: Knex): Promise<void> {
return database.schema
.createTable('users', table => {
table.uuid('id').notNullable().primary();
table.string('user_name').unique().notNullable();
table.string('passwd_hash', 60).notNullable();
table.text('email');
table.text('real_name');
})
.createTable('teams', table => {
table.uuid('id').notNullable().primary();
table.text('name').notNullable();
})
.createTable('team_members', table => {
table.uuid('user_id').notNullable().references('users.id');
table.uuid('team_id').notNullable().references('teams.id');
table.primary(['user_id', 'team_id']);
table.uuid('role_id').notNullable().references('roles.id');
})
.createTable('roles', table => {
table.uuid('id').notNullable().primary();
table.uuid('team_id').notNullable().references('teams.id');
table.text('name').notNullable();
})
.createTable('projects', table => {
table.uuid('id').notNullable().primary();
table.text('name').notNullable();
})
.createTable('team_projects', table => {
table.uuid('project_id').notNullable().references('projects.id');
table.uuid('team_id').notNullable().references('teams.id');
table.primary(['project_id', 'team_id']);
})
.createTable('tasks', table => {
table.uuid('id').notNullable().primary();
table.uuid('project_id').notNullable().references('projects.id');
table.text('name').notNullable();
table.text('text').notNullable();
table.enum('status', [ 'open', 'closed', 'suspended' ]).notNullable();
})
.createTable('task_requirements', table => {
table.uuid('task_id').notNullable().references('tasks.id');
table.uuid('role_id').notNullable().references('users.id');
table.primary(['task_id', 'role_id']);
table.integer('time').notNullable();
})
.createTable('task_assignees', table => {
table.uuid('user_id').notNullable().references('users.id');
table.uuid('task_id').notNullable().references('tasks.id');
table.primary(['user_id', 'task_id']);
table.integer('time').notNullable();
table.boolean('assigned').notNullable();
table.boolean('working').notNullable();
})
.createTable('comments', table => {
table.uuid('id').notNullable().primary();
table.uuid('task_id').notNullable().references('tasks.id');
table.uuid('user_id').notNullable().references('users.id');
table.text('text').notNullable();
});
}
export async function down(database: Knex): Promise<void> {
return database.schema
.dropTable('comments')
.dropTable('task_assignees')
.dropTable('task_requirements')
.dropTable('tasks')
.dropTable('team_projects')
.dropTable('projects')
.dropTable('roles')
.dropTable('team_members')
.dropTable('teams')
.dropTable('users');
}
......@@ -8,7 +8,10 @@
"private": true,
"main": "src/index.ts",
"dependencies": {
"express": "^4.17.1"
"express": "^4.17.1",
"knex": "^0.95.4",
"sqlite3": "^5.0.2",
"uuid": "^8.3.2"
},
"scripts": {
"start": "nodemon src/index.ts",
......
import knex from 'knex';
const database = knex({
client: 'sqlite3',
connection: {
filename: './database.db'
}
});
database.migrate.latest();
export default function getDatabase() {
return database;
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment