|
34 | 34 | throw new Exception('could not create new indexes for hosts table: ' . $e->getMessage()); |
35 | 35 | } |
36 | 36 |
|
37 | | -// Add new settings in settings table |
38 | 37 | try { |
39 | 38 | // Add 'compliance_threshold_count' column if not exists |
40 | 39 | if (!$hostsDb->columnExist('settings', 'compliance_threshold_count')) { |
|
45 | 44 | if (!$hostsDb->columnExist('settings', 'compliance_threshold_days')) { |
46 | 45 | $hostsDb->exec("ALTER TABLE settings ADD COLUMN compliance_threshold_days INTEGER NOT NULL DEFAULT 30"); |
47 | 46 | } |
| 47 | +} catch (Exception $e) { |
| 48 | + throw new Exception('could not create new columns in hosts settings table: ' . $e->getMessage()); |
| 49 | +} |
48 | 50 |
|
| 51 | +try { |
49 | 52 | // Overwrite settings with old values if they exist |
50 | | - $hostsDb->exec("UPDATE settings SET compliance_threshold_count = (SELECT pkgs_count_considered_outdated FROM settings), compliance_threshold_days = 30"); |
| 53 | + if ($hostsDb->columnExist('settings', 'pkgs_count_considered_outdated')) { |
| 54 | + $hostsDb->exec("UPDATE settings SET compliance_threshold_count = (SELECT pkgs_count_considered_outdated FROM settings)"); |
| 55 | + } |
| 56 | +} catch (Exception $e) { |
| 57 | + throw new Exception('could not migrate old settings to new compliance_threshold_count in hosts settings table: ' . $e->getMessage()); |
| 58 | +} |
51 | 59 |
|
52 | | - // Drop old settings columns |
| 60 | +try { |
| 61 | + // Drop old 'pkgs_count_considered_outdated' column from settings table |
53 | 62 | if ($hostsDb->columnExist('settings', 'pkgs_count_considered_outdated')) { |
54 | 63 | $hostsDb->exec("ALTER TABLE settings DROP COLUMN pkgs_count_considered_outdated"); |
55 | 64 | } |
56 | 65 |
|
| 66 | + // Drop old 'pkgs_count_considered_critical' column from settings table |
57 | 67 | if ($hostsDb->columnExist('settings', 'pkgs_count_considered_critical')) { |
58 | 68 | $hostsDb->exec("ALTER TABLE settings DROP COLUMN pkgs_count_considered_critical"); |
59 | 69 | } |
60 | 70 | } catch (Exception $e) { |
61 | | - throw new Exception('could not add new settings columns in hosts settings table: ' . $e->getMessage()); |
| 71 | + throw new Exception('could not drop old settings columns in hosts settings table: ' . $e->getMessage()); |
62 | 72 | } |
0 commit comments