* Add next suggestions and remove console logs * Add pomodoro timer * Add pomodoro switch in settings * Fix pomodoro setting * Add timezones to settings * Fix an issue with password reset * Cleanup * Sort tags alphabetically * Clean up today's view * Add an indicator for repeatedly added to today * Refactor tags * Add due date today item * Move recurrence to the subtitle area * Fix today layout * Add a badge to Inbox items * Move inbox badge to sidebar * Add quotes and progress bar * Add translations for quotes * Fix test issues * Add helper script for docker local * Set up overdue tasks * Add linux/arm/v7 build to deploy script * Add linux/arm/v7 build to deploy script pt2 * Fix an issue with helmet and SSL * Add volume db persistence * Fix cog icon issues
102 lines
No EOL
3.4 KiB
JavaScript
102 lines
No EOL
3.4 KiB
JavaScript
const { Sequelize } = require('sequelize');
|
|
const path = require('path');
|
|
|
|
// Database configuration
|
|
let dbConfig;
|
|
|
|
if (process.env.NODE_ENV === 'test') {
|
|
// Use temporary file database for tests to allow external script access
|
|
const testDbPath = path.join(__dirname, '../db', 'test.sqlite3');
|
|
dbConfig = {
|
|
dialect: 'sqlite',
|
|
storage: testDbPath,
|
|
logging: false,
|
|
define: {
|
|
timestamps: true,
|
|
underscored: true,
|
|
createdAt: 'created_at',
|
|
updatedAt: 'updated_at'
|
|
}
|
|
};
|
|
} else {
|
|
const dbPath = process.env.DATABASE_URL
|
|
? process.env.DATABASE_URL.replace('sqlite:///', '')
|
|
: path.join(__dirname, '../db', process.env.NODE_ENV === 'production' ? 'production.sqlite3' : 'development.sqlite3');
|
|
|
|
dbConfig = {
|
|
dialect: 'sqlite',
|
|
storage: dbPath,
|
|
logging: process.env.NODE_ENV === 'development' ? console.log : false,
|
|
define: {
|
|
timestamps: true,
|
|
underscored: true,
|
|
createdAt: 'created_at',
|
|
updatedAt: 'updated_at'
|
|
}
|
|
};
|
|
}
|
|
|
|
const sequelize = new Sequelize(dbConfig);
|
|
|
|
// Import models
|
|
const User = require('./user')(sequelize);
|
|
const Area = require('./area')(sequelize);
|
|
const Project = require('./project')(sequelize);
|
|
const Task = require('./task')(sequelize);
|
|
const Tag = require('./tag')(sequelize);
|
|
const Note = require('./note')(sequelize);
|
|
const InboxItem = require('./inbox_item')(sequelize);
|
|
const TaskEvent = require('./task_event')(sequelize);
|
|
|
|
// Define associations
|
|
User.hasMany(Area, { foreignKey: 'user_id' });
|
|
Area.belongsTo(User, { foreignKey: 'user_id' });
|
|
|
|
User.hasMany(Project, { foreignKey: 'user_id' });
|
|
Project.belongsTo(User, { foreignKey: 'user_id' });
|
|
Project.belongsTo(Area, { foreignKey: 'area_id', allowNull: true });
|
|
Area.hasMany(Project, { foreignKey: 'area_id' });
|
|
|
|
User.hasMany(Task, { foreignKey: 'user_id' });
|
|
Task.belongsTo(User, { foreignKey: 'user_id' });
|
|
Task.belongsTo(Project, { foreignKey: 'project_id', allowNull: true });
|
|
Project.hasMany(Task, { foreignKey: 'project_id' });
|
|
|
|
User.hasMany(Tag, { foreignKey: 'user_id' });
|
|
Tag.belongsTo(User, { foreignKey: 'user_id' });
|
|
|
|
User.hasMany(Note, { foreignKey: 'user_id' });
|
|
Note.belongsTo(User, { foreignKey: 'user_id' });
|
|
Note.belongsTo(Project, { foreignKey: 'project_id', allowNull: true });
|
|
Project.hasMany(Note, { foreignKey: 'project_id' });
|
|
|
|
User.hasMany(InboxItem, { foreignKey: 'user_id' });
|
|
InboxItem.belongsTo(User, { foreignKey: 'user_id' });
|
|
|
|
// TaskEvent associations
|
|
User.hasMany(TaskEvent, { foreignKey: 'user_id', as: 'TaskEvents' });
|
|
TaskEvent.belongsTo(User, { foreignKey: 'user_id', as: 'User' });
|
|
Task.hasMany(TaskEvent, { foreignKey: 'task_id', as: 'TaskEvents' });
|
|
TaskEvent.belongsTo(Task, { foreignKey: 'task_id', as: 'Task' });
|
|
|
|
// Many-to-many associations
|
|
Task.belongsToMany(Tag, { through: 'tasks_tags', foreignKey: 'task_id', otherKey: 'tag_id' });
|
|
Tag.belongsToMany(Task, { through: 'tasks_tags', foreignKey: 'tag_id', otherKey: 'task_id' });
|
|
|
|
Note.belongsToMany(Tag, { through: 'notes_tags', foreignKey: 'note_id', otherKey: 'tag_id' });
|
|
Tag.belongsToMany(Note, { through: 'notes_tags', foreignKey: 'tag_id', otherKey: 'note_id' });
|
|
|
|
Project.belongsToMany(Tag, { through: 'projects_tags', foreignKey: 'project_id', otherKey: 'tag_id' });
|
|
Tag.belongsToMany(Project, { through: 'projects_tags', foreignKey: 'tag_id', otherKey: 'project_id' });
|
|
|
|
module.exports = {
|
|
sequelize,
|
|
User,
|
|
Area,
|
|
Project,
|
|
Task,
|
|
Tag,
|
|
Note,
|
|
InboxItem,
|
|
TaskEvent
|
|
}; |