@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations
77
88
99INSERT INTO schema_migrations
10- VALUES (142 , false);
10+ VALUES (143 , false);
1111
1212-- ---------------------------------------------------------------------------
1313-- Functions
@@ -1103,6 +1103,159 @@ CREATE OR REPLACE VIEW system_platform AS SELECT
11031103FROM system_inventory si JOIN system_patch sp
11041104 ON si .id = sp .system_id AND si .rh_account_id = sp .rh_account_id ;
11051105
1106+ CREATE OR REPLACE FUNCTION system_platform_insert ()
1107+ RETURNS TRIGGER AS
1108+ $system_platform_insert$
1109+ DECLARE
1110+ new_system_id BIGINT ;
1111+ created TIMESTAMPTZ := CURRENT_TIMESTAMP ;
1112+ BEGIN
1113+ INSERT INTO system_inventory (
1114+ inventory_id,
1115+ rh_account_id,
1116+ vmaas_json,
1117+ json_checksum,
1118+ last_updated,
1119+ unchanged_since,
1120+ last_upload,
1121+ stale_timestamp,
1122+ stale_warning_timestamp,
1123+ culled_timestamp,
1124+ stale,
1125+ display_name,
1126+ reporter_id,
1127+ yum_updates,
1128+ satellite_managed,
1129+ built_pkgcache,
1130+ yum_checksum,
1131+ arch,
1132+ bootc,
1133+ tags,
1134+ created
1135+ ) VALUES (
1136+ NEW .inventory_id ,
1137+ NEW .rh_account_id ,
1138+ NEW .vmaas_json ,
1139+ NEW .json_checksum ,
1140+ NEW .last_updated ,
1141+ NEW .unchanged_since ,
1142+ NEW .last_upload ,
1143+ NEW .stale_timestamp ,
1144+ NEW .stale_warning_timestamp ,
1145+ NEW .culled_timestamp ,
1146+ COALESCE(NEW .stale , false),
1147+ NEW .display_name ,
1148+ NEW .reporter_id ,
1149+ NEW .yum_updates ,
1150+ COALESCE(NEW .satellite_managed , false),
1151+ COALESCE(NEW .built_pkgcache , false),
1152+ NEW .yum_checksum ,
1153+ NEW .arch ,
1154+ COALESCE(NEW .bootc , false),
1155+ ' []' ::JSONB,
1156+ created
1157+ )
1158+ RETURNING id INTO new_system_id;
1159+
1160+ INSERT INTO system_patch (
1161+ system_id,
1162+ rh_account_id,
1163+ last_evaluation,
1164+ installable_advisory_count_cache,
1165+ installable_advisory_enh_count_cache,
1166+ installable_advisory_bug_count_cache,
1167+ installable_advisory_sec_count_cache,
1168+ packages_installed,
1169+ packages_installable,
1170+ packages_applicable,
1171+ third_party,
1172+ applicable_advisory_count_cache,
1173+ applicable_advisory_enh_count_cache,
1174+ applicable_advisory_bug_count_cache,
1175+ applicable_advisory_sec_count_cache,
1176+ template_id
1177+ ) VALUES (
1178+ new_system_id,
1179+ NEW .rh_account_id ,
1180+ NEW .last_evaluation ,
1181+ COALESCE(NEW .installable_advisory_count_cache , 0 ),
1182+ COALESCE(NEW .installable_advisory_enh_count_cache , 0 ),
1183+ COALESCE(NEW .installable_advisory_bug_count_cache , 0 ),
1184+ COALESCE(NEW .installable_advisory_sec_count_cache , 0 ),
1185+ COALESCE(NEW .packages_installed , 0 ),
1186+ COALESCE(NEW .packages_installable , 0 ),
1187+ COALESCE(NEW .packages_applicable , 0 ),
1188+ COALESCE(NEW .third_party , false),
1189+ COALESCE(NEW .applicable_advisory_count_cache , 0 ),
1190+ COALESCE(NEW .applicable_advisory_enh_count_cache , 0 ),
1191+ COALESCE(NEW .applicable_advisory_bug_count_cache , 0 ),
1192+ COALESCE(NEW .applicable_advisory_sec_count_cache , 0 ),
1193+ NEW .template_id
1194+ );
1195+
1196+ NEW .id := new_system_id;
1197+ RETURN NEW;
1198+ END;
1199+ $system_platform_insert$
1200+ LANGUAGE ' plpgsql' ;
1201+
1202+ CREATE OR REPLACE FUNCTION system_platform_update ()
1203+ RETURNS TRIGGER AS
1204+ $system_platform_update$
1205+ BEGIN
1206+ UPDATE system_inventory SET
1207+ inventory_id = NEW .inventory_id ,
1208+ vmaas_json = NEW .vmaas_json ,
1209+ json_checksum = NEW .json_checksum ,
1210+ last_updated = NEW .last_updated ,
1211+ unchanged_since = NEW .unchanged_since ,
1212+ last_upload = NEW .last_upload ,
1213+ stale_timestamp = NEW .stale_timestamp ,
1214+ stale_warning_timestamp = NEW .stale_warning_timestamp ,
1215+ culled_timestamp = NEW .culled_timestamp ,
1216+ stale = NEW .stale ,
1217+ display_name = NEW .display_name ,
1218+ reporter_id = NEW .reporter_id ,
1219+ yum_updates = NEW .yum_updates ,
1220+ satellite_managed = NEW .satellite_managed ,
1221+ built_pkgcache = NEW .built_pkgcache ,
1222+ yum_checksum = NEW .yum_checksum ,
1223+ arch = NEW .arch ,
1224+ bootc = NEW .bootc
1225+ WHERE id = OLD .id AND rh_account_id = OLD .rh_account_id ;
1226+
1227+ UPDATE system_patch SET
1228+ last_evaluation = NEW .last_evaluation ,
1229+ installable_advisory_count_cache = NEW .installable_advisory_count_cache ,
1230+ installable_advisory_enh_count_cache = NEW .installable_advisory_enh_count_cache ,
1231+ installable_advisory_bug_count_cache = NEW .installable_advisory_bug_count_cache ,
1232+ installable_advisory_sec_count_cache = NEW .installable_advisory_sec_count_cache ,
1233+ packages_installed = NEW .packages_installed ,
1234+ packages_installable = NEW .packages_installable ,
1235+ packages_applicable = NEW .packages_applicable ,
1236+ third_party = NEW .third_party ,
1237+ applicable_advisory_count_cache = NEW .applicable_advisory_count_cache ,
1238+ applicable_advisory_enh_count_cache = NEW .applicable_advisory_enh_count_cache ,
1239+ applicable_advisory_bug_count_cache = NEW .applicable_advisory_bug_count_cache ,
1240+ applicable_advisory_sec_count_cache = NEW .applicable_advisory_sec_count_cache ,
1241+ template_id = NEW .template_id
1242+ WHERE system_id = OLD .id AND rh_account_id = OLD .rh_account_id ;
1243+
1244+ RETURN NEW;
1245+ END;
1246+ $system_platform_update$
1247+ LANGUAGE ' plpgsql' ;
1248+
1249+ CREATE TRIGGER system_platform_insert_trigger
1250+ INSTEAD OF INSERT ON system_platform
1251+ FOR EACH ROW
1252+ EXECUTE FUNCTION system_platform_insert();
1253+
1254+ CREATE TRIGGER system_platform_update_trigger
1255+ INSTEAD OF UPDATE ON system_platform
1256+ FOR EACH ROW
1257+ EXECUTE FUNCTION system_platform_update();
1258+
11061259GRANT SELECT , INSERT, UPDATE , DELETE ON system_platform TO listener;
11071260-- evaluator needs to update last_evaluation
11081261GRANT UPDATE ON system_platform TO evaluator;
0 commit comments