* @brief Adds source_id / source_title to legacy columns tables in older databases. */
| 1399 | * @brief Adds source_id / source_title to legacy columns tables in older databases. |
| 1400 | */ |
| 1401 | void Sessions::DatabaseManager::migrateColumnsTable(QSqlQuery& q) |
| 1402 | { |
| 1403 | auto columnExists = [&q](const QString& column) { |
| 1404 | if (!q.exec(QStringLiteral("PRAGMA table_info(\"columns\")"))) { |
| 1405 | qWarning() << "[Sessions] PRAGMA table_info failed:" << q.lastError().text(); |
| 1406 | return false; |
| 1407 | } |
| 1408 | while (q.next()) |
| 1409 | if (q.value(1).toString().compare(column, Qt::CaseInsensitive) == 0) |
| 1410 | return true; |
| 1411 | |
| 1412 | return false; |
| 1413 | }; |
| 1414 | |
| 1415 | if (!columnExists(QStringLiteral("source_id"))) { |
| 1416 | if (!q.exec("ALTER TABLE \"columns\" ADD COLUMN source_id INTEGER NOT NULL DEFAULT 0")) |
| 1417 | qWarning() << "[Sessions] ALTER add source_id failed:" << q.lastError().text(); |
| 1418 | } |
| 1419 | |
| 1420 | if (!columnExists(QStringLiteral("source_title"))) { |
| 1421 | if (!q.exec("ALTER TABLE \"columns\" ADD COLUMN source_title TEXT NOT NULL DEFAULT ''")) |
| 1422 | qWarning() << "[Sessions] ALTER add source_title failed:" << q.lastError().text(); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * @brief Creates the per-sample tables (readings, raw_bytes, table_snapshots) and indexes. |