[TASK-2026-01-20-005] feat: Add multi-tenancy to UOM entities
EPIC-P2-005: UOM Multi-tenancy Sync - Add tenant_id field to Uom entity - Add tenant_id field to UomCategory entity - Add Tenant relation to both entities - Add UpdateDateColumn for updated_at - Update indexes for tenant-based unique constraints Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
24b6ba9b38
commit
8d201c5b58
@ -3,28 +3,43 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Index,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Uom } from './uom.entity.js';
|
||||
import { Tenant } from '../../auth/entities/tenant.entity.js';
|
||||
|
||||
@Entity({ schema: 'core', name: 'uom_categories' })
|
||||
@Index('idx_uom_categories_name', ['name'], { unique: true })
|
||||
@Index('idx_uom_categories_tenant', ['tenantId'])
|
||||
@Index('idx_uom_categories_tenant_name', ['tenantId', 'name'], { unique: true })
|
||||
export class UomCategory {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100, nullable: false, unique: true })
|
||||
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
|
||||
tenantId: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100, nullable: false })
|
||||
name: string;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
description: string | null;
|
||||
|
||||
// Relations
|
||||
@ManyToOne(() => Tenant)
|
||||
@JoinColumn({ name: 'tenant_id' })
|
||||
tenant: Tenant;
|
||||
|
||||
@OneToMany(() => Uom, (uom) => uom.category)
|
||||
uoms: Uom[];
|
||||
|
||||
// Audit fields
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
@ -3,11 +3,13 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Index,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { UomCategory } from './uom-category.entity.js';
|
||||
import { Tenant } from '../../auth/entities/tenant.entity.js';
|
||||
|
||||
export enum UomType {
|
||||
REFERENCE = 'reference',
|
||||
@ -16,14 +18,18 @@ export enum UomType {
|
||||
}
|
||||
|
||||
@Entity({ schema: 'core', name: 'uom' })
|
||||
@Index('idx_uom_tenant', ['tenantId'])
|
||||
@Index('idx_uom_category_id', ['categoryId'])
|
||||
@Index('idx_uom_code', ['code'])
|
||||
@Index('idx_uom_active', ['active'])
|
||||
@Index('idx_uom_name_category', ['categoryId', 'name'], { unique: true })
|
||||
@Index('idx_uom_tenant_category_name', ['tenantId', 'categoryId', 'name'], { unique: true })
|
||||
export class Uom {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
|
||||
tenantId: string;
|
||||
|
||||
@Column({ type: 'uuid', nullable: false, name: 'category_id' })
|
||||
categoryId: string;
|
||||
|
||||
@ -64,6 +70,10 @@ export class Uom {
|
||||
active: boolean;
|
||||
|
||||
// Relations
|
||||
@ManyToOne(() => Tenant)
|
||||
@JoinColumn({ name: 'tenant_id' })
|
||||
tenant: Tenant;
|
||||
|
||||
@ManyToOne(() => UomCategory, (category) => category.uoms, {
|
||||
nullable: false,
|
||||
})
|
||||
@ -71,6 +81,9 @@ export class Uom {
|
||||
category: UomCategory;
|
||||
|
||||
// Audit fields
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user