session cylces and adjustments
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
tom.hempel
2026-06-29 13:26:08 +02:00
parent f1caa9e681
commit 7fefc264f4
12 changed files with 1256 additions and 3 deletions

View File

@ -13,7 +13,7 @@ if (defined('QDB_TEST_UPLOADS')) {
define('QDB_LOCK', QDB_UPLOADS_DIR . '/.qdb_lock');
}
define('QDB_SCHEMA', __DIR__ . '/schema.sql');
define('QDB_VERSION', 12);
define('QDB_VERSION', 14);
function qdb_table_exists(PDO $pdo, string $table): bool {
$stmt = $pdo->prepare(
@ -285,6 +285,46 @@ function qdb_apply_migrations(PDO $pdo, string $schemaSql): bool {
}
}
if (!qdb_table_exists($pdo, 'program_session')) {
$pdo->exec("
CREATE TABLE program_session (
sessionID TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL DEFAULT '',
description TEXT NOT NULL DEFAULT '',
sessionNumber INTEGER NOT NULL DEFAULT 1,
orderIndex INTEGER NOT NULL DEFAULT 0,
isActive INTEGER NOT NULL DEFAULT 1,
createdAt INTEGER NOT NULL DEFAULT 0,
updatedAt INTEGER NOT NULL DEFAULT 0
)
");
$pdo->exec("
CREATE TABLE program_session_questionnaire (
sessionID TEXT NOT NULL,
questionnaireID TEXT NOT NULL,
orderIndex INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (sessionID, questionnaireID),
FOREIGN KEY(sessionID) REFERENCES program_session(sessionID) ON DELETE CASCADE,
FOREIGN KEY(questionnaireID) REFERENCES questionnaire(questionnaireID) ON DELETE CASCADE
)
");
$pdo->exec('CREATE INDEX IF NOT EXISTS idx_program_session_order ON program_session(orderIndex, sessionNumber)');
$changed = true;
}
if (!qdb_table_exists($pdo, 'client_program_cycle')) {
$pdo->exec("
CREATE TABLE client_program_cycle (
clientCode TEXT NOT NULL PRIMARY KEY,
cycleNumber INTEGER NOT NULL DEFAULT 1,
cycleStartedAt INTEGER NOT NULL DEFAULT 0,
updatedAt INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY(clientCode) REFERENCES client(clientCode) ON DELETE CASCADE
)
");
$changed = true;
}
if (qdb_table_exists($pdo, 'questionnaire_submission')) {
require_once __DIR__ . '/lib/submissions.php';
if (qdb_backfill_submissions_from_live($pdo)) {