37338-vm/db/migrations/038_add_subject_scope_and_run_number.php
2026-03-02 19:32:17 +00:00

43 lines
1.8 KiB
PHP

<?php
function migrate_038($pdo) {
echo "Starting migration 038 (Subject Scope and Run Number)...
";
$stmt = $pdo->query("SHOW COLUMNS FROM process_definitions LIKE 'subject_scope'");
if (!$stmt->fetch()) {
$pdo->exec("ALTER TABLE process_definitions ADD COLUMN subject_scope VARCHAR(32) NOT NULL DEFAULT 'person' AFTER name");
echo "Added subject_scope to process_definitions.
";
}
$stmt = $pdo->query("SHOW COLUMNS FROM process_instances LIKE 'run_number'");
if (!$stmt->fetch()) {
$pdo->exec("ALTER TABLE process_instances ADD COLUMN run_number INT NOT NULL DEFAULT 1 AFTER subject_id");
echo "Added run_number to process_instances.
";
}
$defJson = json_encode([
'start_node_id' => 'node_start',
'nodes' => [
['id' => 'node_start', 'name' => 'Planowanie', 'type' => 'task', 'ui_hints' => ['color' => 'blue', 'status' => 'not_started']],
['id' => 'node_end', 'name' => 'Zakończone', 'type' => 'end', 'ui_hints' => ['color' => 'green', 'status' => 'completed']]
],
'transitions' => [
['from' => 'node_start', 'to' => 'node_end', 'name' => 'Oznacz jako gotowe', 'trigger' => 'manual']
]
]);
$stmt = $pdo->prepare("SELECT id FROM process_definitions WHERE code = 'meeting_preparation_meeting'");
$stmt->execute();
if (!$stmt->fetch()) {
$stmtIns = $pdo->prepare("INSERT INTO process_definitions (code, name, version, is_active, subject_scope, definition_json) VALUES ('meeting_preparation_meeting', 'Przygotowanie spotkania (spotkanie)', 1, 1, 'meeting', :json)");
$stmtIns->execute(['json' => $defJson]);
echo "Inserted meeting_preparation_meeting definition.
";
}
echo "Migration 038 completed.
";
}