From 32d820ea6bd7f6833d5d97ef2271b390f765ca93 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 7 Dec 2025 00:48:46 +0700 Subject: [PATCH] 251207:0048 Update Schema & Data dictionary/ Login PASS --- .agent/rules/00-project-specs.md | 4 +- README.md | 6 +- specs/00-overview/README.md | 2 +- specs/01-requirements/02-architecture.md | 2 +- .../03.11-document-numbering.md | 4 +- specs/02-architecture/README.md | 4 +- specs/02-architecture/system-architecture.md | 6 +- specs/03-implementation/document-numbering.md | 2 +- .../03-implementation/fullftack-js-v1.5.0.md | 4 +- specs/03-implementation/testing-strategy.md | 10 +- specs/04-operations/README.md | 14 +- specs/04-operations/deployment-guide.md | 16 +- .../document-numbering-operations.md | 4 +- specs/04-operations/environment-setup.md | 2 +- specs/04-operations/security-operations.md | 2 +- .../05-decisions/ADR-005-technology-stack.md | 8 +- .../ADR-015-deployment-infrastructure.md | 2 +- specs/07-database/data-dictionary-v1.5.1.md | 1711 +++++++++++ specs/07-database/data-dictionary-v1.5.1.sql | 2548 ----------------- specs/07-database/lcbp3-v1.5.1-schema.sql | 18 +- 20 files changed, 1773 insertions(+), 2596 deletions(-) create mode 100644 specs/07-database/data-dictionary-v1.5.1.md delete mode 100644 specs/07-database/data-dictionary-v1.5.1.sql diff --git a/.agent/rules/00-project-specs.md b/.agent/rules/00-project-specs.md index e1f3c52..6dbb7e0 100644 --- a/.agent/rules/00-project-specs.md +++ b/.agent/rules/00-project-specs.md @@ -32,8 +32,8 @@ Before generating code or planning a solution, you MUST conceptually load the co 5. **ðŸ’ū DATABASE & SCHEMA (`specs/07-databasee/`)** - *Action:* - **Read `specs/07-database/lcbp3-v1.5.1-schema.sql`** (or relevant `.sql` files) for exact table structures and constraints. - - **Consult `specs/database/data-dictionary-v1.5.1.md`** for field meanings and business rules. - - **Check `specs/database/lcbp3-v1.5.1-seed.sql`** to understand initial data states. + - **Consult `specs/07-database/data-dictionary-v1.5.1.md`** for field meanings and business rules. + - **Check `specs/07-database/lcbp3-v1.5.1-seed.sql`** to understand initial data states. - *Constraint:* NEVER invent table names or columns. Use ONLY what is defined here. 6. **⚙ïļ IMPLEMENTATION DETAILS (`specs/03-implementation/`)** diff --git a/README.md b/README.md index 634fc76..55b7168 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ LCBP3-DMS āđ€āļ›āđ‡āļ™āļĢāļ°āļšāļšāļšāļĢāļīāļŦāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ€āļ­āļ ```typescript { "framework": "NestJS (TypeScript, ESM)", - "database": "MariaDB 10.11", + "database": "MariaDB 11.8", "orm": "TypeORM", "authentication": "JWT + Passport", "authorization": "CASL (RBAC)", @@ -111,7 +111,7 @@ LCBP3-DMS āđ€āļ›āđ‡āļ™āļĢāļ°āļšāļšāļšāļĢāļīāļŦāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ€āļ­āļ - **Node.js**: v20.x āļŦāļĢāļ·āļ­āļŠāļđāļ‡āļāļ§āđˆāļē - **pnpm**: v8.x āļŦāļĢāļ·āļ­āļŠāļđāļ‡āļāļ§āđˆāļē - **Docker**: v24.x āļŦāļĢāļ·āļ­āļŠāļđāļ‡āļāļ§āđˆāļē -- **MariaDB**: 10.11 +- **MariaDB**: 11.8 - **Redis**: 7.x ### āļāļēāļĢāļ•āļīāļ”āļ•āļąāđ‰āļ‡ @@ -466,7 +466,7 @@ This project is **Internal Use Only** - āļĨāļīāļ‚āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ›āđ‡āļ™ āļŠāļģāļŦāļĢāļąāļšāļ„āļģāļ–āļēāļĄāļŦāļĢāļ·āļ­āļ›āļąāļāļŦāļē āļāļĢāļļāļ“āļēāļ•āļīāļ”āļ•āđˆāļ­: -- **Email**: support@np-dms.work +- **Email**: - **Internal Chat**: [āļĢāļ°āļšāļļāļŠāđˆāļ­āļ‡āļ—āļēāļ‡] - **Issue Tracker**: [Gitea Issues](https://git.np-dms.work/lcbp3/lcbp3-dms/issues) diff --git a/specs/00-overview/README.md b/specs/00-overview/README.md index fbb767a..6fb99d8 100644 --- a/specs/00-overview/README.md +++ b/specs/00-overview/README.md @@ -125,7 +125,7 @@ LCBP3-DMS is a comprehensive Document Management System (DMS) designed specifica ### Backend - **Framework:** NestJS (TypeScript) -- **Database:** MariaDB 10.11 +- **Database:** MariaDB 11.8 - **Cache & Queue:** Redis 7.2 - **Search:** Elasticsearch 8.11 - **ORM:** TypeORM diff --git a/specs/01-requirements/02-architecture.md b/specs/01-requirements/02-architecture.md index 843847f..af663a9 100644 --- a/specs/01-requirements/02-architecture.md +++ b/specs/01-requirements/02-architecture.md @@ -57,7 +57,7 @@ specs/01-objectives.md - Framework: NestJS (Node.js, TypeScript, ESM) - āļŦāļ™āđ‰āļēāļ—āļĩāđˆ: āļˆāļąāļ”āļāļēāļĢāđ‚āļ„āļĢāļ‡āļŠāļĢāđ‰āļēāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ (Data Models), āļŠāļĢāđ‰āļēāļ‡ API, āļˆāļąāļ”āļāļēāļĢāļŠāļīāļ—āļ˜āļīāđŒāļœāļđāđ‰āđƒāļŠāđ‰ (Roles & Permissions), āđāļĨāļ°āļŠāļĢāđ‰āļēāļ‡ Workflow āļ—āļąāđ‰āļ‡āļŦāļĄāļ”āļ‚āļ­āļ‡āļĢāļ°āļšāļš -- Database: MariaDB 10.11 +- Database: MariaDB 11.8 - Application name: lcbp3-db - Service name: mariadb diff --git a/specs/01-requirements/03.11-document-numbering.md b/specs/01-requirements/03.11-document-numbering.md index 1cf7a4c..ac6922a 100644 --- a/specs/01-requirements/03.11-document-numbering.md +++ b/specs/01-requirements/03.11-document-numbering.md @@ -1407,12 +1407,12 @@ export class DocumentNumberingController { services: # MariaDB - Master/Replica mariadb-master: - image: mariadb:10.11 + image: mariadb:11.8 environment: MYSQL_REPLICATION_MODE: master mariadb-replica: - image: mariadb:10.11 + image: mariadb:11.8 environment: MYSQL_REPLICATION_MODE: slave MYSQL_MASTER_HOST: mariadb-master diff --git a/specs/02-architecture/README.md b/specs/02-architecture/README.md index 92762ea..94bbfcb 100644 --- a/specs/02-architecture/README.md +++ b/specs/02-architecture/README.md @@ -225,7 +225,7 @@ Layer 6: File Security (Virus Scanning, Access Control) | **Server** | QNAP TS-473A | Physical Server | | **Containerization** | Docker + Docker Compose | Container Orchestration | | **Reverse Proxy** | Nginx Proxy Manager | SSL/TLS + Routing | -| **Database** | MariaDB 10.11 | Relational Database | +| **Database** | MariaDB 11.8 | Relational Database | | **Cache** | Redis 7.x | Caching + Locking | | **Search** | Elasticsearch | Full-text Search | | **Version Control** | Gitea | Self-hosted Git | @@ -337,7 +337,7 @@ graph TB end subgraph "Data Layer" - MariaDB[(MariaDB 10.11
Primary Database)] + MariaDB[(MariaDB 11.8
Primary Database)] Redis[(Redis
Cache + Queue)] Elastic[Elasticsearch
Search Engine] Storage[File Storage
/share/dms-data] diff --git a/specs/02-architecture/system-architecture.md b/specs/02-architecture/system-architecture.md index 19f8727..6e26a58 100644 --- a/specs/02-architecture/system-architecture.md +++ b/specs/02-architecture/system-architecture.md @@ -59,7 +59,7 @@ graph TB NPM --> N8N[n8n Workflow
n8n.np-dms.work] NPM --> Gitea[Gitea Git
git.np-dms.work] - Backend --> MariaDB[(MariaDB 10.11
db.np-dms.work)] + Backend --> MariaDB[(MariaDB 11.8
db.np-dms.work)] Backend --> Redis[(Redis Cache)] Backend --> Elastic[Elasticsearch] Backend --> Storage[File Storage
/share/dms-data] @@ -103,7 +103,7 @@ graph TB | :---------------- | :--------------- | :------------------ | :----------------------- | :-------------------------- | | **Frontend** | lcbp3-frontend | lcbp3.np-dms.work | Next.js 14+ (App Router) | Web Application UI | | **Backend** | lcbp3-backend | backend.np-dms.work | NestJS (TypeScript) | API Server & Business Logic | -| **Database** | lcbp3-db | db.np-dms.work | MariaDB 10.11 | Primary Database | +| **Database** | lcbp3-db | db.np-dms.work | MariaDB 11.8 | Primary Database | | **DB Management** | lcbp3-db | pma.np-dms.work | phpMyAdmin | Database Admin UI | | **Reverse Proxy** | lcbp3-npm | npm.np-dms.work | Nginx Proxy Manager | Reverse Proxy & SSL | | **Workflow** | lcbp3-n8n | n8n.np-dms.work | n8n | Workflow Automation | @@ -154,7 +154,7 @@ graph TB - Workflow Engine - Background Jobs (Notifications, Cleanup) -### 3.4 Database (MariaDB 10.11) +### 3.4 Database (MariaDB 11.8) **Features:** diff --git a/specs/03-implementation/document-numbering.md b/specs/03-implementation/document-numbering.md index e06f192..5c68863 100644 --- a/specs/03-implementation/document-numbering.md +++ b/specs/03-implementation/document-numbering.md @@ -21,7 +21,7 @@ related: - **Backend Framework**: NestJS 10.x - **ORM**: TypeORM 0.3.x -- **Database**: MariaDB 10.11 +- **Database**: MariaDB 11.8 - **Cache/Lock**: Redis 7.x + Redlock - **Message Queue**: BullMQ - **Monitoring**: Prometheus + Grafana diff --git a/specs/03-implementation/fullftack-js-v1.5.0.md b/specs/03-implementation/fullftack-js-v1.5.0.md index 3650b1a..09fec5c 100644 --- a/specs/03-implementation/fullftack-js-v1.5.0.md +++ b/specs/03-implementation/fullftack-js-v1.5.0.md @@ -183,7 +183,7 @@ export class DocumentCounter { #### **3.2.2 Virtual Columns for JSON Performance** -āđ€āļ™āļ·āđˆāļ­āļ‡āļˆāļēāļāđ€āļĢāļēāđƒāļŠāđ‰ MariaDB 10.11 āđāļĨāļ°āļĄāļĩāļāļēāļĢāđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨ JSON (Details) āđƒāļŦāđ‰āđƒāļŠāđ‰ **Generated Columns (Virtual)** āļŠāļģāļŦāļĢāļąāļš Field āļ—āļĩāđˆāļ•āđ‰āļ­āļ‡ Search/Sort āļšāđˆāļ­āļĒāđ† āđāļĨāļ°āļ—āļģ Index āļšāļ™ Virtual Column āļ™āļąāđ‰āļ™ +āđ€āļ™āļ·āđˆāļ­āļ‡āļˆāļēāļāđ€āļĢāļēāđƒāļŠāđ‰ MariaDB 11.8 āđāļĨāļ°āļĄāļĩāļāļēāļĢāđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨ JSON (Details) āđƒāļŦāđ‰āđƒāļŠāđ‰ **Generated Columns (Virtual)** āļŠāļģāļŦāļĢāļąāļš Field āļ—āļĩāđˆāļ•āđ‰āļ­āļ‡ Search/Sort āļšāđˆāļ­āļĒāđ† āđāļĨāļ°āļ—āļģ Index āļšāļ™ Virtual Column āļ™āļąāđ‰āļ™ ```sql -- āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡ SQL Migration @@ -408,7 +408,7 @@ Unified Workflow Engine (Core Architecture) | ----------------------- | ---------------------------------------------------- | -------------------------------------- | | **Framework** | `@nestjs/core`, `@nestjs/common` | Core Framework | | **Language** | `TypeScript` | āđƒāļŠāđ‰ TypeScript āļ—āļąāđ‰āļ‡āļĢāļ°āļšāļš | -| **Database** | `MariaDB 10.11` | āļāļēāļ™āļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļ | +| **Database** | `MariaDB 11.8` | āļāļēāļ™āļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļ | | **ORM** | `@nestjs/typeorm`, `typeorm` | 🗃ïļāļˆāļąāļ”āļāļēāļĢāļāļēāļĢāđ€āļŠāļ·āđˆāļ­āļĄāļ•āđˆāļ­āđāļĨāļ° Query āļāļēāļ™āļ‚āđ‰āļ­āļĄāļđāļĨ | | **Validation** | `class-validator`, `class-transformer` | ðŸ“Ķāļ•āļĢāļ§āļˆāļŠāļ­āļšāđāļĨāļ°āđāļ›āļĨāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāđƒāļ™ DTO | | **Auth** | `@nestjs/jwt`, `@nestjs/passport`, `passport-jwt` | 🔐āļāļēāļĢāļĒāļ·āļ™āļĒāļąāļ™āļ•āļąāļ§āļ•āļ™āļ”āđ‰āļ§āļĒ JWT | diff --git a/specs/03-implementation/testing-strategy.md b/specs/03-implementation/testing-strategy.md index 72a07c7..5908dc8 100644 --- a/specs/03-implementation/testing-strategy.md +++ b/specs/03-implementation/testing-strategy.md @@ -52,11 +52,11 @@ related: ### Test Distribution -| Level | Coverage | Speed | Purpose | -| ----------- | -------- | ---------- | ------------------------------- | -| Unit | 60% | Fast (ms) | āļ—āļ”āļŠāļ­āļšāļ•āļĢāļĢāļāļ°āđāļ•āđˆāļĨāļ° Function | +| Level | Coverage | Speed | Purpose | +| ----------- | -------- | ---------- | ---------------------------- | +| Unit | 60% | Fast (ms) | āļ—āļ”āļŠāļ­āļšāļ•āļĢāļĢāļāļ°āđāļ•āđˆāļĨāļ° Function | | Integration | 30% | Medium (s) | āļ—āļ”āļŠāļ­āļšāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļĢāđˆāļ§āļĄāļāļąāļ™āļ‚āļ­āļ‡ Modules | -| E2E | 10% | Slow (m) | āļ—āļ”āļŠāļ­āļš User Journey āļ—āļąāđ‰āļ‡āļŦāļĄāļ” | +| E2E | 10% | Slow (m) | āļ—āļ”āļŠāļ­āļš User Journey āļ—āļąāđ‰āļ‡āļŦāļĄāļ” | --- @@ -958,7 +958,7 @@ jobs: runs-on: ubuntu-latest services: mariadb: - image: mariadb:10.11 + image: mariadb:11.8 env: MYSQL_ROOT_PASSWORD: test MYSQL_DATABASE: lcbp3_test diff --git a/specs/04-operations/README.md b/specs/04-operations/README.md index a2e7854..6bae253 100644 --- a/specs/04-operations/README.md +++ b/specs/04-operations/README.md @@ -16,23 +16,23 @@ This directory contains operational documentation for deploying, maintaining, an ### Deployment & Infrastructure -| Document | Description | Status | -| ---------------------------------------------- | ------------------------------------------------------ | ----------- | +| Document | Description | Status | +| ---------------------------------------------- | ------------------------------------------------------ | ---------- | | [deployment-guide.md](./deployment-guide.md) | Docker deployment procedures on QNAP Container Station | ✅ Complete | | [environment-setup.md](./environment-setup.md) | Environment variables and configuration management | ✅ Complete | ### Monitoring & Maintenance -| Document | Description | Status | -| -------------------------------------------------------- | --------------------------------------------------- | ----------- | +| Document | Description | Status | +| -------------------------------------------------------- | --------------------------------------------------- | ---------- | | [monitoring-alerting.md](./monitoring-alerting.md) | Monitoring setup, health checks, and alerting rules | ✅ Complete | | [backup-recovery.md](./backup-recovery.md) | Backup strategies and disaster recovery procedures | ✅ Complete | | [maintenance-procedures.md](./maintenance-procedures.md) | Routine maintenance and update procedures | ✅ Complete | ### Security & Compliance -| Document | Description | Status | -| -------------------------------------------------- | ---------------------------------------------- | ----------- | +| Document | Description | Status | +| -------------------------------------------------- | ---------------------------------------------- | ---------- | | [security-operations.md](./security-operations.md) | Security monitoring and incident response | ✅ Complete | | [incident-response.md](./incident-response.md) | Incident classification and response playbooks | ✅ Complete | @@ -74,7 +74,7 @@ graph TB NGINX[NGINX
Reverse Proxy
Port 80/443] Backend[NestJS Backend
Port 3000] Frontend[Next.js Frontend
Port 3001] - MariaDB[(MariaDB 10.11
Port 3306)] + MariaDB[(MariaDB 11.8
Port 3306)] Redis[(Redis 7.2
Port 6379)] ES[(Elasticsearch
Port 9200)] end diff --git a/specs/04-operations/deployment-guide.md b/specs/04-operations/deployment-guide.md index 0705bdf..cdfa963 100644 --- a/specs/04-operations/deployment-guide.md +++ b/specs/04-operations/deployment-guide.md @@ -28,13 +28,13 @@ This guide provides step-by-step instructions for deploying the LCBP3-DMS system ### Hardware Requirements -| Component | Minimum Specification | -| -------------- | -------------------------- | -| CPU | 4 cores @ 2.0 GHz | -| RAM | 16 GB | -| Storage | 500 GB SSD (System + Data) | -| Network | 1 Gbps Ethernet | -| QNAP Model | TS-473A or equivalent | +| Component | Minimum Specification | +| ---------- | -------------------------- | +| CPU | 4 cores @ 2.0 GHz | +| RAM | 16 GB | +| Storage | 500 GB SSD (System + Data) | +| Network | 1 Gbps Ethernet | +| QNAP Model | TS-473A or equivalent | ### Software Requirements @@ -267,7 +267,7 @@ services: retries: 3 mariadb: - image: mariadb:10.11 + image: mariadb:11.8 container_name: lcbp3-mariadb restart: unless-stopped environment: diff --git a/specs/04-operations/document-numbering-operations.md b/specs/04-operations/document-numbering-operations.md index b1f5357..61e3630 100644 --- a/specs/04-operations/document-numbering-operations.md +++ b/specs/04-operations/document-numbering-operations.md @@ -72,7 +72,7 @@ related: # docker-compose.yml services: mariadb-master: - image: mariadb:10.11 + image: mariadb:11.8 environment: MYSQL_REPLICATION_MODE: master MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} @@ -82,7 +82,7 @@ services: - backend mariadb-replica: - image: mariadb:10.11 + image: mariadb:11.8 environment: MYSQL_REPLICATION_MODE: slave MYSQL_MASTER_HOST: mariadb-master diff --git a/specs/04-operations/environment-setup.md b/specs/04-operations/environment-setup.md index f5bf7db..e9f1e3c 100644 --- a/specs/04-operations/environment-setup.md +++ b/specs/04-operations/environment-setup.md @@ -162,7 +162,7 @@ services: # MariaDB Database mariadb: - image: mariadb:10.11 + image: mariadb:11.8 container_name: lcbp3-mariadb environment: MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS} diff --git a/specs/04-operations/security-operations.md b/specs/04-operations/security-operations.md index c13d106..923c86d 100644 --- a/specs/04-operations/security-operations.md +++ b/specs/04-operations/security-operations.md @@ -190,7 +190,7 @@ npm audit --production # Scan Docker images trivy image --severity HIGH,CRITICAL lcbp3-backend:latest trivy image --severity HIGH,CRITICAL lcbp3-frontend:latest -trivy image --severity HIGH,CRITICAL mariadb:10.11 +trivy image --severity HIGH,CRITICAL mariadb:11.8 trivy image --severity HIGH,CRITICAL redis:7.2-alpine ``` diff --git a/specs/05-decisions/ADR-005-technology-stack.md b/specs/05-decisions/ADR-005-technology-stack.md index 0e2d084..a5be857 100644 --- a/specs/05-decisions/ADR-005-technology-stack.md +++ b/specs/05-decisions/ADR-005-technology-stack.md @@ -95,7 +95,7 @@ LCBP3-DMS āļ•āđ‰āļ­āļ‡āđ€āļĨāļ·āļ­āļ Technology Stack āļŠāļģāļŦāļĢāļąāļšāļžāļą | **Framework** | NestJS | Modular, TypeScript-first, similar to Angular | | **Language** | TypeScript 5.x | Type safety, better DX | | **ORM** | TypeORM | TypeScript support, migrations, repositories | -| **Database** | MariaDB 10.11 | JSON support, virtual columns, QNAP compatible | +| **Database** | MariaDB 11.8 | JSON support, virtual columns, QNAP compatible | | **Validation** | class-validator | Decorator-based, integrates with NestJS | | **Authentication** | Passport + JWT | Standard, well-supported | | **Authorization** | CASL | Flexible RBAC implementation | @@ -112,7 +112,7 @@ LCBP3-DMS āļ•āđ‰āļ­āļ‡āđ€āļĨāļ·āļ­āļ Technology Stack āļŠāļģāļŦāļĢāļąāļšāļžāļą | **Styling** | Tailwind CSS | Utility-first, fast development | | **Component Library** | shadcn/ui | Accessible, customizable, TypeScript | | **State Management** | TanStack Query | Server state management | -| **Form Handling** | React Hook Form | Performance, āļ•āđ‰ validation with Zod | +| **Form Handling** | React Hook Form | Performance, āļ•āđ‰ validation with Zod | | **Testing** | Vitest + Playwright | Fast unit tests, reliable E2E | #### Infrastructure @@ -121,7 +121,7 @@ LCBP3-DMS āļ•āđ‰āļ­āļ‡āđ€āļĨāļ·āļ­āļ Technology Stack āļŠāļģāļŦāļĢāļąāļšāļžāļą | :------------------- | :---------------------- | :------------------------------- | | **Containerization** | Docker + Docker Compose | QNAP Container Station | | **Reverse Proxy** | Nginx Proxy Manager | UI-based SSL management | -| **Database** | MariaDB 10.11 | Robust, JSON support | +| **Database** | MariaDB 11.8 | Robust, JSON support | | **Cache** | Redis 7 | Session, locks, queue management | | **Search** | Elasticsearch 8 | Full-text search | | **Workflow** | n8n | Visual workflow automation | @@ -212,7 +212,7 @@ lcbp3-dms/ ### Database Choice -**Chosen:** MariaDB 10.11 (Not PostgreSQL) +**Chosen:** MariaDB 11.8 (Not PostgreSQL) **Rationale:** diff --git a/specs/05-decisions/ADR-015-deployment-infrastructure.md b/specs/05-decisions/ADR-015-deployment-infrastructure.md index e6d8562..ee7c566 100644 --- a/specs/05-decisions/ADR-015-deployment-infrastructure.md +++ b/specs/05-decisions/ADR-015-deployment-infrastructure.md @@ -64,7 +64,7 @@ services: - lcbp3-network mariadb: - image: mariadb:10.11 + image: mariadb:11.8 volumes: - mariadb-data:/var/lib/mysql networks: diff --git a/specs/07-database/data-dictionary-v1.5.1.md b/specs/07-database/data-dictionary-v1.5.1.md new file mode 100644 index 0000000..3e2494d --- /dev/null +++ b/specs/07-database/data-dictionary-v1.5.1.md @@ -0,0 +1,1711 @@ +# **āļ•āļēāļĢāļēāļ‡āļāļēāļ™āļ‚āđ‰āļ­āļĄāļđāļĨ (Data Dictionary) - LCBP3-DMS (V1.5.1)** + +āđ€āļ­āļāļŠāļēāļĢāļ™āļĩāđ‰āļŠāļĢāļļāļ›āđ‚āļ„āļĢāļ‡āļŠāļĢāđ‰āļēāļ‡āļ•āļēāļĢāļēāļ‡, +FOREIGN KEYS (FK), +āđāļĨāļ° Constraints āļ—āļĩāđˆāļŠāļģāļ„āļąāļāļ—āļąāđ‰āļ‡āļŦāļĄāļ”āđƒāļ™āļāļēāļ™āļ‚āđ‰āļ­āļĄāļđāļĨ LCBP3 - DMS (v1.5.1) āđ€āļžāļ·āđˆāļ­āđƒāļŠāđ‰āđ€āļ›āđ‡āļ™āđ€āļ­āļāļŠāļēāļĢāļ­āđ‰āļēāļ‡āļ­āļīāļ‡āļŠāļģāļŦāļĢāļąāļšāļ—āļĩāļĄāļžāļąāļ’āļ™āļē Backend (NestJS) āđāļĨāļ° Frontend (Next.js) āđ‚āļ”āļĒāļ­āļīāļ‡āļˆāļēāļ Requirements āđāļĨāļ° SQL Script āļĨāđˆāļēāļŠāļļāļ” ** āļŠāļ–āļēāļ™āļ°: ** FINAL GUIDELINE ** āļ§āļąāļ™āļ—āļĩāđˆ: ** 2025 -12 -04 ** āļ­āđ‰āļēāļ‡āļ­āļīāļ‡: ** Requirements v1.5.1 & FullStackJS Guidelines v1.5.1 ** Classification: ** Internal Technical Documentation ## 📝 āļŠāļĢāļļāļ›āļĢāļēāļĒāļāļēāļĢāļ›āļĢāļąāļšāļ›āļĢāļļāļ‡ (Summary of Changes in v1.5.1) +1.** Enhanced Document Numbering **: āļ›āļĢāļąāļšāļ›āļĢāļļāļ‡āļ•āļēāļĢāļēāļ‡ `document_number_counters` āđƒāļŦāđ‰āļĢāļ­āļ‡āļĢāļąāļš 8 - COLUMN Composite PK āđāļĨāļ°āđ€āļžāļīāđˆāļĄāļ•āļēāļĢāļēāļ‡ `document_number_audit`, +`document_number_errors` 2.** Unified Workflow ENGINE **: āđ€āļžāļīāđˆāļĄāļ•āļēāļĢāļēāļ‡ `workflow_definitions`, +`workflow_instances`, +`workflow_histories` āđ€āļžāļ·āđˆāļ­āļĢāļ­āļ‡āļĢāļąāļš Workflow āđāļšāļš DYNAMIC 3.** New MASTER TABLES **: āđ€āļžāļīāđˆāļĄāļ•āļēāļĢāļēāļ‡ `disciplines` āđāļĨāļ° `correspondence_sub_types` āļ•āļēāļĄ Req 6B 4.** System Enhancements **: āđ€āļžāļīāđˆāļĄāļ•āļēāļĢāļēāļ‡ `json_schemas` āđāļĨāļ° `user_preferences` 5.** Schema Updates **: āđ€āļžāļīāđˆāļĄ `discipline_id` āđƒāļ™āļ•āļēāļĢāļēāļ‡ `correspondences` āđāļĨāļ° `rfas` --- + +## **1. ðŸĒ Core & Master Data Tables (āļ­āļ‡āļ„āđŒāļāļĢ, āđ‚āļ„āļĢāļ‡āļāļēāļĢ, āļŠāļąāļāļāļē)** + +### 1.1 organization_roles + +* * Purpose **: MASTER TABLE FOR organization role TYPES IN the system | COLUMN Name | Data TYPE | Constraints | Description | | ----------- | ----------- | --------------------------- | ---------------------------------------------------------------- | +| id | INT | PRIMARY KEY, +AUTO_INCREMENT | UNIQUE identifier FOR organization role | | role_name | VARCHAR(20) | NOT NULL, +UNIQUE | Role name ( + OWNER, + DESIGNER, + CONSULTANT, + CONTRACTOR, + THIRD PARTY +) | ** INDEXES **: - PRIMARY KEY (id) - UNIQUE (role_name) ** Business Rules **: - Predefined system roles FOR organization TYPES - Cannot be deleted IF referenced by organizations --- + +### 1.2 organizations + +* * Purpose **: MASTER TABLE storing ALL organizations involved IN the system | COLUMN Name | Data TYPE | Constraints | Description | | ----------------- | ------------ | ----------------------------------- | ---------------------------------------- | +| id | INT | PRIMARY KEY, +AUTO_INCREMENT | UNIQUE identifier FOR organization | | organization_code | VARCHAR(20) | NOT NULL, +UNIQUE | Organization code (e.g., 'āļāļ—āļ—.', 'TEAM') | | organization_name | VARCHAR(255) | NOT NULL | FULL organization name | | is_active | BOOLEAN | DEFAULT TRUE | Active STATUS (1 = active, 0 = inactive) | | created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | | updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last +UPDATE timestamp | ** INDEXES **: - PRIMARY KEY (id) - UNIQUE (organization_code) - INDEX (is_active) ** Relationships **: - Referenced by: users, + project_organizations, + contract_organizations, + correspondences, + circulations --- + + ### 1.3 projects + + * * Purpose **: MASTER TABLE FOR ALL projects IN the system | COLUMN Name | Data TYPE | Constraints | Description | | ------------ | ------------ | --------------------------- | ----------------------------- | + | id | INT | PRIMARY KEY, + AUTO_INCREMENT | UNIQUE identifier FOR project | | project_code | VARCHAR(50) | NOT NULL, + UNIQUE | Project code (e.g., 'LCBP3') | | project_name | VARCHAR(255) | NOT NULL | FULL project name | | is_active | TINYINT(1) | DEFAULT 1 | Active STATUS | ** INDEXES **: - PRIMARY KEY (id) - UNIQUE (project_code) - INDEX (is_active) ** Relationships **: - Referenced by: contracts, + correspondences, + document_number_formats, + drawings --- + + ### 1.4 contracts + + * * Purpose **: MASTER TABLE FOR contracts within projects | COLUMN Name | Data TYPE | Constraints | Description | | ------------- | ------------ | ----------------------------------- | ------------------------------ | + | id | INT | PRIMARY KEY, + AUTO_INCREMENT | UNIQUE identifier FOR contract | | project_id | INT | NOT NULL, + FK | Reference TO projects TABLE | | contract_code | VARCHAR(50) | NOT NULL, + UNIQUE | Contract code | | contract_name | VARCHAR(255) | NOT NULL | FULL contract name | | description | TEXT | NULL | Contract description | | start_date | DATE | NULL | Contract START date | | end_date | DATE | NULL | Contract +END date | | is_active | BOOLEAN | DEFAULT TRUE | Active STATUS | | created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | | updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last +UPDATE timestamp | ** INDEXES **: - PRIMARY KEY (id) - UNIQUE (contract_code) - FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE - INDEX (project_id, is_active) ** Relationships **: - Parent: projects - Referenced by: contract_organizations, + user_assignments --- + + ### 1.5 disciplines (NEW v1.5.1) + + * * Purpose **: āđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨāļŠāļēāļ‚āļēāļ‡āļēāļ™ (Disciplines) āđāļĒāļāļ•āļēāļĄāļŠāļąāļāļāļē (Req 6B) | COLUMN Name | Data TYPE | Constraints | Description | |: -------------- | :----------- | :----------- | :--------------------- | + | id | INT | PK, + AI | UNIQUE identifier | | contract_id | INT | FK, + NOT NULL | āļœāļđāļāļāļąāļšāļŠāļąāļāļāļē | | discipline_code | VARCHAR(10) | NOT NULL | āļĢāļŦāļąāļŠāļŠāļēāļ‚āļē (āđ€āļŠāđˆāļ™ GEN, STR) | | code_name_th | VARCHAR(255) | NULL | āļŠāļ·āđˆāļ­āđ„āļ—āļĒ | | code_name_en | VARCHAR(255) | NULL | āļŠāļ·āđˆāļ­āļ­āļąāļ‡āļāļĪāļĐ | | is_active | TINYINT(1) | DEFAULT 1 | āļŠāļ–āļēāļ™āļ°āļāļēāļĢāđƒāļŠāđ‰āļ‡āļēāļ™ | ** INDEXES **: - UNIQUE (contract_id, discipline_code) --- + + ## **2. ðŸ‘Ĩ Users & RBAC Tables (āļœāļđāđ‰āđƒāļŠāđ‰, āļŠāļīāļ—āļ˜āļīāđŒ, āļšāļ—āļšāļēāļ—)** + + ### 2.1 users + + * * Purpose **: MASTER TABLE storing ALL system users | COLUMN Name | Data TYPE | Constraints | Description | | ----------------------- | ------------ | ----------------------------------- | -------------------------------- | + | user_id | INT | PRIMARY KEY, + AUTO_INCREMENT | UNIQUE identifier FOR user | | username | VARCHAR(50) | NOT NULL, + UNIQUE | Login username | | password_hash | VARCHAR(255) | NOT NULL | Hashed PASSWORD (bcrypt) | | first_name | VARCHAR(50) | NULL | User 's first name | +| last_name | VARCHAR(50) | NULL | User' s last name | | email | VARCHAR(100) | NOT NULL, + UNIQUE | Email address | | line_id | VARCHAR(100) | NULL | LINE messenger ID | | primary_organization_id | INT | NULL, + FK | PRIMARY organization affiliation | | is_active | TINYINT(1) | DEFAULT 1 | Active STATUS | | failed_attempts | INT | DEFAULT 0 | Failed login attempts counter | | locked_until | DATETIME | NULL | Account LOCK expiration time | | last_login_at | TIMESTAMP | NULL | Last successful login timestamp | | created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | | updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last +UPDATE timestamp | | deleted_at | DATETIME | NULL | Deleted at | ** INDEXES **: - PRIMARY KEY (user_id) - UNIQUE (username) - UNIQUE (email) - FOREIGN KEY (primary_organization_id) REFERENCES organizations(id) ON DELETE +SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: organizations (primary_organization_id) - Referenced by: user_assignments, + audit_logs, + notifications, + circulation_routings --- + + ### 2.2 roles + + * * Purpose **: MASTER TABLE defining system roles WITH scope levels | COLUMN Name | Data TYPE | Constraints | Description | | ----------- | ------------ | --------------------------- | ---------------------------------------------------- | + | role_id | INT | PRIMARY KEY, + AUTO_INCREMENT | UNIQUE identifier FOR role | | role_name | VARCHAR(100) | NOT NULL | Role name (e.g., 'Superadmin', 'Document Control') | | scope | ENUM | NOT NULL | Scope LEVEL: GLOBAL, + Organization, + Project, + Contract | | description | TEXT | NULL | Role description | | is_system | BOOLEAN | DEFAULT FALSE | System role flag (cannot be deleted) | ** INDEXES **: - PRIMARY KEY (role_id) - INDEX (scope) ** Relationships **: - Referenced by: role_permissions, + user_assignments --- + + ### 2.3 permissions + + * * Purpose **: MASTER TABLE defining ALL system permissions | COLUMN Name | Data TYPE | Constraints | Description | | --------------- | ------------ | --------------------------- | ------------------------------------------------------ | + | permission_id | INT | PRIMARY KEY, + AUTO_INCREMENT | UNIQUE identifier FOR permission | | permission_name | VARCHAR(100) | NOT NULL, + UNIQUE | Permission code (e.g., 'rfas.create', 'document.view') | | description | TEXT | NULL | Permission description | | module | VARCHAR(50) | NULL | Related module name | | scope_level | ENUM | NULL | Scope: GLOBAL, + ORG, + PROJECT | | is_active | TINYINT(1) | DEFAULT 1 | Active STATUS | ** INDEXES **: - PRIMARY KEY (permission_id) - UNIQUE (permission_name) - INDEX (module) - INDEX (scope_level) - INDEX (is_active) ** Relationships **: - Referenced by: role_permissions --- + + ### 2.4 role_permissions + + * * Purpose **: Junction TABLE mapping roles TO permissions (M :N) | COLUMN Name | Data TYPE | Constraints | Description | | ------------- | --------- | --------------- | ------------------------------ | + | role_id | INT | PRIMARY KEY, + FK | Reference TO roles TABLE | | permission_id | INT | PRIMARY KEY, + FK | Reference TO permissions TABLE | ** INDEXES **: - PRIMARY KEY (role_id, permission_id) - FOREIGN KEY (role_id) REFERENCES roles(role_id) ON DELETE CASCADE - FOREIGN KEY (permission_id) REFERENCES permissions(permission_id) ON DELETE CASCADE - INDEX (permission_id) ** Relationships **: - Parent: roles, + permissions --- + + ### 2.5 user_assignments + + * * Purpose **: Junction TABLE assigning users TO roles WITH scope context | COLUMN Name | Data TYPE | Constraints | Description | | ------------------- | --------- | --------------------------- | ---------------------------------- | + | id | INT | PRIMARY KEY, + AUTO_INCREMENT | UNIQUE identifier | | user_id | INT | NOT NULL, + FK | Reference TO users TABLE | | role_id | INT | NOT NULL, + FK | Reference TO roles TABLE | | organization_id | INT | NULL, + FK | Organization scope (IF applicable) | | project_id | INT | NULL, + FK | Project scope (IF applicable) | | contract_id | INT | NULL, + FK | Contract scope (IF applicable) | | assigned_by_user_id | INT | NULL, + FK | User who made the assignment | | assigned_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Assignment timestamp | ** INDEXES **: - PRIMARY KEY (id) - FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE - FOREIGN KEY (role_id) REFERENCES roles(role_id) ON DELETE CASCADE - FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE - FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE - FOREIGN KEY (contract_id) REFERENCES contracts(id) ON DELETE CASCADE - FOREIGN KEY (assigned_by_user_id) REFERENCES users(user_id) - INDEX (user_id, role_id) - INDEX (organization_id) - INDEX (project_id) - INDEX (contract_id) ** Relationships **: - Parent: users, + roles, + organizations, + projects, + contracts --- + + ### 2.6 project_organizations + + * * Purpose **: Junction TABLE linking projects TO participating organizations (M :N) | COLUMN Name | Data TYPE | Constraints | Description | | --------------- | --------- | --------------- | -------------------------------- | + | project_id | INT | PRIMARY KEY, + FK | Reference TO projects TABLE | | organization_id | INT | PRIMARY KEY, + FK | Reference TO organizations TABLE | ** INDEXES **: - PRIMARY KEY (project_id, organization_id) - FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE - FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE - INDEX (organization_id) ** Relationships **: - Parent: projects, + organizations --- + + ### 2.7 contract_organizations + + * * Purpose **: Junction TABLE linking contracts TO participating organizations WITH roles (M :N) | COLUMN Name | Data TYPE | Constraints | Description | | ---------------- | ------------ | --------------- | ------------------------------------------------------------------------- | + | contract_id | INT | PRIMARY KEY, + FK | Reference TO contracts TABLE | | organization_id | INT | PRIMARY KEY, + FK | Reference TO organizations TABLE | | role_in_contract | VARCHAR(100) | NULL | Organization 's role in contract (Owner, Designer, Consultant, Contractor) | + +**Indexes**: + +* PRIMARY KEY (contract_id, organization_id) +* FOREIGN KEY (contract_id) REFERENCES contracts(id) ON DELETE CASCADE +* FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE +* INDEX (organization_id) +* INDEX (role_in_contract) + +**Relationships**: + +* Parent: contracts, organizations + +--- + +### 2.8 user_preferences (NEW v1.5.1) + +**Purpose**: āđ€āļāđ‡āļšāļāļēāļĢāļ•āļąāđ‰āļ‡āļ„āđˆāļēāļŠāđˆāļ§āļ™āļ•āļąāļ§āļ‚āļ­āļ‡āļœāļđāđ‰āđƒāļŠāđ‰ (Req 5.5, 6.8.3) + +| Column Name | Data Type | Constraints | Description | +| :----------- | :---------- | :---------------- | :-------------- | +| user_id | INT | PK, FK | User ID | +| notify_email | BOOLEAN | DEFAULT TRUE | āļĢāļąāļšāļ­āļĩāđ€āļĄāļĨāđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™ | +| notify_line | BOOLEAN | DEFAULT TRUE | āļĢāļąāļšāđ„āļĨāļ™āđŒāđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™ | +| digest_mode | BOOLEAN | DEFAULT FALSE | āļĢāļąāļšāđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™āđāļšāļšāļĢāļ§āļĄ | +| ui_theme | VARCHAR(20) | DEFAULT ' light ' | UI Theme | + +--- + +### 2.9 refresh_tokens (NEW v1.5.1) + +**Purpose**: āđ€āļāđ‡āļš Refresh Tokens āļŠāļģāļŦāļĢāļąāļšāļāļēāļĢāļ—āļģ Authentication āđāļĨāļ° Token Rotation + +| Column Name | Data Type | Constraints | Description | +| :---------------- | :----------- | :------------------------ | :------------------------------------ | +| token_id | INT | PK, AI | Unique Token ID | +| user_id | INT | FK, NOT NULL | āđ€āļˆāđ‰āļēāļ‚āļ­āļ‡ Token | +| token_hash | VARCHAR(255) | NOT NULL | Hash āļ‚āļ­āļ‡ Refresh Token (Security) | +| expires_at | DATETIME | NOT NULL | āļ§āļąāļ™āļŦāļĄāļ”āļ­āļēāļĒāļļāļ‚āļ­āļ‡ Token | +| is_revoked | BOOLEAN | DEFAULT FALSE | āļŠāļ–āļēāļ™āļ°āļ–āļđāļāļĒāļāđ€āļĨāļīāļ (True = āđƒāļŠāđ‰āļ‡āļēāļ™āđ„āļĄāđˆāđ„āļ”āđ‰) | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | āđ€āļ§āļĨāļēāļ—āļĩāđˆāļŠāļĢāđ‰āļēāļ‡ | +| replaced_by_token | VARCHAR(255) | NULL | Token āđƒāļŦāļĄāđˆāļ—āļĩāđˆāļĄāļēāđāļ—āļ™āļ—āļĩāđˆ (āļāļĢāļ“āļĩ Token Rotation) | + +**Indexes**: + +* PRIMARY KEY (token_id) +* FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE +* INDEX (user_id) + +**Relationships**: + +* Parent: users + +--- + +## **3. ✉ïļ Correspondences Tables (āđ€āļ­āļāļŠāļēāļĢāļŦāļĨāļąāļ, Revisions, Workflows)** + +### 3.1 correspondence_types + +**Purpose**: Master table for correspondence document types + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | --------------------------- | --------------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique identifier | +| type_code | VARCHAR(50) | NOT NULL, UNIQUE | Type code (e.g., ' RFA ', ' RFI ', ' TRANSMITTAL ') | +| type_name | VARCHAR(255) | NOT NULL | Full type name | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (type_code) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Referenced by: correspondences, document_number_formats, document_number_counters + +--- + +### 3.2 correspondence_sub_types (NEW v1.5.1) + +**Purpose**: āđ€āļāđ‡āļšāļ›āļĢāļ°āđ€āļ āļ—āļŦāļ™āļąāļ‡āļŠāļ·āļ­āļĒāđˆāļ­āļĒ (Sub Types) āļŠāļģāļŦāļĢāļąāļš Mapping āđ€āļĨāļ‚āļĢāļŦāļąāļŠ (Req 6B) + +| Column Name | Data Type | Constraints | Description | +| :--------------------- | :----------- | :----------- | :------------------------ | +| id | INT | PK, AI | Unique identifier | +| contract_id | INT | FK, NOT NULL | āļœāļđāļāļāļąāļšāļŠāļąāļāļāļē | +| correspondence_type_id | INT | FK, NOT NULL | āļœāļđāļāļāļąāļšāļ›āļĢāļ°āđ€āļ āļ—āđ€āļ­āļāļŠāļēāļĢāļŦāļĨāļąāļ | +| sub_type_code | VARCHAR(20) | NOT NULL | āļĢāļŦāļąāļŠāļĒāđˆāļ­āļĒ (āđ€āļŠāđˆāļ™ MAT, SHP) | +| sub_type_name | VARCHAR(255) | NULL | āļŠāļ·āđˆāļ­āļ›āļĢāļ°āđ€āļ āļ—āļŦāļ™āļąāļ‡āļŠāļ·āļ­āļĒāđˆāļ­āļĒ | +| sub_type_number | VARCHAR(10) | NULL | āđ€āļĨāļ‚āļĢāļŦāļąāļŠāļŠāļģāļŦāļĢāļąāļš Running Number | + +--- + +### 3.3 correspondences (UPDATE v1.5.1) + +**Purpose**: Master table for correspondence documents (non-revisioned data) + +| Column Name | Data Type | Constraints | Description | +| ------------------------- | ------------ | --------------------------- | ------------------------------------------ | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Master correspondence ID | +| correspondence_number | VARCHAR(100) | NOT NULL | Document number (from numbering system) | +| correspondence_type_id | INT | NOT NULL, FK | Reference to correspondence_types | +| **discipline_id** | **INT** | **NULL, FK** | **[NEW] āļŠāļēāļ‚āļēāļ‡āļēāļ™ (āļ–āđ‰āļēāļĄāļĩ)** | +| is_internal_communication | TINYINT(1) | DEFAULT 0 | Internal (1) or external (0) communication | +| project_id | INT | NOT NULL, FK | Reference to projects table | +| originator_id | INT | NULL, FK | Originating organization | +| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| created_by | INT | NULL, FK | User who created the record | +| deleted_at | DATETIME | NULL | Soft delete timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE RESTRICT +* **FOREIGN KEY (discipline_id) REFERENCES disciplines(id) ON DELETE SET NULL** +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* FOREIGN KEY (originator_id) REFERENCES organizations(id) ON DELETE SET NULL +* FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL +* UNIQUE KEY (project_id, correspondence_number) +* INDEX (correspondence_type_id) +* INDEX (originator_id) +* INDEX (deleted_at) + +**Relationships**: + +* Parent: correspondence_types, **disciplines**, projects, organizations, users +* Children: correspondence_revisions, correspondence_recipients, correspondence_tags, correspondence_references, correspondence_attachments, circulations, transmittals + +--- + +### 3.4 correspondence_revisions (UPDATE v1.5.1) + +**Purpose**: Child table storing revision history of correspondences (1:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------------ | ------------ | --------------------------------- | -------------------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique revision ID | +| correspondence_id | INT | NOT NULL, FK | Master correspondence ID | +| revision_number | INT | NOT NULL | Revision sequence (0, 1, 2...) | +| revision_label | VARCHAR(10) | NULL | Display revision (A, B, 1.1...) | +| is_current | BOOLEAN | DEFAULT FALSE | Current revision flag | +| correspondence_status_id | INT | NOT NULL, FK | Current status of this revision | +| title | VARCHAR(255) | NOT NULL | Document title | +| document_date | DATE | NULL | Document date | +| issued_date | DATETIME | NULL | Issue date | +| received_date | DATETIME | NULL | Received date | +| due_date | DATETIME | NULL | Due date for response | +| description | TEXT | NULL | Revision description | +| details | JSON | NULL | Type-specific details (e.g., RFI questions) | +| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Revision creation timestamp | +| created_by | INT | NULL, FK | User who created revision | +| updated_by | INT | NULL, FK | User who last updated | +| v_ref_project_id | INT | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column āļ”āļķāļ‡ Project ID āļˆāļēāļ JSON details āđ€āļžāļ·āđˆāļ­āļ—āļģ Index | +| v_ref_type | VARCHAR(50) | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column āļ”āļķāļ‡ Type āļˆāļēāļ JSON details | +| v_doc_subtype | VARCHAR(50) | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column āļ”āļķāļ‡ Type āļˆāļēāļ JSON details | +| schema_version | INT | DEFAULT 1 | Version of the schema used with this details | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* FOREIGN KEY (correspondence_status_id) REFERENCES correspondence_status(id) ON DELETE RESTRICT +* FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL +* FOREIGN KEY (updated_by) REFERENCES users(user_id) ON DELETE SET NULL +* UNIQUE KEY (correspondence_id, revision_number) +* UNIQUE KEY (correspondence_id, is_current) +* INDEX (correspondence_status_id) +* INDEX (is_current) +* INDEX (document_date) +* INDEX (issued_date) +* INDEX (v_ref_project_id) +* INDEX (v_ref_type) +* INDEX (v_doc_subtype) + +--- + +### 3.5 correspondence_recipients + +**Purpose**: Junction table for correspondence recipients (TO/CC) (M:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------------- | -------------------- | --------------- | ---------------------------- | +| correspondence_id | INT | PRIMARY KEY, FK | Reference to correspondences | +| recipient_organization_id | INT | PRIMARY KEY, FK | Recipient organization | +| recipient_type | ENUM(' TO ', ' CC ') | PRIMARY KEY | Recipient type | + +**Indexes**: + +* PRIMARY KEY (correspondence_id, recipient_organization_id, recipient_type) +* FOREIGN KEY (correspondence_id) REFERENCES correspondence_revisions(correspondence_id) ON DELETE CASCADE +* FOREIGN KEY (recipient_organization_id) REFERENCES organizations(id) ON DELETE RESTRICT +* INDEX (recipient_organization_id) +* INDEX (recipient_type) + +**Relationships**: + +* Parent: correspondences, organizations + +--- + +### 3.6 tags + +**Purpose**: Master table for document tagging system + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | ----------------------------------- | ------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique tag ID | +| tag_name | VARCHAR(100) | NOT NULL, UNIQUE | Tag name | +| description | TEXT | NULL | Tag description | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (tag_name) +* INDEX (tag_name) - For autocomplete + +**Relationships**: + +* Referenced by: correspondence_tags + +--- + +### 3.7 correspondence_tags + +**Purpose**: Junction table linking correspondences to tags (M:N) + +| Column Name | Data Type | Constraints | Description | +| ----------------- | --------- | --------------- | ---------------------------- | +| correspondence_id | INT | PRIMARY KEY, FK | Reference to correspondences | +| tag_id | INT | PRIMARY KEY, FK | Reference to tags | + +**Indexes**: + +* PRIMARY KEY (correspondence_id, tag_id) +* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE +* INDEX (tag_id) + +**Relationships**: + +* Parent: correspondences, tags + +--- + +### 3.8 correspondence_references + +**Purpose**: Junction table for cross-referencing correspondences (M:N) + +| Column Name | Data Type | Constraints | Description | +| --------------------- | --------- | --------------- | ------------------------------------- | +| src_correspondence_id | INT | PRIMARY KEY, FK | Source correspondence ID | +| tgt_correspondence_id | INT | PRIMARY KEY, FK | Target (referenced) correspondence ID | + +**Indexes**: + +* PRIMARY KEY (src_correspondence_id, tgt_correspondence_id) +* FOREIGN KEY (src_correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* FOREIGN KEY (tgt_correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* INDEX (tgt_correspondence_id) + +**Relationships**: + +* Parent: correspondences (both sides) + +--- + +## **4. 📐 approval: RFA Tables (āđ€āļ­āļāļŠāļēāļĢāļ‚āļ­āļ­āļ™āļļāļĄāļąāļ•āļī, Workflows)** + +### 4.1 rfa_types + +**Purpose**: Master table for RFA (Request for Approval) types + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | --------------------------- | ------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique identifier | +| type_code | VARCHAR(20) | NOT NULL, UNIQUE | Type code (DWG, DOC, MAT, etc.) | +| type_name | VARCHAR(100) | NOT NULL | Full type name | +| description | TEXT | NULL | Type description | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (type_code) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Referenced by: rfas + +--- + +### 4.2 rfa_status_codes + +**Purpose**: Master table for RFA status codes + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | --------------------------- | --------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique identifier | +| status_code | VARCHAR(20) | NOT NULL, UNIQUE | Status code (DFT, FAP, FRE, etc.) | +| status_name | VARCHAR(100) | NOT NULL | Full status name | +| description | TEXT | NULL | Status description | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (status_code) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Referenced by: rfa_revisions + +--- + +### 4.3 rfa_approve_codes + +**Purpose**: Master table for RFA approval result codes + +| Column Name | Data Type | Constraints | Description | +| ------------ | ------------ | --------------------------- | -------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique identifier | +| approve_code | VARCHAR(20) | NOT NULL, UNIQUE | Approval code (1A, 1C, 3R, etc.) | +| approve_name | VARCHAR(100) | NOT NULL | Full approval name | +| description | TEXT | NULL | Code description | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (approve_code) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Referenced by: rfa_revisions + +--- + +### 4.4 rfas (UPDATE v1.5.1) + +**Purpose**: Master table for RFA documents (non-revisioned data) + +| Column Name | Data Type | Constraints | Description | +| ----------------- | --------- | --------------------------- | --------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Master RFA ID | +| rfa_type_id | INT | NOT NULL, FK | Reference to rfa_types | +| **discipline_id** | **INT** | **NULL, FK** | **[NEW] āļŠāļēāļ‚āļēāļ‡āļēāļ™ (āļ–āđ‰āļēāļĄāļĩ)** | +| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| created_by | INT | NULL, FK | User who created the record | +| deleted_at | DATETIME | NULL | Soft delete timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (rfa_type_id) REFERENCES rfa_types(id) +* **FOREIGN KEY (discipline_id) REFERENCES disciplines(id) ON DELETE SET NULL** +* FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL +* INDEX (rfa_type_id) +* INDEX (deleted_at) + +**Relationships**: + +* Parent: rfa_types, **disciplines**, users +* Children: rfa_revisions + +--- + +### 4.5 rfa_revisions (UPDATE v1.5.1) + +**Purpose**: Child table storing revision history of RFAs (1:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------- | ------------ | --------------------------------- | ----------------------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique revision ID | +| correspondence_id | INT | NOT NULL, FK | Link to correspondence (RFA as correspondence) | +| rfa_id | INT | NOT NULL, FK | Master RFA ID | +| revision_number | INT | NOT NULL | Revision sequence (0, 1, 2...) | +| revision_label | VARCHAR(10) | NULL | Display revision (A, B, 1.1...) | +| is_current | BOOLEAN | DEFAULT FALSE | Current revision flag | +| rfa_status_code_id | INT | NOT NULL, FK | Current RFA status | +| rfa_approve_code_id | INT | NULL, FK | Approval result code | +| title | VARCHAR(255) | NOT NULL | RFA title | +| document_date | DATE | NULL | Document date | +| issued_date | DATE | NULL | Issue date for approval | +| received_date | DATETIME | NULL | Received date | +| approved_date | DATE | NULL | Approval date | +| description | TEXT | NULL | Revision description | +| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Revision creation timestamp | +| created_by | INT | NULL, FK | User who created revision | +| updated_by | INT | NULL, FK | User who last updated | +| details | JSON | NULL | Type-specific details (e.g., RFI questions) | +| v_ref_drawing_count | INT | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column āļ”āļķāļ‡ Drawing Count āļˆāļēāļ JSON details āđ€āļžāļ·āđˆāļ­āļ—āļģ Index | +| schema_version | INT | DEFAULT 1 | Version of the schema used with this details | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* FOREIGN KEY (rfa_id) REFERENCES rfas(id) ON DELETE CASCADE +* FOREIGN KEY (rfa_status_code_id) REFERENCES rfa_status_codes(id) +* FOREIGN KEY (rfa_approve_code_id) REFERENCES rfa_approve_codes(id) ON DELETE SET NULL +* FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL +* FOREIGN KEY (updated_by) REFERENCES users(user_id) ON DELETE SET NULL +* UNIQUE KEY (rfa_id, revision_number) +* UNIQUE KEY (rfa_id, is_current) +* INDEX (rfa_status_code_id) +* INDEX (rfa_approve_code_id) +* INDEX (is_current) +* INDEX (v_ref_drawing_count): āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢ Index āļ‚āđ‰āļ­āļĄāļđāļĨāļ•āļąāļ§āđ€āļĨāļ‚āđƒāļ™ JSON + +**Relationships**: + +* Parent: correspondences, rfas, rfa_status_codes, rfa_approve_codes, users +* Children: rfa_items, rfa_workflows + +--- + +### 4.6 rfa_items + +**Purpose**: Junction table linking RFA revisions to shop drawing revisions (M:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------------ | --------- | --------------- | ------------------------------ | +| rfarev_correspondence_id | INT | PRIMARY KEY, FK | RFA revision correspondence ID | +| shop_drawing_revision_id | INT | PRIMARY KEY, FK | Shop drawing revision ID | + +**Indexes**: + +* PRIMARY KEY (rfarev_correspondence_id, shop_drawing_revision_id) +* FOREIGN KEY (rfarev_correspondence_id) REFERENCES rfa_revisions(correspondence_id) ON DELETE CASCADE +* FOREIGN KEY (shop_drawing_revision_id) REFERENCES shop_drawing_revisions(id) ON DELETE CASCADE +* INDEX (shop_drawing_revision_id) + +**Relationships**: + +* Parent: rfa_revisions, shop_drawing_revisions + +**Business Rules**: + +* Used primarily for RFA type = ' DWG ' (Shop Drawing) +* One RFA can contain multiple shop drawings +* One shop drawing can be referenced by multiple RFAs + +--- + +### 4.7 rfa_workflows + +**Purpose**: Transaction log table tracking actual RFA approval workflow execution + +| Column Name | Data Type | Constraints | Description | +| --------------- | --------- | ----------------------------------- | ------------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique workflow log ID | +| rfa_revision_id | INT | NOT NULL, FK | Reference to RFA revision | +| step_number | INT | NOT NULL | Current step number | +| organization_id | INT | NOT NULL, FK | Organization responsible | +| assigned_to | INT | NULL, FK | Assigned user ID | +| action_type | ENUM | NULL | Action type: REVIEW, APPROVE, ACKNOWLEDGE | +| status | ENUM | NULL | Status: PENDING, IN_PROGRESS, COMPLETED, REJECTED | +| comments | TEXT | NULL | Comments/remarks | +| completed_at | DATETIME | NULL | Completion timestamp | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | +| state_context | JSON\* | NULL | āđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨ Context āļ‚āļ­āļ‡ Workflow āļ“ āļ‚āļ“āļ°āļ™āļąāđ‰āļ™ (Snapshot) | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (rfa_revision_id) REFERENCES rfa_revisions(id) ON DELETE CASCADE +* FOREIGN KEY (organization_id) REFERENCES organizations(id) +* FOREIGN KEY (assigned_to) REFERENCES users(user_id) +* INDEX (rfa_revision_id, step_number) +* INDEX (assigned_to, status) +* INDEX (status) + +**Relationships**: + +* Parent: rfa_revisions, organizations, users + +**Business Rules**: + +* Records actual workflow execution history +* Tracks who did what and when +* Multiple records per RFA revision (one per step) +* Status changes tracked via updated_at + +--- + +## **5. 📐 Drawings Tables (āđāļšāļš, āļŦāļĄāļ§āļ”āļŦāļĄāļđāđˆ)** + +### 5.1 contract_drawing_volumes + +**Purpose**: Master table for contract drawing volume classification + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | ----------------------------------- | ------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique volume ID | +| project_id | INT | NOT NULL, FK | Reference to projects | +| volume_code | VARCHAR(50) | NOT NULL | Volume code | +| volume_name | VARCHAR(255) | NOT NULL | Volume name | +| description | TEXT | NULL | Volume description | +| sort_order | INT | DEFAULT 0 | Display order | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* UNIQUE KEY (project_id, volume_code) +* INDEX (sort_order) + +**Relationships**: + +* Parent: projects +* Referenced by: contract_drawings + +**Business Rules**: + +* Volume codes must be unique within a project +* Used for organizing large sets of contract drawings + +--- + +### 5.2 contract_drawing_cats + +**Purpose**: Master table for contract drawing main categories + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | ----------------------------------- | ------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique category ID | +| project_id | INT | NOT NULL, FK | Reference to projects | +| cat_code | VARCHAR(50) | NOT NULL | Category code | +| cat_name | VARCHAR(255) | NOT NULL | Category name | +| description | TEXT | NULL | Category description | +| sort_order | INT | DEFAULT 0 | Display order | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* UNIQUE KEY (project_id, cat_code) +* INDEX (sort_order) + +**Relationships**: + +* Parent: projects +* Referenced by: contract_drawing_subcat_cat_maps + +**Business Rules**: + +* Category codes must be unique within a project +* Hierarchical relationship with sub-categories via mapping table + +--- + +### 5.3 contract_drawing_sub_cats + +**Purpose**: Master table for contract drawing sub-categories + +| Column Name | Data Type | Constraints | Description | +| ------------ | ------------ | ----------------------------------- | ------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique sub-category ID | +| project_id | INT | NOT NULL, FK | Reference to projects | +| sub_cat_code | VARCHAR(50) | NOT NULL | Sub-category code | +| sub_cat_name | VARCHAR(255) | NOT NULL | Sub-category name | +| description | TEXT | NULL | Sub-category description | +| sort_order | INT | DEFAULT 0 | Display order | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* UNIQUE KEY (project_id, sub_cat_code) +* INDEX (sort_order) + +**Relationships**: + +* Parent: projects +* Referenced by: contract_drawings, contract_drawing_subcat_cat_maps + +**Business Rules**: + +* Sub-category codes must be unique within a project +* Can be mapped to multiple main categories via mapping table + +--- + +### 5.4 contract_drawing_subcat_cat_maps + +**Purpose**: Junction table mapping sub-categories to main categories (M:N) + +| Column Name | Data Type | Constraints | Description | +| ----------- | --------- | --------------- | -------------------------- | +| project_id | INT | PRIMARY KEY, FK | Reference to projects | +| sub_cat_id | INT | PRIMARY KEY, FK | Reference to sub-category | +| cat_id | INT | PRIMARY KEY, FK | Reference to main category | + +**Indexes**: + +* PRIMARY KEY (project_id, sub_cat_id, cat_id) +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* FOREIGN KEY (sub_cat_id) REFERENCES contract_drawing_sub_cats(id) ON DELETE CASCADE +* FOREIGN KEY (cat_id) REFERENCES contract_drawing_cats(id) ON DELETE CASCADE +* INDEX (sub_cat_id) +* INDEX (cat_id) + +**Relationships**: + +* Parent: projects, contract_drawing_sub_cats, contract_drawing_cats + +**Business Rules**: + +* Allows flexible categorization +* One sub-category can belong to multiple main categories +* All three fields required for uniqueness + +--- + +### 5.5 contract_drawings + +**Purpose**: Master table for contract drawings (from contract specifications) + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | ----------------------------------- | ------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique drawing ID | +| project_id | INT | NOT NULL, FK | Reference to projects | +| condwg_no | VARCHAR(255) | NOT NULL | Contract drawing number | +| title | VARCHAR(255) | NOT NULL | Drawing title | +| sub_cat_id | INT | NULL, FK | Reference to sub-category | +| volume_id | INT | NULL, FK | Reference to volume | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | +| deleted_at | DATETIME | NULL | Soft delete timestamp | +| updated_by | INT | NULL, FK | User who last updated | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* FOREIGN KEY (sub_cat_id) REFERENCES contract_drawing_sub_cats(id) ON DELETE RESTRICT +* FOREIGN KEY (volume_id) REFERENCES contract_drawing_volumes(id) ON DELETE RESTRICT +* FOREIGN KEY (updated_by) REFERENCES users(user_id) +* UNIQUE KEY (project_id, condwg_no) +* INDEX (sub_cat_id) +* INDEX (volume_id) +* INDEX (deleted_at) + +**Relationships**: + +* Parent: projects, contract_drawing_sub_cats, contract_drawing_volumes, users +* Referenced by: shop_drawing_revision_contract_refs, contract_drawing_attachments + +**Business Rules**: + +* Drawing numbers must be unique within a project +* Represents baseline/contract drawings +* Referenced by shop drawings for compliance tracking +* Soft delete preserves history + +--- + +### 5.6 shop_drawing_main_categories + +**Purpose**: Master table for shop drawing main categories (discipline-level) + +| Column Name | Data Type | Constraints | Description | +| ------------------ | ------------ | ----------------------------------- | ------------------------------------ | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique category ID | +| main_category_code | VARCHAR(50) | NOT NULL, UNIQUE | Category code (ARCH, STR, MEP, etc.) | +| main_category_name | VARCHAR(255) | NOT NULL | Category name | +| description | TEXT | NULL | Category description | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (main_category_code) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Referenced by: shop_drawing_sub_categories, shop_drawings + +**Business Rules**: + +* Global categories (not project-specific) +* Typically represents engineering disciplines + +--- + +### 5.7 shop_drawing_sub_categories + +**Purpose**: Master table for shop drawing sub-categories (component-level) + +| Column Name | Data Type | Constraints | Description | +| ----------------- | ------------ | ----------------------------------- | ----------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique sub-category ID | +| sub_category_code | VARCHAR(50) | NOT NULL, UNIQUE | Sub-category code (STR-COLUMN, ARCH-DOOR, etc.) | +| sub_category_name | VARCHAR(255) | NOT NULL | Sub-category name | +| main_category_id | INT | NOT NULL, FK | Reference to main category | +| description | TEXT | NULL | Sub-category description | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (sub_category_code) +* FOREIGN KEY (main_category_id) REFERENCES shop_drawing_main_categories(id) +* INDEX (main_category_id) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Parent: shop_drawing_main_categories +* Referenced by: shop_drawings + +**Business Rules**: + +* Global sub-categories (not project-specific) +* Hierarchical under main categories +* Represents specific drawing types or components + +--- + +### 5.8 shop_drawings + +**Purpose**: Master table for shop drawings (contractor-submitted) + +| Column Name | Data Type | Constraints | Description | +| ---------------- | ------------ | ----------------------------------- | -------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique drawing ID | +| project_id | INT | NOT NULL, FK | Reference to projects | +| drawing_number | VARCHAR(100) | NOT NULL, UNIQUE | Shop drawing number | +| title | VARCHAR(500) | NOT NULL | Drawing title | +| main_category_id | INT | NOT NULL, FK | Reference to main category | +| sub_category_id | INT | NOT NULL, FK | Reference to sub-category | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | +| deleted_at | DATETIME | NULL | Soft delete timestamp | +| updated_by | INT | NULL, FK | User who last updated | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (drawing_number) +* FOREIGN KEY (project_id) REFERENCES projects(id) +* FOREIGN KEY (main_category_id) REFERENCES shop_drawing_main_categories(id) +* FOREIGN KEY (sub_category_id) REFERENCES shop_drawing_sub_categories(id) +* FOREIGN KEY (updated_by) REFERENCES users(user_id) +* INDEX (project_id) +* INDEX (main_category_id) +* INDEX (sub_category_id) +* INDEX (deleted_at) + +**Relationships**: + +* Parent: projects, shop_drawing_main_categories, shop_drawing_sub_categories, users +* Children: shop_drawing_revisions + +**Business Rules**: + +* Drawing numbers are globally unique across all projects +* Represents contractor shop drawings +* Can have multiple revisions +* Soft delete preserves history + +--- + +### 5.9 shop_drawing_revisions + +**Purpose**: Child table storing revision history of shop drawings (1:N) + +| Column Name | Data Type | Constraints | Description | +| --------------- | ----------- | --------------------------- | ------------------------------ | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique revision ID | +| shop_drawing_id | INT | NOT NULL, FK | Master shop drawing ID | +| revision_number | INT | NOT NULL | Revision sequence (0, 1, 2...) | +| revision_label | VARCHAR(10) | NULL | Display revision (A, B, C...) | +| revision_date | DATE | NULL | Revision date | +| description | TEXT | NULL | Revision description/changes | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Revision creation timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (shop_drawing_id) REFERENCES shop_drawings(id) ON DELETE CASCADE +* UNIQUE KEY (shop_drawing_id, revision_number) +* INDEX (revision_date) + +**Relationships**: + +* Parent: shop_drawings +* Referenced by: rfa_items, shop_drawing_revision_contract_refs, shop_drawing_revision_attachments + +**Business Rules**: + +* Revision numbers are sequential starting from 0 +* Each revision can reference multiple contract drawings +* Each revision can have multiple file attachments +* Linked to RFAs for approval tracking + +--- + +### 5.10 shop_drawing_revision_contract_refs + +**Purpose**: Junction table linking shop drawing revisions to referenced contract drawings (M:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------------ | --------- | --------------- | ---------------------------------- | +| shop_drawing_revision_id | INT | PRIMARY KEY, FK | Reference to shop drawing revision | +| contract_drawing_id | INT | PRIMARY KEY, FK | Reference to contract drawing | + +**Indexes**: + +* PRIMARY KEY (shop_drawing_revision_id, contract_drawing_id) +* FOREIGN KEY (shop_drawing_revision_id) REFERENCES shop_drawing_revisions(id) ON DELETE CASCADE +* FOREIGN KEY (contract_drawing_id) REFERENCES contract_drawings(id) ON DELETE CASCADE +* INDEX (contract_drawing_id) + +**Relationships**: + +* Parent: shop_drawing_revisions, contract_drawings + +**Business Rules**: + +* Tracks which contract drawings each shop drawing revision is based on +* Ensures compliance with contract specifications +* One shop drawing revision can reference multiple contract drawings + +--- + +## **6. 🔄 Circulations Tables (āđƒāļšāđ€āļ§āļĩāļĒāļ™āļ āļēāļĒāđƒāļ™)** + +### 6.1 circulation_status_codes + +**Purpose**: Master table for circulation workflow status codes + +| Column Name | Data Type | Constraints | Description | +| ----------- | ----------- | --------------------------- | --------------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique status ID | +| code | VARCHAR(20) | NOT NULL, UNIQUE | Status code (OPEN, IN_REVIEW, COMPLETED, CANCELLED) | +| description | VARCHAR(50) | NOT NULL | Status description | +| sort_order | INT | DEFAULT 0 | Display order | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (code) +* INDEX (is_active) +* INDEX (sort_order) + +**Relationships**: + +* Referenced by: circulations + +**Seed Data**: 4 status codes + +* OPEN: Initial status when created +* IN_REVIEW: Under review by recipients +* COMPLETED: All recipients have responded +* CANCELLED: Withdrawn/cancelled + +--- + +### 6.2 circulations + +**Purpose**: Master table for internal circulation sheets (document routing) + +| Column Name | Data Type | Constraints | Description | +| ----------------------- | ------------ | ----------------------------------- | ----------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique circulation ID | +| correspondence_id | INT | UNIQUE, FK | Link to correspondence (1:1 relationship) | +| organization_id | INT | NOT NULL, FK | Organization that owns this circulation | +| circulation_no | VARCHAR(100) | NOT NULL | Circulation sheet number | +| circulation_subject | VARCHAR(500) | NOT NULL | Subject/title | +| circulation_status_code | VARCHAR(20) | NOT NULL, FK | Current status code | +| created_by_user_id | INT | NOT NULL, FK | User who created circulation | +| submitted_at | TIMESTAMP | NULL | Submission timestamp | +| closed_at | TIMESTAMP | NULL | Closure timestamp | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp | +| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp | + +**Indexes**: + +* PRIMARY KEY (id) +* UNIQUE (correspondence_id) +* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) +* FOREIGN KEY (organization_id) REFERENCES organizations(id) +* FOREIGN KEY (circulation_status_code) REFERENCES circulation_status_codes(code) +* FOREIGN KEY (created_by_user_id) REFERENCES users(user_id) +* INDEX (organization_id) +* INDEX (circulation_status_code) +* INDEX (created_by_user_id) + +**Relationships**: + +* Parent: correspondences, organizations, circulation_status_codes, users +* Children: circulation_routings, circulation_attachments + +**Business Rules**: + +* Internal document routing within organization +* One-to-one relationship with correspondences +* Tracks document review/approval workflow +* Status progression: OPEN → IN_REVIEW → COMPLETED/CANCELLED + +--- + +## **7. ðŸ“Ī Transmittals Tables (āđ€āļ­āļāļŠāļēāļĢāļ™āļģāļŠāđˆāļ‡)** + +### 7.1 transmittals + +**Purpose**: Child table for transmittal-specific data (1:1 with correspondences) + +| Column Name | Data Type | Constraints | Description | +| ----------------- | --------- | --------------- | --------------------------------------------------------- | +| correspondence_id | INT | PRIMARY KEY, FK | Reference to correspondences (1:1) | +| purpose | ENUM | NULL | Purpose: FOR_APPROVAL, FOR_INFORMATION, FOR_REVIEW, OTHER | +| remarks | TEXT | NULL | Additional remarks | + +**Indexes**: + +* PRIMARY KEY (correspondence_id) +* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* INDEX (purpose) + +**Relationships**: + +* Parent: correspondences +* Children: transmittal_items + +**Business Rules**: + +* One-to-one relationship with correspondences +* Transmittal is a correspondence type for forwarding documents +* Contains metadata about the transmission + +--- + +### 7.2 transmittal_items + +**Purpose**: Junction table listing documents included in transmittal (M:N) + +| Column Name | Data Type | Constraints | Description | +| ---------------------- | ------------ | --------------------------- | --------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique item ID | +| transmittal_id | INT | NOT NULL, FK | Reference to transmittal | +| item_correspondence_id | INT | NOT NULL, FK | Reference to document being transmitted | +| quantity | INT | DEFAULT 1 | Number of copies | +| remarks | VARCHAR(255) | NULL | Item-specific remarks | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (transmittal_id) REFERENCES transmittals(correspondence_id) ON DELETE CASCADE +* FOREIGN KEY (item_correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* UNIQUE KEY (transmittal_id, item_correspondence_id) +* INDEX (item_correspondence_id) + +**Relationships**: + +* Parent: transmittals, correspondences + +**Business Rules**: + +* One transmittal can contain multiple documents +* Tracks quantity of physical copies (if applicable) +* Links to any type of correspondence document + +--- + +## **8. 📎 File Management Tables (āđ„āļŸāļĨāđŒāđāļ™āļš)** + +### 8.1 attachments + +**Purpose**: Central repository for all file attachments in the system + +| Column Name | Data Type | Constraints | Description | +| ------------------- | ------------ | --------------------------- | -------------------------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique attachment ID | +| original_filename | VARCHAR(255) | NOT NULL | Original filename from upload | +| stored_filename | VARCHAR(255) | NOT NULL | System-generated unique filename | +| file_path | VARCHAR(500) | NOT NULL | Full file path on server (/share/dms-data/) | +| mime_type | VARCHAR(100) | NOT NULL | MIME type (application/pdf, image/jpeg, etc.) | +| file_size | INT | NOT NULL | File size in bytes | +| uploaded_by_user_id | INT | NOT NULL, FK | User who uploaded file | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Upload timestamp | +| is_temporary | BOOLEAN | DEFAULT TRUE | āļĢāļ°āļšāļļāļ§āđˆāļēāđ€āļ›āđ‡āļ™āđ„āļŸāļĨāđŒāļŠāļąāđˆāļ§āļ„āļĢāļēāļ§ (āļĒāļąāļ‡āđ„āļĄāđˆāđ„āļ”āđ‰ Commit) | +| temp_id\* | VARCHAR(100) | NULL | ID āļŠāļąāđˆāļ§āļ„āļĢāļēāļ§āļŠāļģāļŦāļĢāļąāļšāļ­āđ‰āļēāļ‡āļ­āļīāļ‡āļ•āļ­āļ™ Upload Phase 1 (āļ­āļēāļˆāđƒāļŠāđ‰āļĢāđˆāļ§āļĄāļāļąāļš id āļŦāļĢāļ·āļ­āđāļĒāļāļāđ‡āđ„āļ”āđ‰) | +| expires_at | DATETIME | NULL | āđ€āļ§āļĨāļēāļŦāļĄāļ”āļ­āļēāļĒāļļāļ‚āļ­āļ‡āđ„āļŸāļĨāđŒ Temp (āđ€āļžāļ·āđˆāļ­āđƒāļŦāđ‰ Cron Job āļĨāļšāļ­āļ­āļ) | +| checksum | VARCHAR(64) | NULL | SHA-256 Checksum āļŠāļģāļŦāļĢāļąāļš Verify File Integrity [Req 3.9.3] | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (uploaded_by_user_id) REFERENCES users(user_id) ON DELETE CASCADE +* INDEX (stored_filename) +* INDEX (mime_type) +* INDEX (uploaded_by_user_id) +* INDEX (created_at) + +**Relationships**: + +* Parent: users +* Referenced by: correspondence_attachments, circulation_attachments, shop_drawing_revision_attachments, contract_drawing_attachments + +**Business Rules**: + +* Central storage prevents file duplication +* Stored filename prevents naming conflicts +* File path points to QNAP NAS storage +* Original filename preserved for download +* One file record can be linked to multiple documents + +--- + +### 8.2 correspondence_attachments + +**Purpose**: Junction table linking correspondences to file attachments (M:N) + +| Column Name | Data Type | Constraints | Description | +| ----------------- | --------- | --------------- | ---------------------------- | +| correspondence_id | INT | PRIMARY KEY, FK | Reference to correspondences | +| attachment_id | INT | PRIMARY KEY, FK | Reference to attachments | +| is_main_document | BOOLEAN | DEFAULT FALSE | Main/primary document flag | + +**Indexes**: + +* PRIMARY KEY (correspondence_id, attachment_id) +* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE +* FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON DELETE CASCADE +* INDEX (attachment_id) +* INDEX (is_main_document) + +**Relationships**: + +* Parent: correspondences, attachments + +**Business Rules**: + +* One correspondence can have multiple attachments +* One attachment can be linked to multiple correspondences +* is_main_document identifies primary file (typically PDF) + +--- + +### 8.3 circulation_attachments + +**Purpose**: Junction table linking circulations to file attachments (M:N) + +| Column Name | Data Type | Constraints | Description | +| ---------------- | --------- | --------------- | -------------------------- | +| circulation_id | INT | PRIMARY KEY, FK | Reference to circulations | +| attachment_id | INT | PRIMARY KEY, FK | Reference to attachments | +| is_main_document | BOOLEAN | DEFAULT FALSE | Main/primary document flag | + +**Indexes**: + +* PRIMARY KEY (circulation_id, attachment_id) +* FOREIGN KEY (circulation_id) REFERENCES circulations(id) ON DELETE CASCADE +* FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON DELETE CASCADE +* INDEX (attachment_id) +* INDEX (is_main_document) + +**Relationships**: + +* Parent: circulations, attachments + +--- + +### 8.4 shop_drawing_revision_attachments + +**Purpose**: Junction table linking shop drawing revisions to file attachments (M:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------------ | --------- | --------------- | ---------------------------------- | +| shop_drawing_revision_id | INT | PRIMARY KEY, FK | Reference to shop drawing revision | +| attachment_id | INT | PRIMARY KEY, FK | Reference to attachments | +| file_type | ENUM | NULL | File type: PDF, DWG, SOURCE, OTHER | +| is_main_document | BOOLEAN | DEFAULT FALSE | Main/primary document flag | + +**Indexes**: + +* PRIMARY KEY (shop_drawing_revision_id, attachment_id) +* FOREIGN KEY (shop_drawing_revision_id) REFERENCES shop_drawing_revisions(id) ON DELETE CASCADE +* FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON DELETE CASCADE +* INDEX (attachment_id) +* INDEX (file_type) +* INDEX (is_main_document) + +**Relationships**: + +* Parent: shop_drawing_revisions, attachments + +**Business Rules**: + +* file_type categorizes drawing file formats +* Typically includes PDF for viewing and DWG for editing +* SOURCE may include native CAD files + +--- + +### 8.5 contract_drawing_attachments + +**Purpose**: Junction table linking contract drawings to file attachments (M:N) + +| Column Name | Data Type | Constraints | Description | +| ------------------- | --------- | --------------- | ---------------------------------- | +| contract_drawing_id | INT | PRIMARY KEY, FK | Reference to contract drawing | +| attachment_id | INT | PRIMARY KEY, FK | Reference to attachments | +| file_type | ENUM | NULL | File type: PDF, DWG, SOURCE, OTHER | +| is_main_document | BOOLEAN | DEFAULT FALSE | Main/primary document flag | + +**Indexes**: + +* PRIMARY KEY (contract_drawing_id, attachment_id) +* FOREIGN KEY (contract_drawing_id) REFERENCES contract_drawings(id) ON DELETE CASCADE +* FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON DELETE CASCADE +* INDEX (attachment_id) +* INDEX (file_type) +* INDEX (is_main_document) + +**Relationships**: + +* Parent: contract_drawings, attachments + +--- + +## **9. ðŸ”Ē Document Numbering System Tables (āļĢāļ°āļšāļšāđ€āļĨāļ‚āļ—āļĩāđˆāđ€āļ­āļāļŠāļēāļĢ)** + +### 9.1 document_number_formats + +**Purpose**: Master table defining numbering formats for each document type + +| Column Name | Data Type | Constraints | Description | +| ---------------------- | ------------ | --------------------------- | -------------------------------------------- | +| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique format ID | +| project_id | INT | NOT NULL, FK | Reference to projects | +| correspondence_type_id | INT | NOT NULL, FK | Reference to correspondence_types | +| format_string | VARCHAR(100) | NOT NULL | Format pattern (e.g., {ORG}-{TYPE}-{YYYY}-#) | +| description | TEXT | NULL | Format description | +| is_active | TINYINT(1) | DEFAULT 1 | Active status | + +**Indexes**: + +* PRIMARY KEY (id) +* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE +* FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE +* UNIQUE KEY (project_id, correspondence_type_id) +* INDEX (is_active) + +**Relationships**: + +* Parent: projects, correspondence_types + +**Business Rules**: + +* Defines how document numbers are constructed +* Supports placeholders: {PROJ}, {ORG}, {TYPE}, {YYYY}, {MM}, {#} + +--- + +### 9.2 document_number_counters (UPDATE v1.5.1) + +**Purpose**: Transaction table tracking running numbers (High Concurrency) + +| Column Name | Data Type | Constraints | Description | +| -------------------------- | --------- | ------------- | -------------------------------------------- | +| project_id | INT | PK, NOT NULL | āđ‚āļ„āļĢāļ‡āļāļēāļĢ | +| originator_organization_id | INT | PK, NOT NULL | āļ­āļ‡āļ„āđŒāļāļĢāļœāļđāđ‰āļŠāđˆāļ‡ | +| recipient_organization_id | INT | PK, NOT NULL | [NEW] āļ­āļ‡āļ„āđŒāļāļĢāļœāļđāđ‰āļĢāļąāļš (-1 = āļ—āļļāļāļ­āļ‡āļ„āđŒāļāļĢ) | +| correspondence_type_id | INT | PK, NOT NULL | āļ›āļĢāļ°āđ€āļ āļ—āđ€āļ­āļāļŠāļēāļĢ | +| sub_type_id | INT | PK, DEFAULT 0 | [NEW] āļ›āļĢāļ°āđ€āļ āļ—āļĒāđˆāļ­āļĒ āļŠāļģāļŦāļĢāļąāļš TRANSMITTAL (0 = āđ„āļĄāđˆāļĢāļ°āļšāļļ) | +| rfa_type_id | INT | PK, DEFAULT 0 | [NEW] āļ›āļĢāļ°āđ€āļ āļ— RFA (0 = āđ„āļĄāđˆāđƒāļŠāđˆ RFA) | +| discipline_id | INT | PK, DEFAULT 0 | [NEW] āļŠāļēāļ‚āļēāļ‡āļēāļ™ (0 = āđ„āļĄāđˆāļĢāļ°āļšāļļ) | +| current_year | INT | PK, NOT NULL | āļ›āļĩ āļ„.āļĻ. āļ‚āļ­āļ‡āļ•āļąāļ§āļ™āļąāļš (auto-reset āļ—āļļāļāļ›āļĩ) | +| last_number | INT | DEFAULT 0 | āđ€āļĨāļ‚āļĨāđˆāļēāļŠāļļāļ”āļ—āļĩāđˆāļ–āļđāļāđƒāļŠāđ‰āļ‡āļēāļ™āđ„āļ›āđāļĨāđ‰āļ§ | +| updated_at | TIMESTAMP | ON UPDATE | āđ€āļ§āļĨāļēāļ—āļĩāđˆāļ­āļąāļ›āđ€āļ”āļ•āļĨāđˆāļēāļŠāļļāļ” | + +**Indexes**: + +* **PRIMARY KEY (project_id, originator_organization_id, recipient_organization_id, correspondence_type_id, sub_type_id, rfa_type_id, discipline_id, current_year)** + +**Business Rules**: + +* **Composite Primary Key 8 Columns**: āđ€āļžāļ·āđˆāļ­āļĢāļ­āļ‡āļĢāļąāļšāļāļēāļĢāļĢāļąāļ™āđ€āļĨāļ‚āļ—āļĩāđˆāļ‹āļąāļšāļ‹āđ‰āļ­āļ™āļ•āļēāļĄ Req 6B +* **Concurrency Control**: āđƒāļŠāđ‰ Redis Lock āļŦāļĢāļ·āļ­ Optimistic Locking āđƒāļ™āļāļēāļĢāļ­āļąāļ›āđ€āļ”āļ• `last_number` +* **Reset Rule**: `current_year` āđ€āļ›āļĨāļĩāđˆāļĒāļ™ -> āđ€āļĢāļīāđˆāļĄāļ™āļąāļš 1 āđƒāļŦāļĄāđˆ + +--- + +### 9.3 document_number_audit (NEW v1.5.1) + +**Purpose**: Audit log for document number generation (Debugging & Tracking) + +| Column Name | Data Type | Constraints | Description | +| :---------------- | :----------- | :---------- | :---------------------------------- | +| id | BIGINT | PK, AI | Unique ID | +| transaction_id | VARCHAR(36) | NOT NULL | UUID āļ‚āļ­āļ‡ Transaction āļāļēāļĢāļ‚āļ­āđ€āļĨāļ‚ | +| counter_key_json | JSON | NOT NULL | āļ„āđˆāļē Key āļ—āļĩāđˆāđƒāļŠāđ‰āđƒāļ™āļāļēāļĢ Query (āđ€āļāđ‡āļšāđ€āļ›āđ‡āļ™ JSON) | +| generated_number | VARCHAR(100) | NOT NULL | āđ€āļĨāļ‚āļ—āļĩāđˆāđ„āļ”āđ‰ | +| requested_by | INT | FK | User āļ—āļĩāđˆāļ‚āļ­āđ€āļĨāļ‚ | +| requested_at | TIMESTAMP | DEFAULT NOW | āđ€āļ§āļĨāļēāļ—āļĩāđˆāļ‚āļ­ | +| execution_time_ms | INT | NULL | āđ€āļ§āļĨāļēāļ—āļĩāđˆāđƒāļŠāđ‰āđƒāļ™āļāļēāļĢāļ›āļĢāļ°āļĄāļ§āļĨāļœāļĨ (ms) | + +--- + +### 9.4 document_number_errors (NEW v1.5.1) + +**Purpose**: Error log for failed document number generation + +| Column Name | Data Type | Constraints | Description | +| :--------------- | :---------- | :---------- | :------------------------------- | +| id | BIGINT | PK, AI | Unique ID | +| transaction_id | VARCHAR(36) | NOT NULL | UUID āļ‚āļ­āļ‡ Transaction | +| error_code | VARCHAR(50) | NOT NULL | āļĢāļŦāļąāļŠ Error (āđ€āļŠāđˆāļ™ ERR_LOCK_TIMEOUT) | +| error_message | TEXT | NOT NULL | āļĢāļēāļĒāļĨāļ°āđ€āļ­āļĩāļĒāļ” Error | +| counter_key_json | JSON | NULL | āļ„āđˆāļē Key āļ—āļĩāđˆāļžāļĒāļēāļĒāļēāļĄāđƒāļŠāđ‰ | +| occurred_at | TIMESTAMP | DEFAULT NOW | āđ€āļ§āļĨāļēāļ—āļĩāđˆāđ€āļāļīāļ” Error | + +--- + +## **10. ⚙ïļ Unified Workflow Engine Tables (NEW v1.5.1)** + +### 10.1 workflow_definitions + +**Purpose**: āđ€āļāđ‡āļšāđāļĄāđˆāđāļšāļš (Template) āļ‚āļ­āļ‡ Workflow (Req 3.6) + +| Column Name | Data Type | Constraints | Description | +| :------------ | :----------- | :----------- | :--------------------------------------------- | +| id | INT | PK, AI | Unique ID | +| workflow_code | VARCHAR(50) | UNIQUE | āļĢāļŦāļąāļŠ Workflow (āđ€āļŠāđˆāļ™ WF-RFA-GENERIC) | +| workflow_name | VARCHAR(255) | NOT NULL | āļŠāļ·āđˆāļ­ Workflow | +| description | TEXT | NULL | āļ„āļģāļ­āļ˜āļīāļšāļēāļĒ | +| module | VARCHAR(50) | NOT NULL | āđƒāļŠāđ‰āļāļąāļš Module āđ„āļŦāļ™ (RFA, CORRESPONDENCE) | +| steps_config | JSON | NOT NULL | āļāļēāļĢāļ•āļąāđ‰āļ‡āļ„āđˆāļē Step (Sequence, Approvers, Conditions) | +| is_active | BOOLEAN | DEFAULT TRUE | āļŠāļ–āļēāļ™āļ°āļāļēāļĢāđƒāļŠāđ‰āļ‡āļēāļ™ | +| version | INT | DEFAULT 1 | āđ€āļ§āļ­āļĢāđŒāļŠāļąāļ™āļ‚āļ­āļ‡ Definition | + +**Business Rules**: +* `steps_config` āđ€āļāđ‡āļš Logic āļ‚āļ­āļ‡ Workflow āļ—āļąāđ‰āļ‡āļŦāļĄāļ”āđƒāļ™āļĢāļđāļ›āđāļšāļš JSON āđ€āļžāļ·āđˆāļ­āļ„āļ§āļēāļĄāļĒāļ·āļ”āļŦāļĒāļļāđˆāļ™ + +--- + +### 10.2 workflow_instances + +**Purpose**: āđ€āļāđ‡āļšāļŠāļ–āļēāļ™āļ°āļ‚āļ­āļ‡ Workflow āļ—āļĩāđˆāļāļģāļĨāļąāļ‡āļĢāļąāļ™āļ­āļĒāļđāđˆāļˆāļĢāļīāļ‡ (Runtime) + +| Column Name | Data Type | Constraints | Description | +| :--------------------- | :----------- | :----------- | :----------------------------------------- | +| id | BIGINT | PK, AI | Unique ID | +| workflow_definition_id | INT | FK, NOT NULL | āļ­āđ‰āļēāļ‡āļ­āļīāļ‡ Definition | +| business_key | VARCHAR(100) | INDEX | ID āļ‚āļ­āļ‡āđ€āļ­āļāļŠāļēāļĢāļ—āļĩāđˆāļœāļđāļāļāļąāļš Workflow āļ™āļĩāđ‰ (āđ€āļŠāđˆāļ™ RFA-001) | +| current_step_name | VARCHAR(100) | NOT NULL | āļŠāļ·āđˆāļ­ Step āļ›āļąāļˆāļˆāļļāļšāļąāļ™ | +| status | ENUM | NOT NULL | IN_PROGRESS, COMPLETED, TERMINATED | +| context_data | JSON | NULL | āļ‚āđ‰āļ­āļĄāļđāļĨāļ›āļĢāļ°āļāļ­āļšāļāļēāļĢāļ•āļąāļ”āļŠāļīāļ™āđƒāļˆ (Variables) | +| started_at | TIMESTAMP | DEFAULT NOW | āđ€āļ§āļĨāļēāļ—āļĩāđˆāđ€āļĢāļīāđˆāļĄ | +| completed_at | TIMESTAMP | NULL | āđ€āļ§āļĨāļēāļ—āļĩāđˆāļˆāļš | + +--- + +### 10.3 workflow_histories + +**Purpose**: āđ€āļāđ‡āļšāļ›āļĢāļ°āļ§āļąāļ•āļīāļāļēāļĢāļ”āļģāđ€āļ™āļīāļ™āļāļēāļĢāđƒāļ™āđāļ•āđˆāļĨāļ° Step (Audit Trail) + +| Column Name | Data Type | Constraints | Description | +| :------------------- | :----------- | :----------- | :--------------------------------- | +| id | BIGINT | PK, AI | Unique ID | +| workflow_instance_id | BIGINT | FK, NOT NULL | āļ­āđ‰āļēāļ‡āļ­āļīāļ‡ Instance | +| step_name | VARCHAR(100) | NOT NULL | āļŠāļ·āđˆāļ­ Step | +| action | VARCHAR(50) | NOT NULL | āļāļēāļĢāļāļĢāļ°āļ—āļģ (APPROVE, REJECT, COMMENT) | +| actor_id | INT | FK, NULL | User āļ—āļĩāđˆāļāļĢāļ°āļ—āļģ | +| comments | TEXT | NULL | āļ„āļ§āļēāļĄāđ€āļŦāđ‡āļ™āđ€āļžāļīāđˆāļĄāđ€āļ•āļīāļĄ | +| performed_at | TIMESTAMP | DEFAULT NOW | āđ€āļ§āļĨāļēāļ—āļĩāđˆāļāļĢāļ°āļ—āļģ | + +--- + +## **11. ðŸ–Ĩïļ System & Logs Tables (āļĢāļ°āļšāļš, āļšāļąāļ™āļ—āļķāļ)** + +### 11.1 json_schemas (NEW v1.5.1) + +**Purpose**: āđ€āļāđ‡āļš Schema āļŠāļģāļŦāļĢāļąāļš Validate JSON Columns (Req 3.12) + +| Column Name | Data Type | Constraints | Description | +| :---------- | :---------- | :----------- | :------------------------------------- | +| id | INT | PK, AI | Unique ID | +| schema_code | VARCHAR(50) | UNIQUE | āļĢāļŦāļąāļŠ Schema (āđ€āļŠāđˆāļ™ RFA_DETAILS_V1) | +| schema_body | JSON | NOT NULL | JSON Schema Draft 7/2020-12 definition | +| description | TEXT | NULL | āļ„āļģāļ­āļ˜āļīāļšāļēāļĒ | +| is_active | BOOLEAN | DEFAULT TRUE | āļŠāļ–āļēāļ™āļ° | + +--- + +### 11.2 audit_logs (UPDATE v1.5.1) + +**Purpose**: Centralized audit logging for all system actions + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | --------------------------- | ----------------------------------------- | +| id | BIGINT | PRIMARY KEY, AUTO_INCREMENT | Unique log ID | +| user_id | INT | NULL, FK | User who performed action | +| action | VARCHAR(50) | NOT NULL | Action name (CREATE, UPDATE, DELETE, etc) | +| module | VARCHAR(50) | NOT NULL | Module name (USERS, RFA, etc) | +| entity_id | VARCHAR(50) | NULL | ID of affected entity | +| old_values | JSON | NULL | Data before change | +| new_values | JSON | NULL | Data after change | +| ip_address | VARCHAR(45) | NULL | User IP address | +| user_agent | VARCHAR(255) | NULL | User browser/client info | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Log timestamp | + +**Indexes**: + +* PRIMARY KEY (id, created_at) -- **Partition Key** +* INDEX (user_id) +* INDEX (module) +* INDEX (action) +* INDEX (created_at) +* INDEX (entity_id) + +**Partitioning**: +* **PARTITION BY RANGE (YEAR(created_at))**: āđāļšāđˆāļ‡ Partition āļĢāļēāļĒāļ›āļĩ āđ€āļžāļ·āđˆāļ­āļ›āļĢāļ°āļŠāļīāļ—āļ˜āļīāļ āļēāļžāđƒāļ™āļāļēāļĢāđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨāļĢāļ°āļĒāļ°āļĒāļēāļ§ + +--- + +### 11.3 notifications (UPDATE v1.5.1) + +**Purpose**: System notifications for users + +| Column Name | Data Type | Constraints | Description | +| ----------- | ------------ | --------------------------- | ----------------------------------- | +| id | BIGINT | PRIMARY KEY, AUTO_INCREMENT | Unique notification ID | +| user_id | INT | NOT NULL, FK | Recipient user ID | +| title | VARCHAR(255) | NOT NULL | Notification title | +| message | TEXT | NOT NULL | Notification body | +| link | VARCHAR(500) | NULL | Action link URL | +| type | VARCHAR(50) | DEFAULT ' INFO ' | Type: INFO, WARNING, ERROR, SUCCESS | +| is_read | BOOLEAN | DEFAULT FALSE | Read status | +| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Notification timestamp | + +**Indexes**: + +* PRIMARY KEY (id, created_at) -- **Partition Key** +* FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE +* INDEX (user_id, is_read) +* INDEX (created_at) + +**Partitioning**: +* **PARTITION BY RANGE (YEAR(created_at))**: āđāļšāđˆāļ‡ Partition āļĢāļēāļĒāļ›āļĩ + +--- + +## **12. 🔍 Views (āļĄāļļāļĄāļĄāļ­āļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ)** + +### 12.1 v_correspondence_details + +**Purpose**: Denormalized view for correspondence listing and searching + +```sql +CREATE VIEW v_correspondence_details AS +SELECT + c.id, + c.correspondence_number, + c.correspondence_type_id, + ct.type_name, + c.project_id, + p.project_code, + c.originator_id, + org.organization_code AS originator_code, + cr.title, + cr.revision_number, + cr.correspondence_status_id, + cs.status_name, + cr.document_date, + cr.created_at +FROM correspondences c +JOIN correspondence_revisions cr ON c.id = cr.correspondence_id AND cr.is_current = 1 +JOIN correspondence_types ct ON c.correspondence_type_id = ct.id +JOIN projects p ON c.project_id = p.id +LEFT JOIN organizations org ON c.originator_id = org.id +LEFT JOIN correspondence_status cs ON cr.correspondence_status_id = cs.id; +``` + +### 12.2 v_rfa_details + +**Purpose**: Denormalized view for RFA listing and searching + +```sql +CREATE VIEW v_rfa_details AS +SELECT + r.id, + c.correspondence_number AS rfa_number, + rt.type_code AS rfa_type, + rr.title, + rr.revision_number, + rsc.status_name AS rfa_status, + rac.approve_name AS approval_result, + rr.document_date, + rr.due_date +FROM rfas r +JOIN correspondences c ON r.id = c.id -- Assuming 1:1 mapping logic or shared ID +JOIN rfa_revisions rr ON r.id = rr.rfa_id AND rr.is_current = 1 +JOIN rfa_types rt ON r.rfa_type_id = rt.id +JOIN rfa_status_codes rsc ON rr.rfa_status_code_id = rsc.id +LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id; +``` + +--- + +## **13. 📊 Index Summaries (āļŠāļĢāļļāļ› Index)** + +### 13.1 Performance Indexes + +| Table Name | Index Columns | Purpose | +| :----------------------- | :------------------------------------------------- | :----------------------------- | +| correspondences | (project_id, correspondence_number) | Fast lookup by document number | +| correspondences | (correspondence_type_id) | Filter by type | +| correspondence_revisions | (correspondence_id, is_current) | Get current revision | +| rfas | (rfa_type_id) | Filter by RFA type | +| rfa_revisions | (rfa_id, is_current) | Get current RFA revision | +| rfa_revisions | (rfa_status_code_id) | Filter by status | +| audit_logs | (created_at) | Date range queries | +| audit_logs | (user_id) | User activity history | +| audit_logs | (module, action) | Action type analysis | +| notifications | (user_id, is_read) | Unread notifications query | +| document_number_counters | (project_id, correspondence_type_id, current_year) | Running number generation | +| workflow_instances | (business_key) | Workflow lookup by document ID | +| workflow_instances | (status) | Monitor active workflows | + +### 13.2 Unique Constraints + +| Table Name | Columns | Description | +| :---------------------- | :----------------------------------- | :--------------------------------- | +| users | (username) | Unique login name | +| users | (email) | Unique email address | +| organizations | (organization_code) | Unique organization code | +| projects | (project_code) | Unique project code | +| contracts | (contract_code) | Unique contract code | +| correspondences | (project_id, correspondence_number) | Unique document number per project | +| rfas | (drawing_number) | Unique shop drawing number | +| document_number_formats | (project_id, correspondence_type_id) | One format per type per project | +| workflow_definitions | (workflow_code) | Unique workflow code | + +--- + +## **14. ðŸ›Ąïļ Data Integrity Constraints (āļ„āļ§āļēāļĄāļ–āļđāļāļ•āđ‰āļ­āļ‡āļ‚āļ­āļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ)** + +### 14.1 Soft Delete Policy + +* **Tables with `deleted_at`**: + * users + * organizations + * projects + * contracts + * correspondences + * rfas + * shop_drawings + * contract_drawings +* **Rule**: Records are never physically deleted. `deleted_at` is set to timestamp. +* **Query Rule**: All standard queries MUST include `WHERE deleted_at IS NULL`. + +### 14.2 Foreign Key Cascades + +* **ON DELETE CASCADE**: + * Used for child tables that cannot exist without parent (e.g., `correspondence_revisions`, `rfa_revisions`, `correspondence_attachments`). +* **ON DELETE RESTRICT**: + * Used for master data references to prevent accidental deletion of used data (e.g., `correspondence_types`, `organizations`). +* **ON DELETE SET NULL**: + * Used for optional references (e.g., `created_by`, `originator_id`). + +--- + +## **15. 🔐 Security & Permissions Model (āļ„āļ§āļēāļĄāļ›āļĨāļ­āļ”āļ āļąāļĒ)** + +### 15.1 Row-Level Security (RLS) Logic + +* **Organization Scope**: Users can only see documents where `originator_id` OR `recipient_organization_id` matches their organization. +* **Project Scope**: Users can only see documents within projects they are assigned to. +* **Confidentiality**: Documents marked `is_confidential` are visible ONLY to specific roles or users. + +### 15.2 Role-Based Access Control (RBAC) + +* **Permissions** are granular (e.g., `correspondence.view`, `correspondence.create`). +* **Roles** aggregate permissions (e.g., `Document Controller` = `view` + `create` + `edit`). +* **Assignments** link Users to Roles within a Context (Global, Project, or Organization). + +--- + +## **16. 🔄 Data Migration & Seeding (āļāļēāļĢāļĒāđ‰āļēāļĒāļ‚āđ‰āļ­āļĄāļđāļĨ)** + +### 16.1 Initial Seeding (V1.5.1) + +1. **Master Data**: + * `organizations`: Owner, Consultant, Contractor + * `projects`: LCBP3 + * `correspondence_types`: LETTER, MEMO, TRANSMITTAL, RFA + * `rfa_types`: DWG, MAT, DOC, RFI + * `rfa_status_codes`: DFT, PEND, APPR, REJ + * `disciplines`: GEN, STR, ARC, MEP (New V1.5.1) +2. **System Users**: + * `admin`: Super Admin + * `system`: System Bot for automated tasks + +### 16.2 Migration Strategy + +* **Schema Migration**: Use TypeORM Migrations or raw SQL scripts (versioned). +* **Data Migration**: + * **V1.4.5 -> V1.5.1**: + * Run SQL script `8_lcbp3_v1_5_1.sql` + * Populate `disciplines` table. + * Update `document_number_counters` PK (Requires careful migration of existing counters). + * Initialize `workflow_definitions`. + +--- + +## **17. 📈 Monitoring & Maintenance (āļāļēāļĢāļ”āļđāđāļĨāļĢāļąāļāļĐāļē)** + +### 17.1 Database Maintenance + +* **Daily**: Incremental Backup. +* **Weekly**: Full Backup + `OPTIMIZE TABLE` for heavy tables (`audit_logs`, `notifications`). +* **Monthly**: Archive old `audit_logs` partitions to cold storage. + +### 17.2 Health Checks + +* Monitor `document_number_errors` for numbering failures. +* Monitor `workflow_instances` for stuck workflows (`status = ' IN_PROGRESS '` > 7 days). +* Check `document_number_counters` for gaps or resets. + +--- + +## **18. 📖 Glossary (āļ„āļģāļĻāļąāļžāļ—āđŒ)** + +* **RFA**: Request for Approval (āđ€āļ­āļāļŠāļēāļĢāļ‚āļ­āļ­āļ™āļļāļĄāļąāļ•āļī) +* **Transmittal**: Document Transmittal Sheet (āđƒāļšāļ™āļģāļŠāđˆāļ‡āđ€āļ­āļāļŠāļēāļĢ) +* **Shop Drawing**: āđāļšāļšāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ—āļĩāđˆāļœāļđāđ‰āļĢāļąāļšāđ€āļŦāļĄāļēāļˆāļąāļ”āļ—āļģ +* **Contract Drawing**: āđāļšāļšāļŠāļąāļāļāļē (āđāļšāļšāļ•āļąāđ‰āļ‡āļ•āđ‰āļ™) +* **Revision**: āļ‰āļšāļąāļšāđāļāđ‰āđ„āļ‚ (0, 1, 2, A, B, C) +* **Originator**: āļœāļđāđ‰āļˆāļąāļ”āļ—āļģ/āļœāļđāđ‰āļŠāđˆāļ‡āđ€āļ­āļāļŠāļēāļĢ +* **Recipient**: āļœāļđāđ‰āļĢāļąāļšāđ€āļ­āļāļŠāļēāļĢ +* **Workflow**: āļāļĢāļ°āļšāļ§āļ™āļāļēāļĢāļ—āļģāļ‡āļēāļ™/āļ­āļ™āļļāļĄāļąāļ•āļī +* **Discipline**: āļŠāļēāļ‚āļēāļ‡āļēāļ™ (āđ€āļŠāđˆāļ™ āđ‚āļĒāļ˜āļē, āļŠāļ–āļēāļ›āļąāļ•āļĒāđŒ, āđ„āļŸāļŸāđ‰āļē) + +--- + +**End of Data Dictionary V1.5.1** diff --git a/specs/07-database/data-dictionary-v1.5.1.sql b/specs/07-database/data-dictionary-v1.5.1.sql deleted file mode 100644 index 63c3147..0000000 --- a/specs/07-database/data-dictionary-v1.5.1.sql +++ /dev/null @@ -1,2548 +0,0 @@ -INSERT INTO organization_roles (id, role_name) -VALUES (1, 'OWNER'), - (2, 'DESIGNER'), - (3, 'CONSULTANT'), - (4, 'CONTRACTOR'), - (5, 'THIRD PARTY'), - (6, 'GUEST'); - -INSERT INTO organizations ( - id, - organization_code, - organization_name, - role_id - ) -VALUES (1, 'āļāļ—āļ—.', 'āļāļēāļĢāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāđˆāļ‡āļ›āļĢāļ°āđ€āļ—āļĻāđ„āļ—āļĒ', 1), - ( - 10, - 'āļŠāļ„āļ‰.3', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3', - 1 - ), - ( - 11, - 'āļŠāļ„āļ‰.3-01', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ—āļĩāđˆāļ›āļĢāļķāļāļĐāļēāļ„āļ§āļšāļ„āļļāļĄāļ‡āļēāļ™', - 1 - ), - (12, 'āļŠāļ„āļ‰.3-02', 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ‡āļēāļ™āļ—āļēāļ‡āļ—āļ°āđ€āļĨ', 1), - ( - 13, - 'āļŠāļ„āļ‰.3-03', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ­āļēāļ„āļēāļĢāđāļĨāļ°āļĢāļ°āļšāļšāļŠāļēāļ˜āļēāļĢāļ“āļđāļ›āđ‚āļ āļ„', - 1 - ), - ( - 14, - 'āļŠāļ„āļ‰.3-04', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ•āļĢāļ§āļˆāļŠāļ­āļšāļœāļĨāļāļĢāļ°āļ—āļšāļŠāļīāđˆāļ‡āđāļ§āļ”āļĨāđ‰āļ­āļĄ', - 1 - ), - ( - 15, - 'āļŠāļ„āļ‰.3-05', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āđ€āļĒāļĩāļĒāļ§āļĒāļēāļāļēāļĢāļ›āļĢāļ°āļĄāļ‡', - 1 - ), - ( - 16, - 'āļŠāļ„āļ‰.3-06', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 3', - 1 - ), - ( - 17, - 'āļŠāļ„āļ‰.3-07', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 4', - 1 - ), - ( - 18, - 'āļŠāļ„āļ‰.3-xx', - 'āļ•āļĢāļ§āļˆāļĢāļąāļšāļžāļąāļŠāļ”āļļ āļ—āļĩāđˆāļ›āļĢāļķāļāļĐāļēāļ­āļ­āļāđāļšāļš āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 4', - 1 - ), - ( - 21, - 'TEAM', - 'Designer Consulting Ltd.', - 2 - ), - ( - 22, - 'āļ„āļ„āļ‡.', - 'Construction Supervision Ltd.', - 3 - ), - ( - 41, - 'āļœāļĢāļĄ.1', - 'Contractor āļ‡āļēāļ™āļ—āļēāļ‡āļ—āļ°āđ€āļĨ', - 4 - ), - ( - 42, - 'āļœāļĢāļĄ.2', - 'Contractor āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡', - 4 - ), - ( - 43, - 'āļœāļĢāļĄ.3', - 'Contractor āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 3', - 4 - ), - ( - 44, - 'āļœāļĢāļĄ.4', - 'Contractor āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 4', - 4 - ), - ( - 31, - 'EN', - 'Third Party Environment', - 5 - ), - ( - 32, - 'CAR', - 'Third Party Fishery Care', - 5 - ); - --- Seed project -INSERT INTO projects (project_code, project_name) -VALUES ( - 'LCBP3', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1-4)' - ), - ( - 'LCBP3-C1', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ‡āļēāļ™āļ—āļēāļ‡āļ—āļ°āđ€āļĨ' - ), - ( - 'LCBP3-C2', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 2) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ­āļēāļ„āļēāļĢ āļ—āđˆāļēāđ€āļ—āļĩāļĒāļšāđ€āļĢāļ·āļ­ āļĢāļ°āļšāļšāļ–āļ™āļ™ āđāļĨāļ°āļĢāļ°āļšāļšāļŠāļēāļ˜āļēāļĢāļ“āļđāļ›āđ‚āļ āļ„' - ), - ( - 'LCBP3-C3', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 3) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' - ), - ( - 'LCBP3-C4', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 4) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' - ), - ( - 'LCBP3-EN', - 'āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 4) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' - ); - --- Seed contract --- āđƒāļŠāđ‰ Subquery āđ€āļžāļ·āđˆāļ­āļ”āļķāļ‡ project_id āļĄāļēāđ€āļŠāļ·āđˆāļ­āļĄāđ‚āļĒāļ‡ āļ—āļģāđƒāļŦāđ‰āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āļĄāļēāļ™āļąāđˆāļ‡āļˆāļąāļ”āļāļēāļĢ ID āļ”āđ‰āļ§āļĒāļ•āļąāļ§āđ€āļ­āļ‡ -INSERT INTO contracts ( - contract_code, - contract_name, - project_id, - is_active - ) -VALUES ( - 'LCBP3-DS', - 'āļ‡āļēāļ™āļˆāđ‰āļēāļ‡āļ—āļĩāđˆāļ›āļĢāļĩāļāļĐāļēāļ­āļ­āļāđāļšāļš āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1-4)', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3' - ), - TRUE - ), - ( - 'LCBP3-PS', - 'āļ‡āļēāļ™āļˆāđ‰āļēāļ‡āļ—āļĩāđˆāļ›āļĢāļĩāļāļĐāļēāļ„āļ§āļšāļ„āļļāļĄāļ‡āļēāļ™ āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1-4)', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3' - ), - TRUE - ), - ( - 'LCBP3-C1', - 'āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ‡āļēāļ™āļ—āļēāļ‡āļ—āļ°āđ€āļĨ', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3-C1' - ), - TRUE - ), - ( - 'LCBP3-C2', - 'āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 2) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ­āļēāļ„āļēāļĢ āļ—āđˆāļēāđ€āļ—āļĩāļĒāļšāđ€āļĢāļ·āļ­ āļĢāļ°āļšāļšāļ–āļ™āļ™ āđāļĨāļ°āļĢāļ°āļšāļšāļŠāļēāļ˜āļēāļĢāļ“āļđāļ›āđ‚āļ āļ„', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3-C2' - ), - TRUE - ), - ( - 'LCBP3-C3', - 'āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 3) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3-C3' - ), - TRUE - ), - ( - 'LCBP3-C4', - 'āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 4) āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3-C4' - ), - TRUE - ), - ( - 'LCBP3-EN', - 'āļ‡āļēāļ™āļˆāđ‰āļēāļ‡āđ€āļŦāļĄāļēāļ•āļĢāļ§āļˆāļŠāļ­āļšāļœāļĨāļāļĢāļ°āļ—āļšāļŠāļīāđˆāļ‡āđāļ§āļ”āļĨāđ‰āļ­āļĄāļ™āļ°āļŦāļ§āđˆāļēāļ‡āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āđ‚āļ„āļĢāļ‡āļāļēāļĢāļžāļąāļ’āļ™āļēāļ—āđˆāļēāđ€āļĢāļ·āļ­āđāļŦāļĨāļĄāļ‰āļšāļąāļ‡ āļĢāļ°āļĒāļ°āļ—āļĩāđˆ 3 (āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1-4)', - ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3' - ), - TRUE - ); - --- Seed user --- Initial SUPER_ADMIN user -INSERT INTO users ( - `user_id`, - `username`, - `password_hash`, - `first_name`, - `last_name`, - `email`, - `line_id`, - `primary_organization_id` - ) -VALUES ( - 1, - 'superadmin', - '$2b$10$E6d5k.f46jr.POGWKHhiQ.X1ZsFrMpZox//sCxeOiLUULGuAHO0NW', - 'Super', - 'Admin', - 'superadmin @example.com', - NULL, - NULL - ), - ( - 2, - 'admin', - '$2b$10$E6d5k.f46jr.POGWKHhiQ.X1ZsFrMpZox//sCxeOiLUULGuAHO0NW', - 'Admin', - 'āļ„āļ„āļ‡.', - 'admin@example.com', - NULL, - 1 - ), - ( - 3, - 'editor01', - '$2b$10$E6d5k.f46jr.POGWKHhiQ.X1ZsFrMpZox//sCxeOiLUULGuAHO0NW', - 'DC', - 'C1', - 'editor01 @example.com', - NULL, - 41 - ), - ( - 4, - 'viewer01', - '$2b$10$E6d5k.f46jr.POGWKHhiQ.X1ZsFrMpZox//sCxeOiLUULGuAHO0NW', - 'Viewer', - 'āļŠāļ„āļ‰.03', - 'viewer01 @example.com', - NULL, - 10 - ); - --- ========================================================== --- Seed Roles (āļšāļ—āļšāļēāļ—āļžāļ·āđ‰āļ™āļāļēāļ™ 5 āļšāļ—āļšāļēāļ— āļ•āļēāļĄ Req 4.3) --- ========================================================== --- 1. Superadmin (Global) -INSERT INTO roles (role_id, role_name, scope, description) -VALUES ( - 1, - 'Superadmin', - 'Global', - 'āļœāļđāđ‰āļ”āļđāđāļĨāļĢāļ°āļšāļšāļŠāļđāļ‡āļŠāļļāļ”: āļŠāļēāļĄāļēāļĢāļ–āļ—āļģāļ—āļļāļāļ­āļĒāđˆāļēāļ‡āđƒāļ™āļĢāļ°āļšāļš, āļˆāļąāļ”āļāļēāļĢāļ­āļ‡āļ„āđŒāļāļĢ, āđāļĨāļ°āļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļāļĢāļ°āļ”āļąāļš Global' - ), - -- 2. Org Admin (Organization) - ( - 2, - 'Org Admin', - 'Organization', - 'āļœāļđāđ‰āļ”āļđāđāļĨāļ­āļ‡āļ„āđŒāļāļĢ: āļˆāļąāļ”āļāļēāļĢāļœāļđāđ‰āđƒāļŠāđ‰āđƒāļ™āļ­āļ‡āļ„āđŒāļāļĢ, āļˆāļąāļ”āļāļēāļĢāļšāļ—āļšāļēāļ— / āļŠāļīāļ—āļ˜āļīāđŒāļ āļēāļĒāđƒāļ™āļ­āļ‡āļ„āđŒāļāļĢ, āđāļĨāļ°āļ”āļđāļĢāļēāļĒāļ‡āļēāļ™āļ‚āļ­āļ‡āļ­āļ‡āļ„āđŒāļāļĢ' - ), - -- 3. Document Control (Organization) - ( - 3, - 'Document Control', - 'Organization', - 'āļ„āļ§āļšāļ„āļļāļĄāđ€āļ­āļāļŠāļēāļĢāļ‚āļ­āļ‡āļ­āļ‡āļ„āđŒāļāļĢ: āđ€āļžāļīāđˆāļĄ / āđāļāđ‰āđ„āļ‚ / āļĨāļšāđ€āļ­āļāļŠāļēāļĢ, āđāļĨāļ°āļāļģāļŦāļ™āļ”āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ­āļāļŠāļēāļĢāļ āļēāļĒāđƒāļ™āļ­āļ‡āļ„āđŒāļāļĢ' - ), - -- 4. Editor (Organization) - ( - 4, - 'Editor', - 'Organization', - 'āļœāļđāđ‰āđāļāđ‰āđ„āļ‚āđ€āļ­āļāļŠāļēāļĢāļ‚āļ­āļ‡āļ­āļ‡āļ„āđŒāļāļĢ: āđ€āļžāļīāđˆāļĄ / āđāļāđ‰āđ„āļ‚āđ€āļ­āļāļŠāļēāļĢāļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļšāļĄāļ­āļšāļŦāļĄāļēāļĒ' - ), - -- 5. Viewer (Organization) - ( - 5, - 'Viewer', - 'Organization', - 'āļœāļđāđ‰āļ”āļđāđ€āļ­āļāļŠāļēāļĢāļ‚āļ­āļ‡āļ­āļ‡āļ„āđŒāļāļĢ: āļ”āļđāđ€āļ­āļāļŠāļēāļĢāļ—āļĩāđˆāļĄāļĩāļŠāļīāļ—āļ˜āļīāđŒāđ€āļ‚āđ‰āļēāļ–āļķāļ‡āđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™' - ), - -- 6. Project Manager (Project) - ( - 6, - 'Project Manager', - 'Project', - 'āļœāļđāđ‰āļˆāļąāļ”āļāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢ: āļˆāļąāļ”āļāļēāļĢāļŠāļĄāļēāļŠāļīāļāđƒāļ™āđ‚āļ„āļĢāļ‡āļāļēāļĢ, āļŠāļĢāđ‰āļēāļ‡ / āļˆāļąāļ”āļāļēāļĢāļŠāļąāļāļāļēāđƒāļ™āđ‚āļ„āļĢāļ‡āļāļēāļĢ, āđāļĨāļ°āļ”āļđāļĢāļēāļĒāļ‡āļēāļ™āđ‚āļ„āļĢāļ‡āļāļēāļĢ' - ), - -- 7. Contract Admin (Contract) - ( - 7, - 'Contract Admin', - 'Contract', - 'āļœāļđāđ‰āļ”āļđāđāļĨāļŠāļąāļāļāļē: āļˆāļąāļ”āļāļēāļĢāļŠāļĄāļēāļŠāļīāļāđƒāļ™āļŠāļąāļāļāļē, āļŠāļĢāđ‰āļēāļ‡ / āļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļāđ€āļ‰āļžāļēāļ°āļŠāļąāļāļāļē, āđāļĨāļ°āļ­āļ™āļļāļĄāļąāļ•āļīāđ€āļ­āļāļŠāļēāļĢāđƒāļ™āļŠāļąāļāļāļē' - ); - --- ===================================================== --- 2. Seed Permissions (āļŠāļīāļ—āļ˜āļīāđŒāļāļēāļĢāđƒāļŠāđ‰āļ‡āļēāļ™āļ—āļąāđ‰āļ‡āļŦāļĄāļ”) --- āļŠāļīāļ—āļ˜āļīāđŒāļĢāļ°āļ”āļąāļšāļĢāļ°āļšāļšāđāļĨāļ°āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāļŦāļĨāļąāļ (System & Master Data) --- ===================================================== -INSERT INTO permissions ( - permission_id, - permission_name, - description - ) -VALUES ( - 1, - 'system.manage_all', - 'āļ—āļģāļ—āļļāļāļ­āļĒāđˆāļēāļ‡āđƒāļ™āļĢāļ°āļšāļš (Superadmin Power)' - ), - -- āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāļ­āļ‡āļ„āđŒāļāļĢ - ( - 2, - 'organization.create', - 'āļŠāļĢāđ‰āļēāļ‡āļ­āļ‡āļ„āđŒāļāļĢāđƒāļŦāļĄāđˆ' - ), - ( - 3, - 'organization.edit', - 'āđāļāđ‰āđ„āļ‚āļ‚āđ‰āļ­āļĄāļđāļĨāļ­āļ‡āļ„āđŒāļāļĢ' - ), - ( - 4, - 'organization.delete', - 'āļĨāļšāļ­āļ‡āļ„āđŒāļāļĢ' - ), - ( - 5, - 'organization.view', - 'āļ”āļđāļĢāļēāļĒāļāļēāļĢāļ­āļ‡āļ„āđŒāļāļĢ' - ), - -- āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢ - ( - 6, - 'project.create', - 'āļŠāļĢāđ‰āļēāļ‡āđ‚āļ„āļĢāļ‡āļāļēāļĢāđƒāļŦāļĄāđˆ' - ), - ( - 7, - 'project.edit', - 'āđāļāđ‰āđ„āļ‚āļ‚āđ‰āļ­āļĄāļđāļĨāđ‚āļ„āļĢāļ‡āļāļēāļĢ' - ), - (8, 'project.delete', 'āļĨāļšāđ‚āļ„āļĢāļ‡āļāļēāļĢ'), - ( - 9, - 'project.view', - 'āļ”āļđāļĢāļēāļĒāļāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢ' - ), - -- āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāļšāļ—āļšāļēāļ—āđāļĨāļ°āļŠāļīāļ—āļ˜āļīāđŒ (Roles & Permissions) - ( - 10, - 'role.create', - 'āļŠāļĢāđ‰āļēāļ‡āļšāļ—āļšāļēāļ— (Role) āđƒāļŦāļĄāđˆ' - ), - ( - 11, - 'role.edit', - 'āđāļāđ‰āđ„āļ‚āļšāļ—āļšāļēāļ— (Role)' - ), - (12, 'role.delete', 'āļĨāļšāļšāļ—āļšāļēāļ— (Role)'), - ( - 13, - 'permission.assign', - 'āļĄāļ­āļšāļŠāļīāļ—āļ˜āļīāđŒāđƒāļŦāđ‰āļāļąāļšāļšāļ—āļšāļēāļ— (Role)' - ), - -- āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļ (Master Data) - ( - 14, - 'master_data.document_type.manage', - 'āļˆāļąāļ”āļāļēāļĢāļ›āļĢāļ°āđ€āļ āļ—āđ€āļ­āļāļŠāļēāļĢ (Document Types)' - ), - ( - 15, - 'master_data.document_status.manage', - 'āļˆāļąāļ”āļāļēāļĢāļŠāļ–āļēāļ™āļ°āđ€āļ­āļāļŠāļēāļĢ (Document Statuses)' - ), - ( - 16, - 'master_data.drawing_category.manage', - 'āļˆāļąāļ”āļāļēāļĢāļŦāļĄāļ§āļ”āļŦāļĄāļđāđˆāđāļšāļš (Drawing Categories)' - ), - ( - 17, - 'master_data.tag.manage', - 'āļˆāļąāļ”āļāļēāļĢ Tags' - ), - -- āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāļœāļđāđ‰āđƒāļŠāđ‰āļ‡āļēāļ™ - ( - 18, - 'user.create', - 'āļŠāļĢāđ‰āļēāļ‡āļœāļđāđ‰āđƒāļŠāđ‰āļ‡āļēāļ™āđƒāļŦāļĄāđˆ' - ), - ( - 19, - 'user.edit', - 'āđāļāđ‰āđ„āļ‚āļ‚āđ‰āļ­āļĄāļđāļĨāļœāļđāđ‰āđƒāļŠāđ‰āļ‡āļēāļ™' - ), - ( - 20, - 'user.delete', - 'āļĨāļš / āļ›āļīāļ”āļāļēāļĢāđƒāļŠāđ‰āļ‡āļēāļ™āļœāļđāđ‰āđƒāļŠāđ‰' - ), - ( - 21, - 'user.view', - 'āļ”āļđāļ‚āđ‰āļ­āļĄāļđāļĨāļœāļđāđ‰āđƒāļŠāđ‰āļ‡āļēāļ™' - ), - ( - 22, - 'user.assign_organization', - 'āļĄāļ­āļšāļœāļđāđ‰āđƒāļŠāđ‰āļ‡āļēāļ™āđƒāļŦāđ‰āļāļąāļšāļ­āļ‡āļ„āđŒāļāļĢ' - ); - --- ===================================================== --- == 2. āļŠāļīāļ—āļ˜āļīāđŒāļāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢāđāļĨāļ°āļŠāļąāļāļāļē (Project & Contract) == --- ===================================================== -INSERT INTO permissions ( - permission_id, - permission_name, - description - ) -VALUES ( - 23, - 'project.manage_members', - 'āļˆāļąāļ”āļāļēāļĢāļŠāļĄāļēāļŠāļīāļāđƒāļ™āđ‚āļ„āļĢāļ‡āļāļēāļĢ (āđ€āļŠāļīāļ / āļ–āļ­āļ”āļŠāļĄāļēāļŠāļīāļ)' - ), - ( - 24, - 'project.create_contracts', - 'āļŠāļĢāđ‰āļēāļ‡āļŠāļąāļāļāļēāđƒāļ™āđ‚āļ„āļĢāļ‡āļāļēāļĢ' - ), - ( - 25, - 'project.manage_contracts', - 'āļˆāļąāļ”āļāļēāļĢāļŠāļąāļāļāļēāđƒāļ™āđ‚āļ„āļĢāļ‡āļāļēāļĢ' - ), - ( - 26, - 'project.view_reports', - 'āļ”āļđāļĢāļēāļĒāļ‡āļēāļ™āļĢāļ°āļ”āļąāļšāđ‚āļ„āļĢāļ‡āļāļēāļĢ' - ), - ( - 27, - 'contract.manage_members', - 'āļˆāļąāļ”āļāļēāļĢāļŠāļĄāļēāļŠāļīāļāđƒāļ™āļŠāļąāļāļāļē' - ), - ( - 28, - 'contract.view', - 'āļ”āļđāļ‚āđ‰āļ­āļĄāļđāļĨāļŠāļąāļāļāļē' - ); - --- ===================================================== --- == 3. āļŠāļīāļ—āļ˜āļīāđŒāļāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ€āļ­āļāļŠāļēāļĢ (Document Management) == --- ===================================================== --- āļŠāļīāļ—āļ˜āļīāđŒāļ—āļąāđˆāļ§āđ„āļ›āļŠāļģāļŦāļĢāļąāļšāđ€āļ­āļāļŠāļēāļĢāļ—āļļāļāļ›āļĢāļ°āđ€āļ āļ— -INSERT INTO permissions ( - permission_id, - permission_name, - description - ) -VALUES ( - 29, - 'document.create_draft', - 'āļŠāļĢāđ‰āļēāļ‡āđ€āļ­āļāļŠāļēāļĢāđƒāļ™āļŠāļ–āļēāļ™āļ°āļ‰āļšāļąāļšāļĢāđˆāļēāļ‡ (Draft) ' - ), - ( - 30, - 'document.submit', - 'āļŠāđˆāļ‡āđ€āļ­āļāļŠāļēāļĢ (Submitted)' - ), - (31, 'document.view', 'āļ”āļđāđ€āļ­āļāļŠāļēāļĢ'), - ( - 32, - 'document.edit', - 'āđāļāđ‰āđ„āļ‚āđ€āļ­āļāļŠāļēāļĢ (āļ—āļąāđˆāļ§āđ„āļ›)' - ), - ( - 33, - 'document.admin_edit', - 'āđāļāđ‰āđ„āļ‚ / āļ–āļ­āļ™ / āļĒāļāđ€āļĨāļīāļāđ€āļ­āļāļŠāļēāļĢāļ—āļĩāđˆāļŠāđˆāļ‡āđāļĨāđ‰āļ§ (Admin Power) ' - ), - (34, 'document.delete', 'āļĨāļšāđ€āļ­āļāļŠāļēāļĢ'), - ( - 35, - 'document.attach', - 'āļˆāļąāļ”āļāļēāļĢāđ„āļŸāļĨāđŒāđāļ™āļš (āļ­āļąāļ›āđ‚āļŦāļĨāļ” / āļĨāļš) ' - ), - -- āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ‰āļžāļēāļ°āļŠāļģāļŦāļĢāļąāļš Correspondence - ( - 36, - 'correspondence.create', - 'āļŠāļĢāđ‰āļēāļ‡āđ€āļ­āļāļŠāļēāļĢāđ‚āļ•āđ‰āļ•āļ­āļš (Correspondence) ' - ), - -- āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ‰āļžāļēāļ°āļŠāļģāļŦāļĢāļąāļš Request for Approval (RFA) - ( - 37, - 'rfa.create', - 'āļŠāļĢāđ‰āļēāļ‡āđ€āļ­āļāļŠāļēāļĢāļ‚āļ­āļ­āļ™āļļāļĄāļąāļ•āļī (RFA)' - ), - ( - 38, - 'rfa.manage_shop_drawings', - 'āļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨ Shop Drawing āđāļĨāļ° Contract Drawing āļ—āļĩāđˆāđ€āļāļĩāđˆāļĒāļ§āļ‚āđ‰āļ­āļ‡' - ), - -- āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ‰āļžāļēāļ°āļŠāļģāļŦāļĢāļąāļš Shop Drawing & Contract Drawing - ( - 39, - 'drawing.create', - 'āļŠāļĢāđ‰āļēāļ‡ / āđāļāđ‰āđ„āļ‚āļ‚āđ‰āļ­āļĄāļđāļĨāđāļšāļš (Shop / Contract Drawing)' - ), - -- āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ‰āļžāļēāļ°āļŠāļģāļŦāļĢāļąāļš Transmittal - ( - 40, - 'transmittal.create', - 'āļŠāļĢāđ‰āļēāļ‡āđ€āļ­āļāļŠāļēāļĢāļ™āļģāļŠāđˆāļ‡ (Transmittal)' - ), - -- āļŠāļīāļ—āļ˜āļīāđŒāđ€āļ‰āļžāļēāļ°āļŠāļģāļŦāļĢāļąāļš Circulation Sheet (āđƒāļšāđ€āļ§āļĩāļĒāļ™) - ( - 41, - 'circulation.create', - 'āļŠāļĢāđ‰āļēāļ‡āđƒāļšāđ€āļ§āļĩāļĒāļ™āđ€āļ­āļāļŠāļēāļĢ (Circulation)' - ), - ( - 42, - 'circulation.respond', - 'āļ•āļ­āļšāļāļĨāļąāļšāđƒāļšāđ€āļ§āļĩāļĒāļ™ (Main / Action)' - ), - ( - 43, - 'circulation.acknowledge', - 'āļĢāļąāļšāļ—āļĢāļēāļšāđƒāļšāđ€āļ§āļĩāļĒāļ™ (Information)' - ), - ( - 44, - 'circulation.close', - 'āļ›āļīāļ”āđƒāļšāđ€āļ§āļĩāļĒāļ™' - ); - --- ===================================================== --- == 4. āļŠāļīāļ—āļ˜āļīāđŒāļāļēāļĢāļˆāļąāļ”āļāļēāļĢ Workflow == --- ===================================================== -INSERT INTO permissions ( - permission_id, - permission_name, - description - ) -VALUES ( - 45, - 'workflow.action_review', - 'āļ”āļģāđ€āļ™āļīāļ™āļāļēāļĢāđƒāļ™āļ‚āļąāđ‰āļ™āļ•āļ­āļ™āļ›āļąāļˆāļˆāļļāļšāļąāļ™ (āđ€āļŠāđˆāļ™ āļ•āļĢāļ§āļˆāļŠāļ­āļšāđāļĨāđ‰āļ§)' - ), - ( - 46, - 'workflow.force_proceed', - 'āļšāļąāļ‡āļ„āļąāļšāđ„āļ›āļĒāļąāļ‡āļ‚āļąāđ‰āļ™āļ•āļ­āļ™āļ–āļąāļ”āđ„āļ› (Document Control Power)' - ), - ( - 47, - 'workflow.revert', - 'āļĒāđ‰āļ­āļ™āļāļĨāļąāļšāđ„āļ›āļĒāļąāļ‡āļ‚āļąāđ‰āļ™āļ•āļ­āļ™āļāđˆāļ­āļ™āļŦāļ™āđ‰āļē (Document Control Power)' - ); - --- ===================================================== --- == 5. āļŠāļīāļ—āļ˜āļīāđŒāļ”āđ‰āļēāļ™āļāļēāļĢāļ„āđ‰āļ™āļŦāļēāđāļĨāļ°āļĢāļēāļĒāļ‡āļēāļ™ (Search & Reporting) == --- ===================================================== -INSERT INTO permissions ( - permission_id, - permission_name, - description - ) -VALUES ( - 48, - 'search.advanced', - 'āđƒāļŠāđ‰āļ‡āļēāļ™āļāļēāļĢāļ„āđ‰āļ™āļŦāļēāļ‚āļąāđ‰āļ™āļŠāļđāļ‡' - ), - ( - 49, - 'report.generate', - 'āļŠāļĢāđ‰āļēāļ‡āļĢāļēāļĒāļ‡āļēāļ™āļŠāļĢāļļāļ› (āļĢāļēāļĒāļ§āļąāļ™ / āļŠāļąāļ›āļ”āļēāļŦāđŒ / āđ€āļ”āļ·āļ­āļ™ / āļ›āļĩ)' - ); - --- ========================================================== --- Seed Role-Permissions Mapping (āļˆāļąāļšāļ„āļđāđˆāļŠāļīāļ—āļ˜āļīāđŒāđ€āļĢāļīāđˆāļĄāļ•āđ‰āļ™) --- ========================================================== --- Seed data for the 'role_permissions 'table --- This table links roles to their specific permissions. --- NOTE: This assumes the role_id and permission_id FROM the previous seed data files. --- Superadmin (role_id = 1), Org Admin (role_id = 2), Document Control (role_id = 3), etc. --- ===================================================== --- == 1. Superadmin (role_id = 1) - Gets ALL permissions == --- ===================================================== --- Superadmin can do everything. We can dynamically link all permissions to this role. --- This is a robust way to ensure Superadmin always has full power. -INSERT INTO role_permissions (role_id, permission_id) -SELECT 1, - permission_id -FROM permissions; - --- ===================================================== --- == 2. Org Admin (role_id = 2) == --- ===================================================== -INSERT INTO role_permissions (role_id, permission_id) -VALUES -- āļˆāļąāļ”āļāļēāļĢāļœāļđāđ‰āđƒāļŠāđ‰āđƒāļ™āļ­āļ‡āļ„āđŒāļāļĢ - (2, 18), - -- user.create - (2, 19), - -- user.edit - (2, 20), - -- user.delete - (2, 21), - -- user.view - (2, 22), - -- user.assign_organization - -- āļˆāļąāļ”āļāļēāļĢāļ­āļ‡āļ„āđŒāļāļĢ - (2, 3), - -- organization.edit - (2, 5), - -- organization.view - -- āļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļāļ—āļĩāđˆāļ­āļ™āļļāļāļēāļ• (āđ€āļ‰āļžāļēāļ° Tags) - (2, 17), - -- master_data.tag.manage - -- āļ”āļđāļ‚āđ‰āļ­āļĄāļđāļĨāļ•āđˆāļēāļ‡āđ† āđƒāļ™āļ­āļ‡āļ„āđŒāļāļĢ - (2, 31), - -- document.view - (2, 9), - -- project.view - (2, 28), - -- contract.view - -- āļāļēāļĢāļ„āđ‰āļ™āļŦāļēāđāļĨāļ°āļĢāļēāļĒāļ‡āļēāļ™ - (2, 48), - -- search.advanced - (2, 49); - --- report.generate --- ===================================================== --- == 3. Document Control (role_id = 3) == --- ===================================================== -INSERT INTO role_permissions (role_id, permission_id) -VALUES -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢāđ€āļ­āļāļŠāļēāļĢāļ—āļąāđ‰āļ‡āļŦāļĄāļ” - (3, 29), - -- document.create_draft - (3, 30), - -- document.submit - (3, 31), - -- document.view - (3, 32), - -- document.edit - (3, 33), - -- document.admin_edit - (3, 34), - -- document.delete - (3, 35), - -- document.attach - -- āļŠāļīāļ—āļ˜āļīāđŒāļŠāļĢāđ‰āļēāļ‡āđ€āļ­āļāļŠāļēāļĢāđāļ•āđˆāļĨāļ°āļ›āļĢāļ°āđ€āļ āļ— - (3, 36), - -- correspondence.create - (3, 37), - -- rfa.create - (3, 39), - -- drawing.create - (3, 40), - -- transmittal.create - (3, 41), - -- circulation.create - -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢ Workflow - (3, 45), - -- workflow.action_review - (3, 46), - -- workflow.force_proceed - (3, 47), - -- workflow.revert - -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢ Circulation - (3, 42), - -- circulation.respond - (3, 43), - -- circulation.acknowledge - (3, 44), - -- circulation.close - -- āļŠāļīāļ—āļ˜āļīāđŒāļ­āļ·āđˆāļ™āđ† āļ—āļĩāđˆāļˆāļģāđ€āļ›āđ‡āļ™ - (3, 38), - -- rfa.manage_shop_drawings - (3, 48), - -- search.advanced - (3, 49); - --- report.generate --- ===================================================== --- == 4. Editor (role_id = 4) == --- ===================================================== -INSERT INTO role_permissions (role_id, permission_id) -VALUES -- āļŠāļīāļ—āļ˜āļīāđŒāđāļāđ‰āđ„āļ‚āđ€āļ­āļāļŠāļēāļĢ (āđāļ•āđˆāđ„āļĄāđˆāđƒāļŠāđˆāļŠāļīāļ—āļ˜āļīāđŒ Admin) - (4, 29), - -- document.create_draft - (4, 30), - -- document.submit - (4, 31), - -- document.view - (4, 32), - -- document.edit - (4, 35), - -- document.attach - -- āļŠāļīāļ—āļ˜āļīāđŒāļŠāļĢāđ‰āļēāļ‡āđ€āļ­āļāļŠāļēāļĢāđāļ•āđˆāļĨāļ°āļ›āļĢāļ°āđ€āļ āļ— - (4, 36), - -- correspondence.create - (4, 37), - -- rfa.create - (4, 39), - -- drawing.create - (4, 40), - -- transmittal.create - (4, 41), - -- circulation.create - -- āļŠāļīāļ—āļ˜āļīāđŒāļ­āļ·āđˆāļ™āđ† āļ—āļĩāđˆāļˆāļģāđ€āļ›āđ‡āļ™ - (4, 38), - -- rfa.manage_shop_drawings - (4, 48); - --- search.advanced --- ===================================================== --- == 5. Viewer (role_id = 5) == --- ===================================================== -INSERT INTO role_permissions (role_id, permission_id) -VALUES -- āļŠāļīāļ—āļ˜āļīāđŒāļ”āļđāđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™ - (5, 31), - -- document.view - (5, 48); - --- search.advanced --- ===================================================== --- == 6. Project Manager (role_id = 6) == --- ===================================================== -INSERT INTO role_permissions (role_id, permission_id) -VALUES -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢ - (6, 23), - -- project.manage_members - (6, 24), - -- project.create_contracts - (6, 25), - -- project.manage_contracts - (6, 26), - -- project.view_reports - (6, 9), - -- project.view - -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨāļŦāļĨāļąāļāļĢāļ°āļ”āļąāļšāđ‚āļ„āļĢāļ‡āļāļēāļĢ - (6, 16), - -- master_data.drawing_category.manage - -- āļŠāļīāļ—āļ˜āļīāđŒāļ”āļđāļ‚āđ‰āļ­āļĄāļđāļĨāđƒāļ™āļŠāļąāļāļāļē - (6, 28), - -- contract.view - -- āļŠāļīāļ—āļ˜āļīāđŒāđƒāļ™āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ€āļ­āļāļŠāļēāļĢ (āļĢāļ°āļ”āļąāļš Editor) - (6, 29), - -- document.create_draft - (6, 30), - -- document.submit - (6, 31), - -- document.view - (6, 32), - -- document.edit - (6, 35), - -- document.attach - (6, 36), - -- correspondence.create - (6, 37), - -- rfa.create - (6, 39), - -- drawing.create - (6, 40), - -- transmittal.create - (6, 41), - -- circulation.create - (6, 38), - -- rfa.manage_shop_drawings - (6, 48), - -- search.advanced - (6, 49); - --- report.generate --- ===================================================== --- == 7. Contract Admin (role_id = 7) == --- ===================================================== -INSERT INTO role_permissions (role_id, permission_id) -VALUES -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢāļŠāļąāļāļāļē - (7, 27), - -- contract.manage_members - (7, 28), - -- contract.view - -- āļŠāļīāļ—āļ˜āļīāđŒāđƒāļ™āļāļēāļĢāļ­āļ™āļļāļĄāļąāļ•āļī (āļŠāđˆāļ§āļ™āļŦāļ™āļķāđˆāļ‡āļ‚āļ­āļ‡ Workflow) - (7, 45), - -- workflow.action_review - -- āļŠāļīāļ—āļ˜āļīāđŒāļˆāļąāļ”āļāļēāļĢāļ‚āđ‰āļ­āļĄāļđāļĨāđ€āļ‰āļžāļēāļ°āļŠāļąāļāļāļē - (7, 38), - -- rfa.manage_shop_drawings - (7, 39), - -- drawing.create - -- āļŠāļīāļ—āļ˜āļīāđŒāđƒāļ™āļāļēāļĢāļˆāļąāļ”āļāļēāļĢāđ€āļ­āļāļŠāļēāļĢ (āļĢāļ°āļ”āļąāļš Editor) - (7, 29), - -- document.create_draft - (7, 30), - -- document.submit - (7, 31), - -- document.view - (7, 32), - -- document.edit - (7, 35), - -- document.attach - (7, 36), - -- correspondence.create - (7, 37), - -- rfa.create - (7, 40), - -- transmittal.create - (7, 41), - -- circulation.create - (7, 48); - --- Seed data for the 'user_assignments' table -INSERT INTO `user_assignments` ( - `id`, - `user_id`, - `role_id`, - `organization_id`, - `project_id`, - `contract_id`, - `assigned_by_user_id` - ) -VALUES ( - 1, - 1, - 1, - NULL, - NULL, - NULL, - NULL - ), - (2, 2, 2, 1, NULL, NULL, NULL); - --- ===================================================== --- == 4. āļāļēāļĢāđ€āļŠāļ·āđˆāļ­āļĄāđ‚āļĒāļ‡āđ‚āļ„āļĢāļ‡āļāļēāļĢāļāļąāļšāļ­āļ‡āļ„āđŒāļāļĢ (project_organizations) == --- ===================================================== --- āđ‚āļ„āļĢāļ‡āļāļēāļĢāļŦāļĨāļąāļ (LCBP3) āļˆāļ°āļĄāļĩāļ­āļ‡āļ„āđŒāļāļĢāļŦāļĨāļąāļāđ† āđ€āļ‚āđ‰āļēāļĄāļēāđ€āļāļĩāđˆāļĒāļ§āļ‚āđ‰āļ­āļ‡āļ—āļąāđ‰āļ‡āļŦāļĄāļ” -INSERT INTO project_organizations (project_id, organization_id) -SELECT ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3' - ), - id -FROM organizations -WHERE organization_code IN ( - 'āļāļ—āļ—.', - 'āļŠāļ„āļ‰.3', - 'TEAM', - 'āļ„āļ„āļ‡.', - 'āļœāļĢāļĄ.1', - 'āļœāļĢāļĄ.2', - 'āļœāļĢāļĄ.3', - 'āļœāļĢāļĄ.4', - 'EN', - 'CAR' - ); - --- āđ‚āļ„āļĢāļ‡āļāļēāļĢāļĒāđˆāļ­āļĒ (LCBP3C1) āļˆāļ°āļĄāļĩāđ€āļ‰āļžāļēāļ°āļ­āļ‡āļ„āđŒāļāļĢāļ—āļĩāđˆāđ€āļāļĩāđˆāļĒāļ§āļ‚āđ‰āļ­āļ‡ -INSERT INTO project_organizations (project_id, organization_id) -SELECT ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3-C1' - ), - id -FROM organizations -WHERE organization_code IN ( - 'āļāļ—āļ—.', - 'āļŠāļ„āļ‰.3', - 'āļŠāļ„āļ‰.3 -02', - 'āļ„āļ„āļ‡.', - 'āļœāļĢāļĄ.1 ' - ); - --- āļ—āļģāđ€āļŠāđˆāļ™āđ€āļ”āļĩāļĒāļ§āļāļąāļ™āļŠāļģāļŦāļĢāļąāļšāđ‚āļ„āļĢāļ‡āļāļēāļĢāļ­āļ·āđˆāļ™āđ† (āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡) -INSERT INTO project_organizations (project_id, organization_id) -SELECT ( - SELECT id - FROM projects - WHERE project_code = 'LCBP3-C2' - ), - id -FROM organizations -WHERE organization_code IN ( - 'āļāļ—āļ—.', - 'āļŠāļ„āļ‰.3', - 'āļŠāļ„āļ‰.3 -03', - 'āļ„āļ„āļ‡.', - 'āļœāļĢāļĄ.2' - ); - --- ===================================================== --- == 5. āļāļēāļĢāđ€āļŠāļ·āđˆāļ­āļĄāđ‚āļĒāļ‡āļŠāļąāļāļāļēāļāļąāļšāļ­āļ‡āļ„āđŒāļāļĢ (contract_organizations) == --- ===================================================== --- āļŠāļąāļāļāļēāļ—āļĩāđˆāļ›āļĢāļķāļāļĐāļēāļ­āļ­āļāđāļšāļš (DSLCBP3) -INSERT INTO contract_organizations ( - contract_id, - organization_id, - role_in_contract - ) -VALUES ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-DS' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļāļ—āļ—.' - ), - 'Owner' - ), - ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-DS' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'TEAM' - ), - 'Designer' - ); - --- āļŠāļąāļāļāļēāļ—āļĩāđˆāļ›āļĢāļķāļāļĐāļēāļ„āļ§āļšāļ„āļļāļĄāļ‡āļēāļ™ (PSLCBP3) -INSERT INTO contract_organizations ( - contract_id, - organization_id, - role_in_contract - ) -VALUES ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-PS' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļāļ—āļ—.' - ), - 'Owner' - ), - ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-PS' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļ„āļ„āļ‡.' - ), - 'Consultant' - ); - --- āļŠāļąāļāļāļēāļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 1 (LCBP3-C1) -INSERT INTO contract_organizations ( - contract_id, - organization_id, - role_in_contract - ) -VALUES ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-C1' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļāļ—āļ—.' - ), - 'Owner' - ), - ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-C1' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļœāļĢāļĄ.1' - ), - 'Contractor' - ); - --- āļŠāļąāļāļāļēāļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ āļŠāđˆāļ§āļ™āļ—āļĩāđˆ 2 (LCBP3-C2) -INSERT INTO contract_organizations ( - contract_id, - organization_id, - role_in_contract - ) -VALUES ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-C2' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļāļ—āļ—.' - ), - 'Owner' - ), - ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-C2' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļœāļĢāļĄ.2' - ), - 'Contractor' - ); - --- āļŠāļąāļāļāļēāļ•āļĢāļ§āļˆāļŠāļ­āļšāļŠāļīāđˆāļ‡āđāļ§āļ”āļĨāđ‰āļ­āļĄ (LCBP3-EN) -INSERT INTO contract_organizations ( - contract_id, - organization_id, - role_in_contract - ) -VALUES ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-EN' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'āļāļ—āļ—.' - ), - 'Owner' - ), - ( - ( - SELECT id - FROM contracts - WHERE contract_code = 'LCBP3-EN' - ), - ( - SELECT id - FROM organizations - WHERE organization_code = 'EN' - ), - 'Consultant' - ); - --- Seed correspondence_status -INSERT INTO correspondence_status ( - status_code, - status_name, - sort_order, - is_active - ) -VALUES ('DRAFT', 'Draft', 10, 1), - ( - 'SUBOWN', - 'Submitted to Owner', - 21, - 1 - ), - ( - 'SUBDSN', - 'Submitted to Designer', - 22, - 1 - ), - ( - 'SUBCSC', - 'Submitted to CSC', - 23, - 1 - ), - ( - 'SUBCON', - 'Submitted to Contractor', - 24, - 1 - ), - ( - 'SUBOTH', - 'Submitted to Others', - 25, - 1 - ), - ( - 'REPOWN', - 'Reply by Owner', - 31, - 1 - ), - ( - 'REPDSN', - 'Reply by Designer', - 32, - 1 - ), - ('REPCSC', 'Reply by CSC', 33, 1), - ( - 'REPCON', - 'Reply by Contractor', - 34, - 1 - ), - ( - 'REPOTH', - 'Reply by Others', - 35, - 1 - ), - ( - 'RSBOWN', - 'Resubmited by Owner', - 41, - 1 - ), - ( - 'RSBDSN', - 'Resubmited by Designer', - 42, - 1 - ), - ( - 'RSBCSC', - 'Resubmited by CSC', - 43, - 1 - ), - ( - 'RSBCON', - 'Resubmited by Contractor', - 44, - 1 - ), - ( - 'CLBOWN', - 'Closed by Owner', - 51, - 1 - ), - ( - 'CLBDSN', - 'Closed by Designer', - 52, - 1 - ), - ('CLBCSC', 'Closed by CSC', 53, 1), - ( - 'CLBCON', - 'Closed by Contractor', - 54, - 1 - ), - ( - 'CCBOWN', - 'Canceled by Owner', - 91, - 1 - ), - ( - 'CCBDSN', - 'Canceled by Designer', - 92, - 1 - ), - ( - 'CCBCSC', - 'Canceled by CSC', - 93, - 1 - ), - ( - 'CCBCON', - 'Canceled by Contractor', - 94, - 1 - ); - --- Seed correspondence_types -INSERT INTO correspondence_types ( - type_code, - type_name, - sort_order, - is_active - ) -VALUES ( - 'RFA', - 'Request for Approval', - 1, - 1 - ), - ( - 'RFI', - 'Request for Information', - 2, - 1 - ), - ( - 'TRANSMITTAL', - 'Transmittal', - 3, - 1 - ), - ('EMAIL', 'Email', 4, 1), - ( - 'INSTRUCTION', - 'Instruction', - 5, - 1 - ), - ('LETTER', 'Letter', 6, 1), - ('MEMO', 'Memorandum', 7, 1), - ( - 'MOM', - 'Minutes of Meeting', - 8, - 1 - ), - ('NOTICE', 'Notice', 9, 1), - ('OTHER', 'Other', 10, 1); - --- Seed rfa_types -INSERT INTO rfa_types ( - contract_id, - type_code, - type_name_en, - type_name_th - ) -SELECT id, - 'ADW', - 'As Built Drawing', - 'āđāļšāļšāļĢāđˆāļēāļ‡āļŦāļĨāļąāļ‡āļāļēāļĢāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'BC', - 'Box Culvert', - 'āļ—āđˆāļ­āļĢāļ°āļšāļēāļĒāļ™āđ‰āļģāļĢāļđāļ›āļāļĨāđˆāļ­āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'BM', - 'Benchmark', - 'āļŦāļĄāļļāļ”āļŦāļĨāļąāļāļāļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'CER', - 'Certificates', - 'āđƒāļšāļĢāļąāļšāļĢāļ­āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'CN', - 'Canal Drainage', - 'āļĢāļ°āļšāļšāļĢāļ°āļšāļēāļĒāļ™āđ‰āļģāđƒāļ™āļ„āļĨāļ­āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'CON', - 'Contract', - 'āļŠāļąāļāļāļē' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'DDS', - 'Design Data Submission', - 'āļ™āļģāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāļāļēāļĢāļ­āļ­āļāđāļšāļš' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'DDW', - 'Draft Drawing', - 'āđāļšāļšāļĢāđˆāļēāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'DRW', - 'Drawings (All Types)', - 'āđāļšāļšāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'DSN', - 'Design/Calculation/Manual (All Stages)', - 'āļ­āļ­āļāđāļšāļš / āļ„āļģāļ™āļ§āļ“ / āļ„āļđāđˆāļĄāļ·āļ­' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'GEN', - 'General', - 'āļ—āļąāđˆāļ§āđ„āļ›' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'ICR', - 'Incident Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāđ€āļāļīāļ”āļ­āļļāļšāļąāļ•āļīāđ€āļŦāļ•āļļāđāļĨāļ°āļāļēāļĢāļšāļēāļ”āđ€āļˆāđ‡āļš' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'INS', - 'Insurances/Bond/Guarantee', - 'āļāļēāļĢāļ›āļĢāļ°āļāļąāļ™ / āļžāļąāļ™āļ˜āļšāļąāļ•āļĢ / āļāļēāļĢāļ„āđ‰āļģāļ›āļĢāļ°āļāļąāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'INR', - 'Inspection/Audit/Surveillance Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļš / āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļš / āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāđ€āļāđ‰āļēāļĢāļ°āļ§āļąāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'ITP', - 'Inspection and Test Plan', - 'āđāļœāļ™āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļšāđāļĨāļ°āļ—āļ”āļŠāļ­āļš' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'JSA', - 'Jobs Analysis', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļ§āļīāđ€āļ„āļĢāļēāļ°āļŦāđŒāļ„āļ§āļēāļĄāļ›āļĨāļ­āļ”āļ āļąāļĒ' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'MAN', - 'Manual', - 'āļ„āļđāđˆāļĄāļ·āļ­' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'MAT', - 'Materials/Equipment/Plant', - 'āļ§āļąāļŠāļ”āļļ / āļ­āļļāļ›āļāļĢāļ“āđŒ / āđ‚āļĢāļ‡āļ‡āļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'MOM', - 'Minutes of Meeting', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļ›āļĢāļ°āļŠāļļāļĄ' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'MPR', - 'Monthly Progress Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļ„āļ§āļēāļĄāļ„āļ·āļšāļŦāļ™āđ‰āļēāļ›āļĢāļ°āļˆāļģāđ€āļ”āļ·āļ­āļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'MST', - 'Method Statement for Construction/Installation', - 'āļ‚āļąāđ‰āļ™āļ•āļ­āļ™āļāļēāļĢāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ / āļ•āļīāļ”āļ•āļąāđ‰āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'NDS', - 'Non-Design Data Submission', - 'āļ™āļģāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāļ—āļĩāđˆāđ„āļĄāđˆāđ€āļāļĩāđˆāļĒāļ§āļ‚āđ‰āļ­āļ‡āļāļąāļšāļāļēāļĢāļ­āļ­āļāđāļšāļš' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'PMA', - 'Payment/Invoice/Retention/Estimate', - 'āļāļēāļĢāļŠāļģāļĢāļ°āđ€āļ‡āļīāļ™ / āđƒāļšāđāļˆāđ‰āļ‡āļŦāļ™āļĩāđ‰ / āļ›āļĢāļ°āļāļąāļ™āļœāļĨāļ‡āļēāļ™ / āļ›āļĢāļ°āļĄāļēāļ“āļāļēāļĢ' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'PRD', - 'Procedure', - 'āļĢāļ°āđ€āļšāļĩāļĒāļšāļ›āļāļīāļšāļąāļ•āļī' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'PRG', - 'Progress of Construction', - 'āļ„āļ§āļēāļĄāļ„āļ·āļšāļŦāļ™āđ‰āļēāļ‚āļ­āļ‡āļāļēāļĢāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ / āļ āļēāļžāļ–āđˆāļēāļĒ / āļ§āļīāļ”āļĩāđ‚āļ­' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'QMS', - 'Quality Document (Plan/Work Instruction)', - 'āđ€āļ­āļāļŠāļēāļĢāļ”āđ‰āļēāļ™āļ„āļļāļ“āļ āļēāļž (āđāļœāļ™āļ‡āļēāļ™ / āļ‚āđ‰āļ­āđāļ™āļ°āļ™āļģāđƒāļ™āļāļēāļĢāļ—āļģāļ‡āļēāļ™)' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'RPT', - 'Report', - 'āļĢāļēāļĒāļ‡āļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SAR', - 'Semi Annual Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļ›āļĢāļ°āļˆāļģāļŦāļāđ€āļ”āļ·āļ­āļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SCH', - 'Schedule and Program', - 'āđāļœāļ™āļ‡āļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SDW', - 'Shop Drawing', - 'āđāļšāļšāļ‚āļĒāļēāļĒāļĢāļēāļĒāļĨāļ°āđ€āļ­āļĩāļĒāļ”' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SI', - 'Soil Investigation', - 'āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļšāļ”āļīāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SPE', - 'Specification', - 'āļ‚āđ‰āļ­āļāļģāļŦāļ™āļ”' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'TNR', - 'Training Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļāļķāļāļ›āļāļīāļšāļąāļ•āļī' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'UC', - 'Underground Construction', - 'āđ‚āļ„āļĢāļ‡āļŠāļĢāđ‰āļēāļ‡āđƒāļ•āđ‰āļ”āļīāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'VEN', - 'Vendor', - 'āļœāļđāđ‰āļ‚āļēāļĒ' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'VRO', - 'Variation Request/Instruction/Order', - 'āļ„āļģāļ‚āļ­āđ€āļ›āļĨāļĩāđˆāļĒāļ™āđāļ›āļĨāļ‡ / āļ‚āđ‰āļ­āđ€āļŠāļ™āļ­āđāļ™āļ° / āļ‚āđ‰āļ­āđ€āļĢāļĩāļĒāļāļĢāđ‰āļ­āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'WTY', - 'Warranty', - 'āļāļēāļĢāļ›āļĢāļ°āļāļąāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'GEN', - 'General', - 'āļ—āļąāđˆāļ§āđ„āļ›' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'CON', - 'Contract', - 'āļŠāļąāļāļāļē' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'INS', - 'Insurances/Bond/Guarantee', - 'āļāļēāļĢāļ›āļĢāļ°āļāļąāļ™ / āļžāļąāļ™āļ˜āļšāļąāļ•āļĢ / āļāļēāļĢāļ„āđ‰āļģāļ›āļĢāļ°āļāļąāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SCH', - 'Schedule and Program', - 'āđāļœāļ™āļ‡āļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'PMA', - 'Payment/Invoice/Retention/Estimate', - 'āļāļēāļĢāļŠāļģāļĢāļ°āđ€āļ‡āļīāļ™ / āđƒāļšāđāļˆāđ‰āļ‡āļŦāļ™āļĩāđ‰ / āļ›āļĢāļ°āļāļąāļ™āļœāļĨāļ‡āļēāļ™ / āļ›āļĢāļ°āļĄāļēāļ“āļāļēāļĢ' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'VRO', - 'Variation Request/Instruction/Order', - 'āļ„āļģāļ‚āļ­āđ€āļ›āļĨāļĩāđˆāļĒāļ™āđāļ›āļĨāļ‡ / āļ‚āđ‰āļ­āđ€āļŠāļ™āļ­āđāļ™āļ° / āļ‚āđ‰āļ­āđ€āļĢāļĩāļĒāļāļĢāđ‰āļ­āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'VEN', - 'Vendor', - 'āļœāļđāđ‰āļ‚āļēāļĒ' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'WTY', - 'Warranty', - 'āļāļēāļĢāļ›āļĢāļ°āļāļąāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'DRW', - 'Drawings (All Types)', - 'āđāļšāļšāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'DDW', - 'Draft Drawing', - 'āđāļšāļšāļĢāđˆāļēāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SDW', - 'Shop Drawing', - 'āđāļšāļšāļ‚āļĒāļēāļĒāļĢāļēāļĒāļĨāļ°āđ€āļ­āļĩāļĒāļ”' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ADW', - 'As Built Drawing', - 'āđāļšāļšāļĢāđˆāļēāļ‡āļŦāļĨāļąāļ‡āļāļēāļĢāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'DDS', - 'Design Data Submission', - 'āļ™āļģāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāļāļēāļĢāļ­āļ­āļāđāļšāļš' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'DSN', - 'Design/Calculation/Manual (All Stages)', - 'āļ­āļ­āļāđāļšāļš / āļ„āļģāļ™āļ§āļ“ / āļ„āļđāđˆāļĄāļ·āļ­' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'NDS', - 'Non-Design Data Submission', - 'āļ™āļģāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāļ—āļĩāđˆāđ„āļĄāđˆāđ€āļāļĩāđˆāļĒāļ§āļ‚āđ‰āļ­āļ‡āļāļąāļšāļāļēāļĢāļ­āļ­āļāđāļšāļš' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'PRD', - 'Procedure', - 'āļĢāļ°āđ€āļšāļĩāļĒāļšāļ›āļāļīāļšāļąāļ•āļī' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MST', - 'Method Statement for Construction/Installation', - 'āļ‚āļąāđ‰āļ™āļ•āļ­āļ™āļāļēāļĢāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ / āļ•āļīāļ”āļ•āļąāđ‰āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'QMS', - 'Quality Document (Plan/Work Instruction)', - 'āđ€āļ­āļāļŠāļēāļĢāļ”āđ‰āļēāļ™āļ„āļļāļ“āļ āļēāļž (āđāļœāļ™āļ‡āļēāļ™ / āļ‚āđ‰āļ­āđāļ™āļ°āļ™āļģāđƒāļ™āļāļēāļĢāļ—āļģāļ‡āļēāļ™)' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'INR', - 'Inspection/Audit/Surveillance Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļš / āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļš / āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāđ€āļāđ‰āļēāļĢāļ°āļ§āļąāļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ITP', - 'Inspection and Test Plan', - 'āđāļœāļ™āļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļšāđāļĨāļ°āļ—āļ”āļŠāļ­āļš' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MAT', - 'Materials/Equipment/Plant', - 'āļ§āļąāļŠāļ”āļļ / āļ­āļļāļ›āļāļĢāļ“āđŒ / āđ‚āļĢāļ‡āļ‡āļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SPE', - 'Specification', - 'āļ‚āđ‰āļ­āļāļģāļŦāļ™āļ”' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MAN', - 'Manual', - 'āļ„āļđāđˆāļĄāļ·āļ­' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'CER', - 'Certificates', - 'āđƒāļšāļĢāļąāļšāļĢāļ­āļ‡' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SAR', - 'Semi Annual Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļ›āļĢāļ°āļˆāļģāļŦāļāđ€āļ”āļ·āļ­āļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'JSA', - 'Jobs Analysis', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļ§āļīāđ€āļ„āļĢāļēāļ°āļŦāđŒāļ„āļ§āļēāļĄāļ›āļĨāļ­āļ”āļ āļąāļĒ' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MOM', - 'Minutes of Meeting', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļ›āļĢāļ°āļŠāļļāļĄ' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MPR', - 'Monthly Progress Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļ„āļ§āļēāļĄāļ„āļ·āļšāļŦāļ™āđ‰āļēāļ›āļĢāļ°āļˆāļģāđ€āļ”āļ·āļ­āļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ICR', - 'Incident Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāđ€āļāļīāļ”āļ­āļļāļšāļąāļ•āļīāđ€āļŦāļ•āļļāđāļĨāļ°āļāļēāļĢāļšāļēāļ”āđ€āļˆāđ‡āļš' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'PRG', - 'Progress of Construction', - 'āļ„āļ§āļēāļĄāļ„āļ·āļšāļŦāļ™āđ‰āļēāļ‚āļ­āļ‡āļāļēāļĢāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡ / āļ āļēāļžāļ–āđˆāļēāļĒ / āļ§āļīāļ”āļĩāđ‚āļ­' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'RPT', - 'Report', - 'āļĢāļēāļĒāļ‡āļēāļ™' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'TNR', - 'Training Report', - 'āļĢāļēāļĒāļ‡āļēāļ™āļāļēāļĢāļāļķāļāļ›āļāļīāļšāļąāļ•āļī' -FROM contracts -WHERE contract_code = 'LCBP3-C2'; - --- Seed rfa_status_codes -INSERT INTO rfa_status_codes ( - status_code, - status_name, - description, - sort_order - ) -VALUES ('DFT', 'Draft', 'āļ‰āļšāļąāļšāļĢāđˆāļēāļ‡', 1), - ( - 'FAP', - 'For Approve', - 'āđ€āļžāļ·āđˆāļ­āļ‚āļ­āļ­āļ™āļļāļĄāļąāļ•āļī', - 11 - ), - ( - 'FRE', - 'For Review', - 'āđ€āļžāļ·āđˆāļ­āļ•āļĢāļ§āļˆāļŠāļ­āļš', - 12 - ), - ( - 'FCO', - 'For Construction', - 'āđ€āļžāļ·āđˆāļ­āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡', - 20 - ), - ( - 'ASB', - 'AS - Built', - 'āđāļšāļšāļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļˆāļĢāļīāļ‡', - 30 - ), - ( - 'OBS', - 'Obsolete', - 'āđ„āļĄāđˆāđƒāļŠāđ‰āļ‡āļēāļ™', - 80 - ), - ('CC', 'Canceled', 'āļĒāļāđ€āļĨāļīāļ', 99); - -INSERT INTO rfa_approve_codes ( - approve_code, - approve_name, - sort_order, - is_active - ) -VALUES ( - '1A', - 'Approved by Authority', - 10, - 1 - ), - ('1C', 'Approved by CSC', 11, 1), - ('1N', 'Approved As Note', 12, 1), - ( - '1R', - 'Approved with Remarks', - 13, - 1 - ), - ( - '3C', - 'Consultant Comments', - 31, - 1 - ), - ( - '3R', - 'Revise - and Resubmit', - 32, - 1 - ), - ('4X', 'Reject', 40, 1), - ('5N', 'No Further Action', 50, 1); - --- Seed circulation_status_codes -INSERT INTO circulation_status_codes (code, description, sort_order) -VALUES ('OPEN', 'Open', 1), - ('IN_REVIEW', 'In Review', 2), - ('COMPLETED', 'āļ›Completed', 3), - ( - 'CANCELLED', - 'Cancelled / Withdrawn', - 9 - ); - --- āļ•āļēāļĢāļēāļ‡ "āđāļĄāđˆ" āļ‚āļ­āļ‡ RFA (āļĄāļĩāļ„āļ§āļēāļĄāļŠāļąāļĄāļžāļąāļ™āļ˜āđŒ 1:N āļāļąāļš rfa_revisions) --- ========================================================== --- SEED DATA 6B.md (Disciplines, RFA Types, Sub Types) --- ========================================================== --- 1. Seed āļ‚āđ‰āļ­āļĄāļđāļĨ Disciplines (āļŠāļēāļ‚āļēāļ‡āļēāļ™) --- LCBP3-C1 -INSERT INTO disciplines ( - contract_id, - discipline_code, - code_name_th, - code_name_en - ) -SELECT id, - 'GEN', - 'āļ‡āļēāļ™āļšāļĢāļīāļŦāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢ', - 'General Management' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'COD', - 'āļŠāļąāļāļāļēāđāļĨāļ°āļ‚āđ‰āļ­āđ‚āļ•āđ‰āđāļĒāđ‰āļ‡', - 'Contracting' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'QSB', - 'āļŠāļģāļĢāļ§āļˆāļ›āļĢāļīāļĄāļēāļ“āđāļĨāļ°āļ„āļ§āļšāļ„āļļāļĄāļ‡āļšāļ›āļĢāļ°āļĄāļēāļ“', - 'Quantity Survey and Budget Control' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'PPG', - 'āļšāļĢāļīāļŦāļēāļĢāđāļœāļ™āđāļĨāļ°āļ„āļ§āļēāļĄāļāđ‰āļēāļ§āļŦāļ™āđ‰āļē', - 'Plan and Progress Management' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'PRC', - 'āļ‡āļēāļ™āļˆāļąāļ”āļ‹āļ·āđ‰āļ­', - 'Procurement' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SUB', - 'āļœāļđāđ‰āļĢāļąāļšāđ€āļŦāļĄāļēāļŠāđˆāļ§āļ‡', - 'Subcontractor' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'ODC', - 'āļŠāļģāļ™āļąāļāļ‡āļēāļ™-āļ„āļ§āļšāļ„āļļāļĄāđ€āļ­āļāļŠāļēāļĢ', - 'Operation Docment Control' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'LAW', - 'āļāļŽāļŦāļĄāļēāļĒ', - 'Law' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'TRF', - 'āļˆāļĢāļēāļˆāļĢ', - 'Traffic' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'BIM', - 'BIM', - 'Building information modeling' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SRV', - 'āļ‡āļēāļ™āļŠāļģāļĢāļ§āļˆ', - 'Survey' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SFT', - 'āļ„āļ§āļēāļĄāļ›āļĨāļ­āļ”āļ āļąāļĒ', - 'Safety' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'BST', - 'āļ‡āļēāļ™āđ‚āļ„āļĢāļ‡āļŠāļĢāđ‰āļēāļ‡āļ­āļēāļ„āļēāļĢ', - 'Building Structure Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'TEM', - 'āļ‡āļēāļ™āļŠāļąāđˆāļ§āļ„āļĢāļēāļ§', - 'Temporary Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'UTL', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāļŠāļēāļ˜āļēāļĢāļ“āļđāļ›āđ‚āļ āļ„', - 'Utility' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'EPW', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāđ„āļŸāļŸāđ‰āļē', - 'Electrical Power Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'ECM', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāđ„āļŸāļŸāđ‰āļēāļŠāļ·āđˆāļ­āļŠāļēāļĢ', - 'Electrical Communication Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'ENV', - 'āļŠāļīāđˆāļ‡āđāļ§āļ”āļĨāđ‰āļ­āļĄ', - 'Environment' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'AQV', - 'āļ„āļļāļ“āļ āļēāļžāļ­āļēāļāļēāļĻāđāļĨāļ°āļ„āļ§āļēāļĄāļŠāļąāđˆāļ™āļŠāļ°āđ€āļ—āļ·āļ­āļ™', - 'Air quality and vibration' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'WAB', - 'āļ„āļļāļ“āļ āļēāļžāļ™āđ‰āļģāđāļĨāļ°āļŠāļĩāļ§āļ§āļīāļ—āļĒāļēāļ—āļēāļ‡āļ™āđ‰āļģ', - 'Water quality and Aquatic biology' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'ONS', - 'āļ§āļīāļĻāļ§āļāļĢāļĢāļĄāļŠāļēāļĒāļāļąāđˆāļ‡', - 'Onshore Engineer Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'PPR', - 'āļĄāļ§āļĨāļŠāļ™āļŠāļąāļĄāļžāļąāļ™āļ˜āđŒāđāļĨāļ°āļāļēāļĢāļ›āļĢāļ°āļŠāļēāļŠāļąāļĄāļžāļąāļ™āļ˜āđŒ', - 'Public Relations' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'OSW', - 'āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ‡āļēāļ™āļ—āļēāļ‡āļ—āļ°āđ€āļĨ', - 'Offshore Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'DRE', - 'āļ‡āļēāļ™āļ‚āļļāļ”āđāļĨāļ°āļ–āļĄāļ—āļ°āđ€āļĨ', - 'Dredging and Reclamation' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'REV', - 'āļ‡āļēāļ™āļ„āļąāļ™āļŦāļīāļ™āļĨāđ‰āļ­āļĄāļžāļ·āđ‰āļ™āļ—āļĩāđˆāļ–āļĄāļ—āļ°āđ€āļĨ', - 'Revetment' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'BRW', - 'āļ‡āļēāļ™āđ€āļ‚āļ·āđˆāļ­āļ™āļāļąāļ™āļ„āļĨāļ·āđˆāļ™', - 'Breakwater' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SOI', - 'āļ›āļĢāļąāļšāļ›āļĢāļļāļ‡āļ„āļļāļ“āļ āļēāļžāļ”āļīāļ™', - 'Soil Improvement' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'BLC', - 'āļ‡āļēāļ™āļ›āļĢāļąāļšāļ›āļĢāļļāļ‡āļ„āļĨāļ­āļ‡āļšāļēāļ‡āļĨāļ°āļĄāļļāļ‡', - 'Bang Lamung Canal Bank Protection' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'FUP', - 'āļ‡āļēāļ™āļ›āļĢāļ°āļ•āļđāļĢāļ°āļšāļēāļĒāļ™āđ‰āļģāđāļĨāļ°āļ—āđˆāļ­āļĨāļ­āļ”', - 'Floodgate & Under Ground Piping Works' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'SWP', - 'āļ‡āļēāļ™āļ­āļēāļ„āļēāļĢāļ„āļ§āļšāļ„āļļāļĄāļŠāļ–āļēāļ™āļĩāļŠāļđāļšāļ™āđ‰āļģāļ—āļ°āđ€āļĨ', - 'Sea Water Pumping Station Control BuilDing' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'NAV', - 'āļ‡āļēāļ™āļ•āļīāļ”āļ•āļąāđ‰āļ‡āđ€āļ„āļĢāļ·āđˆāļ­āļ‡āļŦāļĄāļēāļĒāļŠāđˆāļ§āļ‡āļāļēāļĢāđ€āļ”āļīāļ™āđ€āļĢāļ·āļ­', - 'Navigations Aids' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'GEO', - 'āļ‡āļēāļ™āļ”āđ‰āļēāļ™āļ˜āļĢāļ“āļĩāđ€āļ—āļ„āļ™āļīāļ„', - 'Geotechnical' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'CRW', - 'āļ‡āļēāļ™āļ”āđ‰āļēāļ™āđ‚āļĒāļ˜āļē - Rock Works', - 'Civil-Rock work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'DVR', - 'āļ—āļĩāļĄāļ™āļąāļāļ›āļĢāļ°āļ”āļēāļ™āđ‰āļģ', - 'Dive Work' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'MTS', - 'āļ‡āļēāļ™āļ—āļ”āļŠāļ­āļšāļ§āļąāļŠāļ”āļļāđāļĨāļ°āļ˜āļĢāļ“āļĩāđ€āļ—āļ„āļ™āļīāļ„', - 'Materials and Geotechnical Testing' -FROM contracts -WHERE contract_code = 'LCBP3-C1' -UNION ALL -SELECT id, - 'OTH', - 'āļ­āļ·āđˆāļ™āđ†', - 'Other' -FROM contracts -WHERE contract_code = 'LCBP3-C1'; - --- LCBP3-C2 -INSERT INTO disciplines ( - contract_id, - discipline_code, - code_name_th, - code_name_en - ) -SELECT id, - 'GEN', - 'āļ‡āļēāļ™āļšāļĢāļīāļŦāļēāļĢāđ‚āļ„āļĢāļ‡āļāļēāļĢ', - 'Project Management' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'COD', - 'āļŠāļąāļāļāļēāđāļĨāļ°āļ‚āđ‰āļ­āđ‚āļ•āđ‰āđāļĒāđ‰āļ‡', - 'Contracts and arguments' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'QSB', - 'āļŠāļģāļĢāļ§āļˆāļ›āļĢāļīāļĄāļēāļ“āđāļĨāļ°āļ„āļ§āļšāļ„āļļāļĄāļ‡āļšāļ›āļĢāļ°āļĄāļēāļ“', - 'Survey the quantity and control the budget' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'PPM', - 'āļšāļĢāļīāļŦāļēāļĢāđāļœāļ™āđāļĨāļ°āļ„āļ§āļēāļĄāļāđ‰āļēāļ§āļŦāļ™āđ‰āļē', - 'Plan Management & Progress' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ODC', - 'āļŠāļģāļ™āļąāļāļ‡āļēāļ™-āļ„āļ§āļšāļ„āļļāļĄāđ€āļ­āļāļŠāļēāļĢ', - 'Document Control Office' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'LAW', - 'āļāļŽāļŦāļĄāļēāļĒ', - 'Law' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'TRF', - 'āļˆāļĢāļēāļˆāļĢ', - 'Traffic' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'BIM', - 'Building Information Modeling', - 'Building Information Modeling' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SRV', - 'āļ‡āļēāļ™āļŠāļģāļĢāļ§āļˆ', - 'Survey' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SFT', - 'āļ„āļ§āļēāļĄāļ›āļĨāļ­āļ”āļ āļąāļĒ', - 'Safety' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'BST', - 'āļ‡āļēāļ™āđ‚āļ„āļĢāļ‡āļŠāļĢāđ‰āļēāļ‡āļ­āļēāļ„āļēāļĢ', - 'Building Structure' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'UTL', - 'āļ‡āļēāļ™āļ°āļšāļšāļŠāļēāļ˜āļēāļĢāļ“āļđāļ›āđ‚āļ āļ„', - 'Public Utilities' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'EPW', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāđ„āļŸāļŸāđ‰āļē', - 'Electrical Systems' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ECM', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāđ„āļŸāļŸāđ‰āļēāļŠāļ·āđˆāļ­āļŠāļēāļĢ', - 'Electrical Communication System' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ENV', - 'āļŠāļīāđˆāļ‡āđāļ§āļ”āļĨāđ‰āļ­āļĄ', - 'Environment' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'AQV', - 'āļ„āļļāļ“āļ āļēāļžāļ­āļēāļāļēāļĻāđāļĨāļ°āļ„āļ§āļēāļĄāļŠāļąāđˆāļ™āļŠāļ°āđ€āļ—āļ·āļ­āļ™', - 'Air Quality and Vibration' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'WAB', - 'āļ„āļļāļ“āļ āļēāļžāļ™āđ‰āļģāđāļĨāļ°āļŠāļĩāļ§āļ§āļīāļ—āļĒāļēāļ—āļēāļ‡āļ™āđ‰āļģ', - 'Water Quality and Aquatic Biology' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ONS', - 'āļ§āļīāļĻāļ§āļāļĢāļĢāļĄāļŠāļēāļĒāļāļąāđˆāļ‡', - 'Coastal Engineering' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'PPR', - 'āļĄāļ§āļĨāļŠāļ™āļŠāļąāļĄāļžāļąāļ™āļ˜āđŒāđāļĨāļ°āļ›āļĢāļ°āļŠāļēāļŠāļąāļĄāļžāļąāļ™āļ˜āđŒ', - 'Mass Relations and Public Relations' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'OFW', - 'āļ‡āļēāļ™āļāđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļ—āļēāļ‡āļ—āļ°āđ€āļĨ', - 'Marine Construction' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'EXR', - 'āļ‡āļēāļ™āļ‚āļļāļ”āđāļĨāļ°āļ–āļĄāļ—āļ°āđ€āļĨ', - 'Excavation and reclamation' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'GEO', - 'āļ‡āļēāļ™āļ”āđ‰āļēāļ™āļ˜āļĢāļ“āļĩāđ€āļ—āļ„āļ™āļīāļ„', - 'Geotechnical work' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'CRW', - 'āļ‡āļēāļ™āļ”āđ‰āļēāļ™āđ‚āļĒāļ˜āļē - Rock Works', - 'Civil Works - Rock Works' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'DVW', - 'āļ—āļĩāļĄāļ™āļąāļāļ›āļĢāļ°āļ”āļēāļ™āđ‰āļģ', - 'Team of Divers' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MTT', - 'āļ‡āļēāļ™āļ—āļ”āļŠāļ­āļšāļ§āļąāļŠāļ”āļļ', - 'Materials Testing' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ARC', - 'āļ‡āļēāļ™āļŠāļ–āļēāļ›āļąāļ•āļĒāļāļĢāļĢāļĄ', - 'Architecture' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'STR', - 'āļ‡āļēāļ™āđ‚āļ„āļĢāļ‡āļŠāļĢāđ‰āļēāļ‡', - 'Structural work' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'SAN', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāļŠāļļāļ‚āļēāļ āļīāļšāļēāļĨ', - 'Sanitation System' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'DRA', - 'āļ‡āļēāļ™āļĢāļ°āļšāļšāļĢāļ°āļšāļēāļĒāļ™āđ‰āļģ', - 'Drainage system work' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'TER', - 'āļ‡āļēāļ™āļ—āđˆāļēāđ€āļ—āļĩāļĒāļšāđ€āļĢāļ·āļ­', - 'Terminal Work work' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'BUD', - 'āļ‡āļēāļ™āļ­āļēāļ„āļēāļĢ', - 'Building' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'ROW', - 'āļ‡āļēāļ™āļ–āļ™āļ™āđāļĨāļ°āļŠāļ°āļžāļēāļ™', - 'Road and Bridge Work' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'MEC', - 'āļ‡āļēāļ™āđ€āļ„āļĢāļīāļ­āļ‡āļāļĨ', - 'Mechanical work' -FROM contracts -WHERE contract_code = 'LCBP3-C2' -UNION ALL -SELECT id, - 'OTH', - 'āļ­āļ·āđˆāļ™ āđ†', - 'Others' -FROM contracts -WHERE contract_code = 'LCBP3-C2'; - --- 2. Seed āļ‚āđ‰āļ­āļĄāļđāļĨ Correspondence Sub Types (Mapping RFA Types āļāļąāļš Number) --- āđ€āļ™āļ·āđˆāļ­āļ‡āļˆāļēāļ sub_type_code āļ•āļĢāļ‡āļāļąāļš RFA Type Code āđāļ•āđˆ Req āļ•āđ‰āļ­āļ‡āļāļēāļĢ Mapping āđ€āļ›āđ‡āļ™ Number --- LCBP3-C1 --- LCBP3-C1 -INSERT INTO correspondence_sub_types ( - contract_id, - correspondence_type_id, - sub_type_code, - sub_type_name, - sub_type_number - ) -SELECT c.id, - ct.id, - 'MAT', - 'Material Approval', - '11' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C1' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'SHP', - 'Shop Drawing Submittal', - '12' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C1' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'DWG', - 'Document Approval', - '13' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C1' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'MET', - 'Engineering Document Submittal', - '14' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C1' - AND ct.type_code = 'RFA'; - --- LCBP3-C2 -INSERT INTO correspondence_sub_types ( - contract_id, - correspondence_type_id, - sub_type_code, - sub_type_name, - sub_type_number - ) -SELECT c.id, - ct.id, - 'MAT', - 'Material Approval', - '21' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C2' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'SHP', - 'Shop Drawing Submittal', - '22' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C2' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'DWG', - 'Document Approval', - '23' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C2' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'MET', - 'Engineering Document Submittal', - '24' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C2' - AND ct.type_code = 'RFA'; - --- LCBP3-C3 -INSERT INTO correspondence_sub_types ( - contract_id, - correspondence_type_id, - sub_type_code, - sub_type_name, - sub_type_number - ) -SELECT c.id, - ct.id, - 'MAT', - 'Material Approval', - '31' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C3' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'SHP', - 'Shop Drawing Submittal', - '32' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C3' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'DWG', - 'Document Approval', - '33' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C3' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'MET', - 'Engineering Document Submittal', - '34' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C3' - AND ct.type_code = 'RFA'; - --- LCBP3-C4 -INSERT INTO correspondence_sub_types ( - contract_id, - correspondence_type_id, - sub_type_code, - sub_type_name, - sub_type_number - ) -SELECT c.id, - ct.id, - 'MAT', - 'Material Approval', - '41' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C4' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'SHP', - 'Shop Drawing Submittal', - '42' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C4' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'DWG', - 'Document Approval', - '43' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C4' - AND ct.type_code = 'RFA' -UNION ALL -SELECT c.id, - ct.id, - 'MET', - 'Engineering Document Submittal', - '44' -FROM contracts c, - correspondence_types ct -WHERE c.contract_code = 'LCBP3-C4' - AND ct.type_code = 'RFA'; diff --git a/specs/07-database/lcbp3-v1.5.1-schema.sql b/specs/07-database/lcbp3-v1.5.1-schema.sql index b8458db..da53d28 100644 --- a/specs/07-database/lcbp3-v1.5.1-schema.sql +++ b/specs/07-database/lcbp3-v1.5.1-schema.sql @@ -2,7 +2,7 @@ -- DMS v1.5.1 Document Management System Database -- Deploy Script Schema -- Server: Container Station on QNAP TS-473A --- Database service: MariaDB 10.11 +-- Database service: MariaDB 11.8 -- database web ui: phpmyadmin 5-apache -- database development ui: DBeaver -- backend service: NestJS @@ -190,6 +190,8 @@ DROP TABLE IF EXISTS contracts; DROP TABLE IF EXISTS projects; +DROP TABLE IF EXISTS refresh_tokens; + DROP TABLE IF EXISTS users; -- Referenced by user_preferences, audit_logs, etc. @@ -268,6 +270,18 @@ CREATE TABLE users ( SET NULL ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'āļ•āļēāļĢāļēāļ‡ Master āđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨāļœāļđāđ‰āđƒāļŠāđ‰āļ‡āļēāļ™ (User)'; +-- āļ•āļēāļĢāļēāļ‡āđ€āļāđ‡āļš Refresh Tokens āļŠāļģāļŦāļĢāļąāļš Authentication +CREATE TABLE refresh_tokens ( + token_id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ID āļ‚āļ­āļ‡āļ•āļēāļĢāļēāļ‡', + user_id INT NOT NULL COMMENT 'āđ€āļˆāđ‰āļēāļ‚āļ­āļ‡ Token', + token_hash VARCHAR(255) NOT NULL COMMENT 'Hash āļ‚āļ­āļ‡ Refresh Token', + expires_at DATETIME NOT NULL COMMENT 'āļ§āļąāļ™āļŦāļĄāļ”āļ­āļēāļĒāļļ', + is_revoked TINYINT(1) DEFAULT 0 COMMENT 'āļŠāļ–āļēāļ™āļ°āļĒāļāđ€āļĨāļīāļ (1=Revoked)', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'āļ§āļąāļ™āļ—āļĩāđˆāļŠāļĢāđ‰āļēāļ‡', + replaced_by_token VARCHAR(255) NULL COMMENT 'Token āđƒāļŦāļĄāđˆāļ—āļĩāđˆāļĄāļēāđāļ—āļ™āļ—āļĩāđˆ (Rotation)', + FOREIGN KEY (user_id) REFERENCES users (user_id) ON DELETE CASCADE +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'āļ•āļēāļĢāļēāļ‡āđ€āļāđ‡āļš Refresh Tokens āļŠāļģāļŦāļĢāļąāļš Authentication'; + -- āļ•āļēāļĢāļēāļ‡ Master āđ€āļāđ‡āļš "āļšāļ—āļšāļēāļ—" āļ‚āļ­āļ‡āļœāļđāđ‰āđƒāļŠāđ‰āđƒāļ™āļĢāļ°āļšāļš CREATE TABLE roles ( role_id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ID āļ‚āļ­āļ‡āļ•āļēāļĢāļēāļ‡', @@ -1232,7 +1246,7 @@ CREATE TABLE backup_logs ( -- 4.2 Virtual Columns for JSON Search (āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļŠāļģāļŦāļĢāļąāļš Correspondence) -- āļĢāļ­āļ‡āļĢāļąāļš: Backend Plan T2.1, Req 3.11.3 -- āđ€āļŦāļ•āļļāļœāļĨ: āđ€āļžāļīāđˆāļĄāļ„āļ§āļēāļĄāđ€āļĢāđ‡āļ§āđƒāļ™āļāļēāļĢ Search/Sort āļ‚āđ‰āļ­āļĄāļđāļĨāļ—āļĩāđˆāļ­āļĒāļđāđˆāđƒāļ™ JSON details --- āļŦāļĄāļēāļĒāđ€āļŦāļ•āļļ: āļ•āđ‰āļ­āļ‡āļĄāļąāđˆāļ™āđƒāļˆāļ§āđˆāļē MariaDB āđ€āļ§āļ­āļĢāđŒāļŠāļąāļ™ 10.11+ āļĢāļ­āļ‡āļĢāļąāļš Syntax āļ™āļĩāđ‰ +-- āļŦāļĄāļēāļĒāđ€āļŦāļ•āļļ: āļ•āđ‰āļ­āļ‡āļĄāļąāđˆāļ™āđƒāļˆāļ§āđˆāļē MariaDB āđ€āļ§āļ­āļĢāđŒāļŠāļąāļ™ 11.8+ āļĢāļ­āļ‡āļĢāļąāļš Syntax āļ™āļĩāđ‰ -- āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡: āļ”āļķāļ‡ Project ID āļ—āļĩāđˆāļ­āđ‰āļēāļ‡āļ­āļīāļ‡āđƒāļ™ details āļ­āļ­āļāļĄāļēāļ—āļģ Index ALTER TABLE correspondence_revisions ADD COLUMN v_ref_project_id INT GENERATED ALWAYS AS (