251125:0000 Phase 6 wait start dev Check

This commit is contained in:
2025-11-25 00:28:33 +07:00
parent 553c2d13ad
commit 582ecb5741
22 changed files with 3757 additions and 489 deletions
@@ -0,0 +1,75 @@
-- ============================================================
-- Database Partitioning Script for LCBP3-DMS (Fixed #1075)
-- Target Tables: audit_logs, notifications
-- Strategy: Range Partitioning by YEAR(created_at)
-- ============================================================
-- ------------------------------------------------------------
-- 1. Audit Logs Partitioning
-- ------------------------------------------------------------
-- Step 1: เอา AUTO_INCREMENT ออกก่อน (เพื่อไม่ให้ติด Error 1075 ตอนลบ PK)
ALTER TABLE audit_logs
MODIFY audit_id BIGINT NOT NULL;
-- Step 2: ลบ Primary Key เดิม
ALTER TABLE audit_logs DROP PRIMARY KEY;
-- Step 3: สร้าง Primary Key ใหม่ (รวม created_at เพื่อทำ Partition)
ALTER TABLE audit_logs
ADD PRIMARY KEY (audit_id, created_at);
-- Step 4: ใส่ AUTO_INCREMENT กลับเข้าไป
ALTER TABLE audit_logs
MODIFY audit_id BIGINT NOT NULL AUTO_INCREMENT;
-- Step 5: สร้าง Partition
ALTER TABLE audit_logs PARTITION BY RANGE (YEAR(created_at)) (
PARTITION p_old
VALUES LESS THAN (2024),
PARTITION p2024
VALUES LESS THAN (2025),
PARTITION p2025
VALUES LESS THAN (2026),
PARTITION p2026
VALUES LESS THAN (2027),
PARTITION p2027
VALUES LESS THAN (2028),
PARTITION p2028
VALUES LESS THAN (2029),
PARTITION p2029
VALUES LESS THAN (2030),
PARTITION p2030
VALUES LESS THAN (2031),
PARTITION p_future
VALUES LESS THAN MAXVALUE
);
-- ------------------------------------------------------------
-- 2. Notifications Partitioning
-- ------------------------------------------------------------
-- Step 1: เอา AUTO_INCREMENT ออกก่อน
ALTER TABLE notifications
MODIFY id INT NOT NULL;
-- Step 2: ลบ Primary Key เดิม
ALTER TABLE notifications DROP PRIMARY KEY;
-- Step 3: สร้าง Primary Key ใหม่
ALTER TABLE notifications
ADD PRIMARY KEY (id, created_at);
-- Step 4: ใส่ AUTO_INCREMENT กลับเข้าไป
ALTER TABLE notifications
MODIFY id INT NOT NULL AUTO_INCREMENT;
-- Step 5: สร้าง Partition
ALTER TABLE notifications PARTITION BY RANGE (YEAR(created_at)) (
PARTITION p_old
VALUES LESS THAN (2024),
PARTITION p2024
VALUES LESS THAN (2025),
PARTITION p2025
VALUES LESS THAN (2026),
PARTITION p2026
VALUES LESS THAN (2027),
PARTITION p2027
VALUES LESS THAN (2028),
PARTITION p2028
VALUES LESS THAN (2029),
PARTITION p2029
VALUES LESS THAN (2030),
PARTITION p2030
VALUES LESS THAN (2031),
PARTITION p_future
VALUES LESS THAN MAXVALUE
);
@@ -0,0 +1,82 @@
// src/database/seeds/workflow-definitions.seed.ts
import { DataSource } from 'typeorm';
import { WorkflowDefinition } from '../../modules/workflow-engine/entities/workflow-definition.entity';
import { WorkflowDslService } from '../../modules/workflow-engine/workflow-dsl.service';
export const seedWorkflowDefinitions = async (dataSource: DataSource) => {
const repo = dataSource.getRepository(WorkflowDefinition);
const dslService = new WorkflowDslService();
// 1. RFA Workflow (Standard)
const rfaDsl = {
workflow: 'RFA',
version: 1,
states: [
{
name: 'DRAFT',
initial: true,
on: { SUBMIT: { to: 'IN_REVIEW', requirements: [{ role: 'Editor' }] } },
},
{
name: 'IN_REVIEW',
on: {
APPROVE: {
to: 'APPROVED',
requirements: [{ role: 'Contract Admin' }],
},
REJECT: {
to: 'REJECTED',
requirements: [{ role: 'Contract Admin' }],
},
COMMENT: { to: 'DRAFT', requirements: [{ role: 'Contract Admin' }] }, // ส่งกลับแก้ไข
},
},
{ name: 'APPROVED', terminal: true },
{ name: 'REJECTED', terminal: true },
],
};
// 2. Circulation Workflow
const circulationDsl = {
workflow: 'CIRCULATION',
version: 1,
states: [
{
name: 'OPEN',
initial: true,
on: { SEND: { to: 'IN_REVIEW' } },
},
{
name: 'IN_REVIEW',
on: {
COMPLETE: { to: 'COMPLETED' }, // เมื่อทุกคนตอบครบ
CANCEL: { to: 'CANCELLED' },
},
},
{ name: 'COMPLETED', terminal: true },
{ name: 'CANCELLED', terminal: true },
],
};
const workflows = [rfaDsl, circulationDsl];
for (const dsl of workflows) {
const exists = await repo.findOne({
where: { workflow_code: dsl.workflow, version: dsl.version },
});
if (!exists) {
const compiled = dslService.compile(dsl);
await repo.save(
repo.create({
workflow_code: dsl.workflow,
version: dsl.version,
dsl: dsl,
compiled: compiled,
is_active: true,
}),
);
console.log(`✅ Seeded Workflow: ${dsl.workflow} v${dsl.version}`);
}
}
};