- Introduced new columns `status`, `created_by`, and `updated_by` in the `users` table to track user status and ownership. - Updated the `employees` table to include a foreign key reference to the `users` table via `user_id`. - Created migration script `0012_users_primary.sql` to apply these changes to the database schema. - Enhanced the `EmployeesService` and `EmployeesRepository` to support user assignments and related data retrieval. - Updated DTOs and service methods to reflect the new user and employee relationships. - Added unit tests to validate the new functionality and ensure data integrity. - Modified existing controllers to accommodate the new fields and relationships in user and employee management.
28 lines
961 B
TypeScript
28 lines
961 B
TypeScript
import { pgTable, text, uniqueIndex, uuid, varchar } from 'drizzle-orm/pg-core';
|
|
import { primaryEntityColumns } from './primary-entity-columns';
|
|
import { users } from './schema';
|
|
|
|
/**
|
|
* Employees (primary aggregate).
|
|
* Kept in a separate module so Drizzle's table type stays resolvable.
|
|
*/
|
|
export const employees = pgTable(
|
|
'employees',
|
|
{
|
|
id: uuid('id').defaultRandom().notNull().primaryKey(),
|
|
code: varchar('code', { length: 16 }).notNull(),
|
|
name: varchar('name', { length: 64 }).notNull(),
|
|
phone: text('phone').notNull(),
|
|
position: text('position').notNull(),
|
|
userId: uuid('user_id').references(() => users.id, { onDelete: 'set null' }),
|
|
...primaryEntityColumns(users),
|
|
},
|
|
(t) => [
|
|
uniqueIndex('employees_code_unique').on(t.code),
|
|
uniqueIndex('employees_user_id_unique').on(t.userId),
|
|
],
|
|
);
|
|
|
|
export type EmployeeRow = typeof employees.$inferSelect;
|
|
export type NewEmployeeRow = typeof employees.$inferInsert;
|