@platform-modules/civil-aviation-authority 2.3.333 → 2.3.335
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-source.js +2 -0
- package/dist/helpers/cancellation-bilingual-persist.helper.d.ts +37 -0
- package/dist/helpers/cancellation-bilingual-persist.helper.js +77 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +2 -3
- package/dist/models/AnnualPlanSubmissionRestrictionModel.d.ts +9 -0
- package/dist/models/AnnualPlanSubmissionRestrictionModel.js +47 -0
- package/dist/models/AnnualTrainingPlanRequestModel.d.ts +12 -21
- package/dist/models/AnnualTrainingPlanRequestModel.js +60 -75
- package/dist/models/CyberSecurityRiskManagementRiskModel.d.ts +4 -0
- package/dist/models/CyberSecurityRiskManagementRiskModel.js +16 -0
- package/dist/models/SlaApprovalsViewModel.js +54 -54
- package/package.json +1 -1
- package/scripts/sync-sla-reports-sql.js +92 -92
- package/sql/README.md +21 -21
- package/sql/add_csrm_risk_tracking_fields.sql +6 -0
- package/sql/add_training_request_reference_number.sql +9 -9
- package/sql/add_training_room_booking_records_reference.sql +19 -19
- package/sql/annual_training_plan_bulk_upload.sql +140 -140
- package/sql/annual_training_plan_department_plans.sql +80 -80
- package/sql/create_annual_plan_submission_restriction.sql +27 -0
- package/sql/sla_reports_admin_procedures.sql +322 -322
- package/sql/sla_reports_approvals_workbook.sql +427 -427
- package/sql/sla_reports_procedures.sql +883 -883
- package/sql/vw_sla_approvals.sql +115 -115
- package/sql/vw_sla_my_requests.sql +58 -58
- package/src/data-source.ts +2 -0
- package/src/index.ts +521 -518
- package/src/models/AccessCardRequestModel.ts +135 -135
- package/src/models/AirportEntryPermitModel.ts +276 -276
- package/src/models/AnnualPlanSubmissionRestrictionModel.ts +27 -0
- package/src/models/AnnualTrainingPlanDepartmentPlanDecisionModel.ts +33 -33
- package/src/models/AnnualTrainingPlanDepartmentPlanModel.ts +31 -31
- package/src/models/AnnualTrainingPlanItemModel.ts +71 -71
- package/src/models/AnnualTrainingPlanRequestModel.ts +156 -156
- package/src/models/CyberSecurityRiskManagementRiskModel.ts +12 -0
- package/src/models/DocumentDriveModel.ts +28 -28
- package/src/models/DocumentFolderModel.ts +45 -45
- package/src/models/HotelApprovalModel.ts +83 -83
- package/src/models/HousingContractCancelApprovalModel.ts +64 -64
- package/src/models/HousingContractRenewalApprovalModel.ts +64 -64
- package/src/models/ITRequestAttachmentModel.ts +73 -73
- package/src/models/ItApprovalsModel.ts +84 -84
- package/src/models/LegalConsultationApprovalModel.ts +65 -65
- package/src/models/MissionTravelPassportExpiryNotificationConfigModel.ts +36 -36
- package/src/models/NotificationModel.ts +89 -89
- package/src/models/ResidentialUnitRentalApprovalModel.ts +143 -143
- package/src/models/ServiceExtensionAfter60ApprovalModel.ts +87 -87
- package/src/models/ServiceSlaApprovalModel.ts +64 -64
- package/src/models/ServicesNotificationConfigModel.ts +55 -55
- package/src/models/SlaApprovalsViewModel.ts +142 -142
- package/src/models/StudyLeaveRequestModel.ts +173 -173
- package/src/models/TrainingRequestModel.ts +169 -169
- package/src/models/TrainingRoomBookingRequestModel.ts +178 -178
- package/src/models/TrainingRoomBookingWorkflowModel.ts +81 -81
- package/src/models/TrainingRoomNotificationConfigModel.ts +30 -30
- package/src/models/role.ts +34 -34
- package/src/scripts.ts +20 -20
- package/src/sla/sla-table-sync.service.ts +90 -90
- package/dist/models/AnnualTrainingPlanDepartmentPlanDecisionModel.d.ts +0 -10
- package/dist/models/AnnualTrainingPlanDepartmentPlanDecisionModel.js +0 -51
- package/dist/models/AnnualTrainingPlanDepartmentPlanModel.d.ts +0 -13
- package/dist/models/AnnualTrainingPlanDepartmentPlanModel.js +0 -50
- package/dist/models/AnnualTrainingPlanItemModel.d.ts +0 -22
- package/dist/models/AnnualTrainingPlanItemModel.js +0 -101
- package/dist/models/DocumentMetadataModel.d.ts +0 -45
- package/dist/models/DocumentMetadataModel.js +0 -171
- package/dist/models/DocumentationDepartmentsModel.d.ts +0 -13
- package/dist/models/DocumentationDepartmentsModel.js +0 -53
- package/dist/models/FolderModel.d.ts +0 -16
- package/dist/models/FolderModel.js +0 -85
- package/dist/models/ImportExportMaterialModels.d.ts +0 -92
- package/dist/models/ImportExportMaterialModels.js +0 -307
- package/dist/models/PermissionModel.d.ts +0 -18
- package/dist/models/PermissionModel.js +0 -68
- package/dist/models/SecurityAccessApprovalModel.d.ts +0 -23
- package/dist/models/SecurityAccessApprovalModel.js +0 -82
- package/dist/models/SecurityAccessAttachmentModel.d.ts +0 -12
- package/dist/models/SecurityAccessAttachmentModel.js +0 -56
- package/dist/models/SecurityAccessChatModel.d.ts +0 -12
- package/dist/models/SecurityAccessChatModel.js +0 -56
- package/dist/models/SecurityAccessRequestModel.d.ts +0 -25
- package/dist/models/SecurityAccessRequestModel.js +0 -80
- package/dist/models/SecurityAccessWorkflowModel.d.ts +0 -24
- package/dist/models/SecurityAccessWorkflowModel.js +0 -84
- package/dist/models/ServiceExtensionAfterAge60Models.d.ts +0 -93
- package/dist/models/ServiceExtensionAfterAge60Models.js +0 -312
- package/dist/models/UUIDBaseModel.d.ts +0 -14
- package/dist/models/UUIDBaseModel.js +0 -66
- package/dist/models/WorkingHoursExtensionModels.d.ts +0 -88
- package/dist/models/WorkingHoursExtensionModels.js +0 -295
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Applies SLA report views + stored procedures to PostgreSQL (idempotent CREATE OR REPLACE).
|
|
3
|
-
*
|
|
4
|
-
* Env from shared_models/.env only:
|
|
5
|
-
* DB_HOST / TYPEORM_HOST
|
|
6
|
-
* DB_PORT / TYPEORM_PORT
|
|
7
|
-
* DB_USER / TYPEORM_USERNAME
|
|
8
|
-
* DB_PASS / TYPEORM_PASSWORD
|
|
9
|
-
* DB_NAME / TYPEORM_DATABASE
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* node scripts/sync-sla-reports-sql.js
|
|
13
|
-
* npm run sync:sla-sql (from shared_models)
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const fs = require('fs');
|
|
17
|
-
const path = require('path');
|
|
18
|
-
const { Client } = require('pg');
|
|
19
|
-
|
|
20
|
-
function loadEnvFiles() {
|
|
21
|
-
const dotenv = require('dotenv');
|
|
22
|
-
const packageRoot = path.resolve(__dirname, '..');
|
|
23
|
-
const packageEnv = path.join(packageRoot, '.env');
|
|
24
|
-
|
|
25
|
-
if (!fs.existsSync(packageEnv)) {
|
|
26
|
-
throw new Error(`Missing env file: ${packageEnv}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
dotenv.config({ path: packageEnv, override: true });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function getDbConfig() {
|
|
33
|
-
const host = (process.env.DB_HOST || process.env.TYPEORM_HOST || '').trim();
|
|
34
|
-
const port = parseInt(process.env.DB_PORT || process.env.TYPEORM_PORT || '5432', 10);
|
|
35
|
-
const user = (process.env.DB_USER || process.env.TYPEORM_USERNAME || '').trim();
|
|
36
|
-
const password = process.env.DB_PASS || process.env.TYPEORM_PASSWORD || '';
|
|
37
|
-
const database = (process.env.DB_NAME || process.env.TYPEORM_DATABASE || '').trim();
|
|
38
|
-
|
|
39
|
-
if (!host || !user || !database) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
'Missing DB config. Set DB_HOST, DB_USER, DB_NAME (and DB_PASS) in shared_models/.env'
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return { host, port, user, password, database };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function main() {
|
|
49
|
-
const skipSync = process.argv.includes('--skip');
|
|
50
|
-
if (skipSync || process.env.SKIP_SLA_SQL_SYNC === 'true') {
|
|
51
|
-
console.log('[sync-sla-reports-sql] skipped (SKIP_SLA_SQL_SYNC or --skip)');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
loadEnvFiles();
|
|
56
|
-
const config = getDbConfig();
|
|
57
|
-
const sqlDir = path.join(__dirname, '..', 'sql');
|
|
58
|
-
const manifestPath = path.join(sqlDir, 'sla-reports-sync.manifest.json');
|
|
59
|
-
|
|
60
|
-
if (!fs.existsSync(manifestPath)) {
|
|
61
|
-
throw new Error(`Manifest not found: ${manifestPath}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const files = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
65
|
-
if (!Array.isArray(files) || files.length === 0) {
|
|
66
|
-
throw new Error('sla-reports-sync.manifest.json must be a non-empty array');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const client = new Client(config);
|
|
70
|
-
await client.connect();
|
|
71
|
-
console.log(`[sync-sla-reports-sql] connected to ${config.host}/${config.database}`);
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
for (const file of files) {
|
|
75
|
-
const filePath = path.join(sqlDir, file);
|
|
76
|
-
if (!fs.existsSync(filePath)) {
|
|
77
|
-
throw new Error(`SQL file missing: ${filePath}`);
|
|
78
|
-
}
|
|
79
|
-
const sql = fs.readFileSync(filePath, 'utf8');
|
|
80
|
-
await client.query(sql);
|
|
81
|
-
console.log(`[sync-sla-reports-sql] applied ${file}`);
|
|
82
|
-
}
|
|
83
|
-
console.log('[sync-sla-reports-sql] done');
|
|
84
|
-
} finally {
|
|
85
|
-
await client.end();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
main().catch((err) => {
|
|
90
|
-
console.error('[sync-sla-reports-sql] failed:', err.message);
|
|
91
|
-
process.exit(1);
|
|
92
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Applies SLA report views + stored procedures to PostgreSQL (idempotent CREATE OR REPLACE).
|
|
3
|
+
*
|
|
4
|
+
* Env from shared_models/.env only:
|
|
5
|
+
* DB_HOST / TYPEORM_HOST
|
|
6
|
+
* DB_PORT / TYPEORM_PORT
|
|
7
|
+
* DB_USER / TYPEORM_USERNAME
|
|
8
|
+
* DB_PASS / TYPEORM_PASSWORD
|
|
9
|
+
* DB_NAME / TYPEORM_DATABASE
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* node scripts/sync-sla-reports-sql.js
|
|
13
|
+
* npm run sync:sla-sql (from shared_models)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const { Client } = require('pg');
|
|
19
|
+
|
|
20
|
+
function loadEnvFiles() {
|
|
21
|
+
const dotenv = require('dotenv');
|
|
22
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
23
|
+
const packageEnv = path.join(packageRoot, '.env');
|
|
24
|
+
|
|
25
|
+
if (!fs.existsSync(packageEnv)) {
|
|
26
|
+
throw new Error(`Missing env file: ${packageEnv}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
dotenv.config({ path: packageEnv, override: true });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getDbConfig() {
|
|
33
|
+
const host = (process.env.DB_HOST || process.env.TYPEORM_HOST || '').trim();
|
|
34
|
+
const port = parseInt(process.env.DB_PORT || process.env.TYPEORM_PORT || '5432', 10);
|
|
35
|
+
const user = (process.env.DB_USER || process.env.TYPEORM_USERNAME || '').trim();
|
|
36
|
+
const password = process.env.DB_PASS || process.env.TYPEORM_PASSWORD || '';
|
|
37
|
+
const database = (process.env.DB_NAME || process.env.TYPEORM_DATABASE || '').trim();
|
|
38
|
+
|
|
39
|
+
if (!host || !user || !database) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
'Missing DB config. Set DB_HOST, DB_USER, DB_NAME (and DB_PASS) in shared_models/.env'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { host, port, user, password, database };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function main() {
|
|
49
|
+
const skipSync = process.argv.includes('--skip');
|
|
50
|
+
if (skipSync || process.env.SKIP_SLA_SQL_SYNC === 'true') {
|
|
51
|
+
console.log('[sync-sla-reports-sql] skipped (SKIP_SLA_SQL_SYNC or --skip)');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
loadEnvFiles();
|
|
56
|
+
const config = getDbConfig();
|
|
57
|
+
const sqlDir = path.join(__dirname, '..', 'sql');
|
|
58
|
+
const manifestPath = path.join(sqlDir, 'sla-reports-sync.manifest.json');
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(manifestPath)) {
|
|
61
|
+
throw new Error(`Manifest not found: ${manifestPath}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const files = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
65
|
+
if (!Array.isArray(files) || files.length === 0) {
|
|
66
|
+
throw new Error('sla-reports-sync.manifest.json must be a non-empty array');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const client = new Client(config);
|
|
70
|
+
await client.connect();
|
|
71
|
+
console.log(`[sync-sla-reports-sql] connected to ${config.host}/${config.database}`);
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
for (const file of files) {
|
|
75
|
+
const filePath = path.join(sqlDir, file);
|
|
76
|
+
if (!fs.existsSync(filePath)) {
|
|
77
|
+
throw new Error(`SQL file missing: ${filePath}`);
|
|
78
|
+
}
|
|
79
|
+
const sql = fs.readFileSync(filePath, 'utf8');
|
|
80
|
+
await client.query(sql);
|
|
81
|
+
console.log(`[sync-sla-reports-sql] applied ${file}`);
|
|
82
|
+
}
|
|
83
|
+
console.log('[sync-sla-reports-sql] done');
|
|
84
|
+
} finally {
|
|
85
|
+
await client.end();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main().catch((err) => {
|
|
90
|
+
console.error('[sync-sla-reports-sql] failed:', err.message);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
});
|
package/sql/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
# SLA reports — database objects
|
|
2
|
-
|
|
3
|
-
Applied in order by `npm run sync:sla-sql` (see `sla-reports-sync.manifest.json`).
|
|
4
|
-
|
|
5
|
-
| File | Description |
|
|
6
|
-
|------|-------------|
|
|
7
|
-
| `vw_sla_my_requests.sql` | My-requests view |
|
|
8
|
-
| `vw_sla_approvals.sql` | Approvals view |
|
|
9
|
-
| `sla_reports_procedures.sql` | User SLA report functions + Excel helpers |
|
|
10
|
-
| `sla_reports_approvals_workbook.sql` | Approvals Excel workbook (Requests + Approvals per sub-service) |
|
|
11
|
-
| `sla_reports_admin_procedures.sql` | Admin SLA report functions (requires procedures file) |
|
|
12
|
-
|
|
13
|
-
From **shared_models** (reads DB config from `shared_models/.env` only — `DB_HOST`, `DB_USER`, `DB_PASS`, `DB_NAME`):
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
cd shared_models && npm run sync:sla-sql
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Skip sync: `SKIP_SLA_SQL_SYNC=true` or pass `--skip`.
|
|
20
|
-
|
|
21
|
-
Reports_Service does not run SQL sync — apply these objects before using the reports API (local dev, CI, or deployment pipeline).
|
|
1
|
+
# SLA reports — database objects
|
|
2
|
+
|
|
3
|
+
Applied in order by `npm run sync:sla-sql` (see `sla-reports-sync.manifest.json`).
|
|
4
|
+
|
|
5
|
+
| File | Description |
|
|
6
|
+
|------|-------------|
|
|
7
|
+
| `vw_sla_my_requests.sql` | My-requests view |
|
|
8
|
+
| `vw_sla_approvals.sql` | Approvals view |
|
|
9
|
+
| `sla_reports_procedures.sql` | User SLA report functions + Excel helpers |
|
|
10
|
+
| `sla_reports_approvals_workbook.sql` | Approvals Excel workbook (Requests + Approvals per sub-service) |
|
|
11
|
+
| `sla_reports_admin_procedures.sql` | Admin SLA report functions (requires procedures file) |
|
|
12
|
+
|
|
13
|
+
From **shared_models** (reads DB config from `shared_models/.env` only — `DB_HOST`, `DB_USER`, `DB_PASS`, `DB_NAME`):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd shared_models && npm run sync:sla-sql
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Skip sync: `SKIP_SLA_SQL_SYNC=true` or pass `--skip`.
|
|
20
|
+
|
|
21
|
+
Reports_Service does not run SQL sync — apply these objects before using the reports API (local dev, CI, or deployment pipeline).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Cyber security risk management risks: tracking / closure fields
|
|
2
|
+
ALTER TABLE cyber_security_risk_management_risks
|
|
3
|
+
ADD COLUMN IF NOT EXISTS new_control TEXT,
|
|
4
|
+
ADD COLUMN IF NOT EXISTS actual_end_date DATE,
|
|
5
|
+
ADD COLUMN IF NOT EXISTS notes TEXT,
|
|
6
|
+
ADD COLUMN IF NOT EXISTS justification_for_delay TEXT;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
-- Reference number for Request Training, assigned when the request reaches Records Department.
|
|
2
|
-
-- Run once per environment. HR and Conductor use synchronize: false.
|
|
3
|
-
|
|
4
|
-
ALTER TABLE IF EXISTS training_requests
|
|
5
|
-
ADD COLUMN IF NOT EXISTS reference_number VARCHAR(20) NULL;
|
|
6
|
-
|
|
7
|
-
CREATE UNIQUE INDEX IF NOT EXISTS uq_training_requests_reference_number
|
|
8
|
-
ON training_requests (reference_number)
|
|
9
|
-
WHERE reference_number IS NOT NULL;
|
|
1
|
+
-- Reference number for Request Training, assigned when the request reaches Records Department.
|
|
2
|
+
-- Run once per environment. HR and Conductor use synchronize: false.
|
|
3
|
+
|
|
4
|
+
ALTER TABLE IF EXISTS training_requests
|
|
5
|
+
ADD COLUMN IF NOT EXISTS reference_number VARCHAR(20) NULL;
|
|
6
|
+
|
|
7
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uq_training_requests_reference_number
|
|
8
|
+
ON training_requests (reference_number)
|
|
9
|
+
WHERE reference_number IS NOT NULL;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
-- Training room booking parallel approvals: workflow log status, log department
|
|
2
|
-
-- columns, and the Records reference number.
|
|
3
|
-
-- Run once per environment. HR and Conductor use synchronize: false.
|
|
4
|
-
|
|
5
|
-
ALTER TYPE training_room_booking_workflows_status_enum
|
|
6
|
-
ADD VALUE IF NOT EXISTS 'In Progress';
|
|
7
|
-
|
|
8
|
-
ALTER TABLE IF EXISTS training_room_booking_workflows
|
|
9
|
-
ADD COLUMN IF NOT EXISTS department_id INTEGER NULL;
|
|
10
|
-
|
|
11
|
-
ALTER TABLE IF EXISTS training_room_booking_workflows
|
|
12
|
-
ADD COLUMN IF NOT EXISTS section_id INTEGER NULL;
|
|
13
|
-
|
|
14
|
-
ALTER TABLE IF EXISTS training_room_booking_requests
|
|
15
|
-
ADD COLUMN IF NOT EXISTS reference_number VARCHAR(20) NULL;
|
|
16
|
-
|
|
17
|
-
CREATE UNIQUE INDEX IF NOT EXISTS uq_training_room_booking_requests_reference_number
|
|
18
|
-
ON training_room_booking_requests (reference_number)
|
|
19
|
-
WHERE reference_number IS NOT NULL;
|
|
1
|
+
-- Training room booking parallel approvals: workflow log status, log department
|
|
2
|
+
-- columns, and the Records reference number.
|
|
3
|
+
-- Run once per environment. HR and Conductor use synchronize: false.
|
|
4
|
+
|
|
5
|
+
ALTER TYPE training_room_booking_workflows_status_enum
|
|
6
|
+
ADD VALUE IF NOT EXISTS 'In Progress';
|
|
7
|
+
|
|
8
|
+
ALTER TABLE IF EXISTS training_room_booking_workflows
|
|
9
|
+
ADD COLUMN IF NOT EXISTS department_id INTEGER NULL;
|
|
10
|
+
|
|
11
|
+
ALTER TABLE IF EXISTS training_room_booking_workflows
|
|
12
|
+
ADD COLUMN IF NOT EXISTS section_id INTEGER NULL;
|
|
13
|
+
|
|
14
|
+
ALTER TABLE IF EXISTS training_room_booking_requests
|
|
15
|
+
ADD COLUMN IF NOT EXISTS reference_number VARCHAR(20) NULL;
|
|
16
|
+
|
|
17
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uq_training_room_booking_requests_reference_number
|
|
18
|
+
ON training_room_booking_requests (reference_number)
|
|
19
|
+
WHERE reference_number IS NOT NULL;
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
-- Annual Training Plan parent/item migration.
|
|
2
|
-
-- Run once per environment before deploying the bulk upload API.
|
|
3
|
-
|
|
4
|
-
DO $$ BEGIN
|
|
5
|
-
CREATE TYPE annual_training_plan_requests_import_status_enum
|
|
6
|
-
AS ENUM ('Validated', 'Imported', 'Failed');
|
|
7
|
-
EXCEPTION
|
|
8
|
-
WHEN duplicate_object THEN NULL;
|
|
9
|
-
END $$;
|
|
10
|
-
|
|
11
|
-
ALTER TABLE annual_training_plan_requests
|
|
12
|
-
ADD COLUMN IF NOT EXISTS plan_name VARCHAR(255),
|
|
13
|
-
ADD COLUMN IF NOT EXISTS plan_number VARCHAR(30),
|
|
14
|
-
ADD COLUMN IF NOT EXISTS plan_year INTEGER,
|
|
15
|
-
ADD COLUMN IF NOT EXISTS source_file_url VARCHAR(1000),
|
|
16
|
-
ADD COLUMN IF NOT EXISTS source_file_name VARCHAR(255),
|
|
17
|
-
ADD COLUMN IF NOT EXISTS total_departments INTEGER NOT NULL DEFAULT 0,
|
|
18
|
-
ADD COLUMN IF NOT EXISTS total_courses INTEGER NOT NULL DEFAULT 0,
|
|
19
|
-
ADD COLUMN IF NOT EXISTS total_participants INTEGER NOT NULL DEFAULT 0,
|
|
20
|
-
ADD COLUMN IF NOT EXISTS import_status annual_training_plan_requests_import_status_enum;
|
|
21
|
-
|
|
22
|
-
CREATE UNIQUE INDEX IF NOT EXISTS uq_annual_training_plan_requests_plan_number
|
|
23
|
-
ON annual_training_plan_requests(plan_number)
|
|
24
|
-
WHERE plan_number IS NOT NULL;
|
|
25
|
-
|
|
26
|
-
CREATE TABLE IF NOT EXISTS annual_training_plan_items (
|
|
27
|
-
id SERIAL PRIMARY KEY,
|
|
28
|
-
request_id INTEGER NOT NULL REFERENCES annual_training_plan_requests(id) ON DELETE CASCADE,
|
|
29
|
-
row_number INTEGER NOT NULL,
|
|
30
|
-
department_id INTEGER NOT NULL,
|
|
31
|
-
section_id INTEGER,
|
|
32
|
-
course_name VARCHAR(255) NOT NULL,
|
|
33
|
-
no_of_participants INTEGER NOT NULL,
|
|
34
|
-
course_cost NUMERIC(10,2) NOT NULL,
|
|
35
|
-
total_cost NUMERIC(14,2) NOT NULL,
|
|
36
|
-
proposed_implementation_date VARCHAR(500) NOT NULL,
|
|
37
|
-
description TEXT NOT NULL,
|
|
38
|
-
reason TEXT NOT NULL,
|
|
39
|
-
job_competency VARCHAR(255),
|
|
40
|
-
place annual_training_plan_requests_place_enum,
|
|
41
|
-
location VARCHAR(255),
|
|
42
|
-
name_of_participants JSONB,
|
|
43
|
-
employee_list JSONB,
|
|
44
|
-
created_by INTEGER,
|
|
45
|
-
updated_by INTEGER,
|
|
46
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
47
|
-
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
48
|
-
is_deleted BOOLEAN DEFAULT FALSE,
|
|
49
|
-
CONSTRAINT uq_annual_training_plan_items_request_row UNIQUE(request_id, row_number)
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
CREATE INDEX IF NOT EXISTS ix_annual_training_plan_items_request
|
|
53
|
-
ON annual_training_plan_items(request_id);
|
|
54
|
-
CREATE INDEX IF NOT EXISTS ix_annual_training_plan_items_department
|
|
55
|
-
ON annual_training_plan_items(department_id);
|
|
56
|
-
|
|
57
|
-
-- Preserve old one-course requests as one child item, then remove the duplicated parent columns.
|
|
58
|
-
DO $$ BEGIN
|
|
59
|
-
IF EXISTS (
|
|
60
|
-
SELECT 1 FROM information_schema.columns
|
|
61
|
-
WHERE table_schema = 'public'
|
|
62
|
-
AND table_name = 'annual_training_plan_requests'
|
|
63
|
-
AND column_name = 'course_name'
|
|
64
|
-
) THEN
|
|
65
|
-
ALTER TABLE annual_training_plan_requests
|
|
66
|
-
ALTER COLUMN course_name DROP NOT NULL,
|
|
67
|
-
ALTER COLUMN no_of_participants DROP NOT NULL,
|
|
68
|
-
ALTER COLUMN course_cost DROP NOT NULL,
|
|
69
|
-
ALTER COLUMN proposed_implementation_date DROP NOT NULL,
|
|
70
|
-
ALTER COLUMN description DROP NOT NULL,
|
|
71
|
-
ALTER COLUMN reason DROP NOT NULL;
|
|
72
|
-
|
|
73
|
-
INSERT INTO annual_training_plan_items (
|
|
74
|
-
request_id, row_number, department_id, section_id, course_name,
|
|
75
|
-
no_of_participants, course_cost, total_cost, proposed_implementation_date,
|
|
76
|
-
description, reason, job_competency, place, location,
|
|
77
|
-
name_of_participants, employee_list, created_by, updated_by,
|
|
78
|
-
created_at, updated_at, is_deleted
|
|
79
|
-
)
|
|
80
|
-
SELECT
|
|
81
|
-
r.id, 1, COALESCE(r.req_user_department_id, 0), r.req_user_section_id,
|
|
82
|
-
r.course_name, r.no_of_participants, r.course_cost, r.total_cost,
|
|
83
|
-
r.proposed_implementation_date, r.description, r.reason,
|
|
84
|
-
r.job_competency, r.place, r.location, r.name_of_participants,
|
|
85
|
-
r.employee_list, r.created_by, r.updated_by, r.created_at, r.updated_at, r.is_deleted
|
|
86
|
-
FROM annual_training_plan_requests r
|
|
87
|
-
WHERE r.course_name IS NOT NULL
|
|
88
|
-
AND r.req_user_department_id IS NOT NULL
|
|
89
|
-
AND NOT EXISTS (
|
|
90
|
-
SELECT 1 FROM annual_training_plan_items i WHERE i.request_id = r.id
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
UPDATE annual_training_plan_requests r
|
|
94
|
-
SET total_departments = x.total_departments,
|
|
95
|
-
total_courses = x.total_courses,
|
|
96
|
-
total_participants = x.total_participants
|
|
97
|
-
FROM (
|
|
98
|
-
SELECT request_id,
|
|
99
|
-
COUNT(DISTINCT department_id)::INTEGER AS total_departments,
|
|
100
|
-
COUNT(*)::INTEGER AS total_courses,
|
|
101
|
-
COALESCE(SUM(no_of_participants), 0)::INTEGER AS total_participants
|
|
102
|
-
FROM annual_training_plan_items
|
|
103
|
-
WHERE is_deleted = FALSE
|
|
104
|
-
GROUP BY request_id
|
|
105
|
-
) x
|
|
106
|
-
WHERE r.id = x.request_id;
|
|
107
|
-
|
|
108
|
-
UPDATE annual_training_plan_requests r
|
|
109
|
-
SET total_cost = x.total_cost
|
|
110
|
-
FROM (
|
|
111
|
-
SELECT request_id, COALESCE(SUM(total_cost), 0) AS total_cost
|
|
112
|
-
FROM annual_training_plan_items
|
|
113
|
-
WHERE is_deleted = FALSE
|
|
114
|
-
GROUP BY request_id
|
|
115
|
-
) x
|
|
116
|
-
WHERE r.id = x.request_id;
|
|
117
|
-
|
|
118
|
-
ALTER TABLE annual_training_plan_requests
|
|
119
|
-
DROP COLUMN IF EXISTS course_name,
|
|
120
|
-
DROP COLUMN IF EXISTS no_of_participants,
|
|
121
|
-
DROP COLUMN IF EXISTS course_cost,
|
|
122
|
-
DROP COLUMN IF EXISTS proposed_implementation_date,
|
|
123
|
-
DROP COLUMN IF EXISTS description,
|
|
124
|
-
DROP COLUMN IF EXISTS place,
|
|
125
|
-
DROP COLUMN IF EXISTS location,
|
|
126
|
-
DROP COLUMN IF EXISTS reason,
|
|
127
|
-
DROP COLUMN IF EXISTS job_competency,
|
|
128
|
-
DROP COLUMN IF EXISTS name_of_participants,
|
|
129
|
-
DROP COLUMN IF EXISTS employee_list;
|
|
130
|
-
END IF;
|
|
131
|
-
END $$;
|
|
132
|
-
|
|
133
|
-
UPDATE annual_training_plan_requests
|
|
134
|
-
SET total_cost = 0
|
|
135
|
-
WHERE total_cost IS NULL;
|
|
136
|
-
|
|
137
|
-
ALTER TABLE annual_training_plan_requests
|
|
138
|
-
ALTER COLUMN total_cost TYPE NUMERIC(14,2),
|
|
139
|
-
ALTER COLUMN total_cost SET DEFAULT 0,
|
|
140
|
-
ALTER COLUMN total_cost SET NOT NULL;
|
|
1
|
+
-- Annual Training Plan parent/item migration.
|
|
2
|
+
-- Run once per environment before deploying the bulk upload API.
|
|
3
|
+
|
|
4
|
+
DO $$ BEGIN
|
|
5
|
+
CREATE TYPE annual_training_plan_requests_import_status_enum
|
|
6
|
+
AS ENUM ('Validated', 'Imported', 'Failed');
|
|
7
|
+
EXCEPTION
|
|
8
|
+
WHEN duplicate_object THEN NULL;
|
|
9
|
+
END $$;
|
|
10
|
+
|
|
11
|
+
ALTER TABLE annual_training_plan_requests
|
|
12
|
+
ADD COLUMN IF NOT EXISTS plan_name VARCHAR(255),
|
|
13
|
+
ADD COLUMN IF NOT EXISTS plan_number VARCHAR(30),
|
|
14
|
+
ADD COLUMN IF NOT EXISTS plan_year INTEGER,
|
|
15
|
+
ADD COLUMN IF NOT EXISTS source_file_url VARCHAR(1000),
|
|
16
|
+
ADD COLUMN IF NOT EXISTS source_file_name VARCHAR(255),
|
|
17
|
+
ADD COLUMN IF NOT EXISTS total_departments INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
ADD COLUMN IF NOT EXISTS total_courses INTEGER NOT NULL DEFAULT 0,
|
|
19
|
+
ADD COLUMN IF NOT EXISTS total_participants INTEGER NOT NULL DEFAULT 0,
|
|
20
|
+
ADD COLUMN IF NOT EXISTS import_status annual_training_plan_requests_import_status_enum;
|
|
21
|
+
|
|
22
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uq_annual_training_plan_requests_plan_number
|
|
23
|
+
ON annual_training_plan_requests(plan_number)
|
|
24
|
+
WHERE plan_number IS NOT NULL;
|
|
25
|
+
|
|
26
|
+
CREATE TABLE IF NOT EXISTS annual_training_plan_items (
|
|
27
|
+
id SERIAL PRIMARY KEY,
|
|
28
|
+
request_id INTEGER NOT NULL REFERENCES annual_training_plan_requests(id) ON DELETE CASCADE,
|
|
29
|
+
row_number INTEGER NOT NULL,
|
|
30
|
+
department_id INTEGER NOT NULL,
|
|
31
|
+
section_id INTEGER,
|
|
32
|
+
course_name VARCHAR(255) NOT NULL,
|
|
33
|
+
no_of_participants INTEGER NOT NULL,
|
|
34
|
+
course_cost NUMERIC(10,2) NOT NULL,
|
|
35
|
+
total_cost NUMERIC(14,2) NOT NULL,
|
|
36
|
+
proposed_implementation_date VARCHAR(500) NOT NULL,
|
|
37
|
+
description TEXT NOT NULL,
|
|
38
|
+
reason TEXT NOT NULL,
|
|
39
|
+
job_competency VARCHAR(255),
|
|
40
|
+
place annual_training_plan_requests_place_enum,
|
|
41
|
+
location VARCHAR(255),
|
|
42
|
+
name_of_participants JSONB,
|
|
43
|
+
employee_list JSONB,
|
|
44
|
+
created_by INTEGER,
|
|
45
|
+
updated_by INTEGER,
|
|
46
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
47
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
48
|
+
is_deleted BOOLEAN DEFAULT FALSE,
|
|
49
|
+
CONSTRAINT uq_annual_training_plan_items_request_row UNIQUE(request_id, row_number)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
CREATE INDEX IF NOT EXISTS ix_annual_training_plan_items_request
|
|
53
|
+
ON annual_training_plan_items(request_id);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS ix_annual_training_plan_items_department
|
|
55
|
+
ON annual_training_plan_items(department_id);
|
|
56
|
+
|
|
57
|
+
-- Preserve old one-course requests as one child item, then remove the duplicated parent columns.
|
|
58
|
+
DO $$ BEGIN
|
|
59
|
+
IF EXISTS (
|
|
60
|
+
SELECT 1 FROM information_schema.columns
|
|
61
|
+
WHERE table_schema = 'public'
|
|
62
|
+
AND table_name = 'annual_training_plan_requests'
|
|
63
|
+
AND column_name = 'course_name'
|
|
64
|
+
) THEN
|
|
65
|
+
ALTER TABLE annual_training_plan_requests
|
|
66
|
+
ALTER COLUMN course_name DROP NOT NULL,
|
|
67
|
+
ALTER COLUMN no_of_participants DROP NOT NULL,
|
|
68
|
+
ALTER COLUMN course_cost DROP NOT NULL,
|
|
69
|
+
ALTER COLUMN proposed_implementation_date DROP NOT NULL,
|
|
70
|
+
ALTER COLUMN description DROP NOT NULL,
|
|
71
|
+
ALTER COLUMN reason DROP NOT NULL;
|
|
72
|
+
|
|
73
|
+
INSERT INTO annual_training_plan_items (
|
|
74
|
+
request_id, row_number, department_id, section_id, course_name,
|
|
75
|
+
no_of_participants, course_cost, total_cost, proposed_implementation_date,
|
|
76
|
+
description, reason, job_competency, place, location,
|
|
77
|
+
name_of_participants, employee_list, created_by, updated_by,
|
|
78
|
+
created_at, updated_at, is_deleted
|
|
79
|
+
)
|
|
80
|
+
SELECT
|
|
81
|
+
r.id, 1, COALESCE(r.req_user_department_id, 0), r.req_user_section_id,
|
|
82
|
+
r.course_name, r.no_of_participants, r.course_cost, r.total_cost,
|
|
83
|
+
r.proposed_implementation_date, r.description, r.reason,
|
|
84
|
+
r.job_competency, r.place, r.location, r.name_of_participants,
|
|
85
|
+
r.employee_list, r.created_by, r.updated_by, r.created_at, r.updated_at, r.is_deleted
|
|
86
|
+
FROM annual_training_plan_requests r
|
|
87
|
+
WHERE r.course_name IS NOT NULL
|
|
88
|
+
AND r.req_user_department_id IS NOT NULL
|
|
89
|
+
AND NOT EXISTS (
|
|
90
|
+
SELECT 1 FROM annual_training_plan_items i WHERE i.request_id = r.id
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
UPDATE annual_training_plan_requests r
|
|
94
|
+
SET total_departments = x.total_departments,
|
|
95
|
+
total_courses = x.total_courses,
|
|
96
|
+
total_participants = x.total_participants
|
|
97
|
+
FROM (
|
|
98
|
+
SELECT request_id,
|
|
99
|
+
COUNT(DISTINCT department_id)::INTEGER AS total_departments,
|
|
100
|
+
COUNT(*)::INTEGER AS total_courses,
|
|
101
|
+
COALESCE(SUM(no_of_participants), 0)::INTEGER AS total_participants
|
|
102
|
+
FROM annual_training_plan_items
|
|
103
|
+
WHERE is_deleted = FALSE
|
|
104
|
+
GROUP BY request_id
|
|
105
|
+
) x
|
|
106
|
+
WHERE r.id = x.request_id;
|
|
107
|
+
|
|
108
|
+
UPDATE annual_training_plan_requests r
|
|
109
|
+
SET total_cost = x.total_cost
|
|
110
|
+
FROM (
|
|
111
|
+
SELECT request_id, COALESCE(SUM(total_cost), 0) AS total_cost
|
|
112
|
+
FROM annual_training_plan_items
|
|
113
|
+
WHERE is_deleted = FALSE
|
|
114
|
+
GROUP BY request_id
|
|
115
|
+
) x
|
|
116
|
+
WHERE r.id = x.request_id;
|
|
117
|
+
|
|
118
|
+
ALTER TABLE annual_training_plan_requests
|
|
119
|
+
DROP COLUMN IF EXISTS course_name,
|
|
120
|
+
DROP COLUMN IF EXISTS no_of_participants,
|
|
121
|
+
DROP COLUMN IF EXISTS course_cost,
|
|
122
|
+
DROP COLUMN IF EXISTS proposed_implementation_date,
|
|
123
|
+
DROP COLUMN IF EXISTS description,
|
|
124
|
+
DROP COLUMN IF EXISTS place,
|
|
125
|
+
DROP COLUMN IF EXISTS location,
|
|
126
|
+
DROP COLUMN IF EXISTS reason,
|
|
127
|
+
DROP COLUMN IF EXISTS job_competency,
|
|
128
|
+
DROP COLUMN IF EXISTS name_of_participants,
|
|
129
|
+
DROP COLUMN IF EXISTS employee_list;
|
|
130
|
+
END IF;
|
|
131
|
+
END $$;
|
|
132
|
+
|
|
133
|
+
UPDATE annual_training_plan_requests
|
|
134
|
+
SET total_cost = 0
|
|
135
|
+
WHERE total_cost IS NULL;
|
|
136
|
+
|
|
137
|
+
ALTER TABLE annual_training_plan_requests
|
|
138
|
+
ALTER COLUMN total_cost TYPE NUMERIC(14,2),
|
|
139
|
+
ALTER COLUMN total_cost SET DEFAULT 0,
|
|
140
|
+
ALTER COLUMN total_cost SET NOT NULL;
|