import type { InferAttributes, InferCreationAttributes, Sequelize } from "sequelize"; import { DataTypes, Model } from "sequelize"; export class DepartmentModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare companyId: string; declare name: string; declare nameKey: string; declare active: boolean; } export class AssignmentModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare companyId: string; declare personId: string; declare departmentId: string; declare position: string | null; declare startDate: string; declare endDate: string | null; declare isPrimary: boolean; } export class AssignmentRevisionModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare assignmentId: string; declare sequence: number; declare position: string | null; declare startDate: string; declare endDate: string | null; declare isPrimary: boolean; declare recordedAt: string; } export const assignmentColumns = { position: { type: DataTypes.STRING(100), allowNull: true }, startDate: { type: DataTypes.DATEONLY, allowNull: false }, endDate: { type: DataTypes.DATEONLY, allowNull: true }, isPrimary: { type: DataTypes.BOOLEAN, allowNull: false }, }; export function initializePeopleModels(database: Sequelize): void { const key = { type: DataTypes.UUID, primaryKey: true }; DepartmentModel.init( { id: key, companyId: { type: DataTypes.UUID, allowNull: false }, name: { type: DataTypes.STRING(100), allowNull: false }, nameKey: { type: DataTypes.STRING(200).BINARY, allowNull: false }, active: { type: DataTypes.BOOLEAN, allowNull: false }, }, { sequelize: database, tableName: "company_departments", timestamps: false } ); AssignmentModel.init( { id: key, companyId: { type: DataTypes.UUID, allowNull: false }, personId: { type: DataTypes.UUID, allowNull: false }, departmentId: { type: DataTypes.UUID, allowNull: false }, ...assignmentColumns, }, { sequelize: database, tableName: "person_department_assignments", timestamps: false } ); AssignmentRevisionModel.init( { id: key, assignmentId: { type: DataTypes.UUID, allowNull: false }, sequence: { type: DataTypes.INTEGER, allowNull: false }, ...assignmentColumns, recordedAt: { type: DataTypes.STRING(24), allowNull: false }, }, { sequelize: database, tableName: "department_assignment_revisions", timestamps: false } ); }