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