From 4b98f6bd479c5314e837010812ce5bf5355c49d5 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Feb 05 2016 13:50:49 +0000
Subject: [PATCH 1/2] drop tables in reverse creation order


---

diff --git a/docs/schema.sql b/docs/schema.sql
index 21c6cea..a4afd05 100644
--- a/docs/schema.sql
+++ b/docs/schema.sql
@@ -1,60 +1,59 @@
 
 -- vim:noet:sw=8
--- still needs work
-DROP TABLE IF EXISTS build_notifications;
 
+DROP TABLE IF EXISTS win_archives;
+DROP TABLE IF EXISTS buildroot_archives;
+DROP TABLE IF EXISTS image_archive_listing;
+DROP TABLE IF EXISTS image_listing;
+DROP TABLE IF EXISTS image_archives;
+DROP TABLE IF EXISTS maven_archives;
+DROP TABLE IF EXISTS archiveinfo;
+DROP TABLE IF EXISTS archivetypes;
+DROP TABLE IF EXISTS win_builds;
+DROP TABLE IF EXISTS maven_builds;
+DROP TABLE IF EXISTS build_notifications;
 DROP TABLE IF EXISTS log_messages;
-
 DROP TABLE IF EXISTS buildroot_listing;
-DROP TABLE IF EXISTS image_listing;
-DROP TABLE IF EXISTS image_archive_listing;
-
+DROP TABLE IF EXISTS rpmsigs;
 DROP TABLE IF EXISTS rpminfo;
-DROP TABLE IF EXISTS image_builds;
-DROP TABLE IF EXISTS image_archives;
-
 DROP TABLE IF EXISTS group_package_listing;
 DROP TABLE IF EXISTS group_req_listing;
 DROP TABLE IF EXISTS group_config;
 DROP TABLE IF EXISTS groups;
-
-DROP TABLE IF EXISTS tag_listing;
 DROP TABLE IF EXISTS tag_packages;
-
+DROP TABLE IF EXISTS tag_listing;
+DROP TABLE IF EXISTS image_builds;
 DROP TABLE IF EXISTS buildroot_tools_info;
 DROP TABLE IF EXISTS standard_buildroot;
 DROP TABLE IF EXISTS buildroot;
+DROP TABLE IF EXISTS cg_users;
+DROP TABLE IF EXISTS content_generator;
+DROP TABLE IF EXISTS tag_external_repos;
+DROP TABLE IF EXISTS external_repo_config;
+DROP TABLE IF EXISTS external_repo;
 DROP TABLE IF EXISTS repo;
-
 DROP TABLE IF EXISTS build_target_config;
 DROP TABLE IF EXISTS build_target;
-
+DROP TABLE IF EXISTS tag_updates;
+DROP TABLE IF EXISTS tag_extra;
 DROP TABLE IF EXISTS tag_config;
 DROP TABLE IF EXISTS tag_inheritance;
 DROP TABLE IF EXISTS tag;
-
 DROP TABLE IF EXISTS build;
-
+DROP TABLE IF EXISTS volume;
+DROP TABLE IF EXISTS package;
 DROP TABLE IF EXISTS task;
-
 DROP TABLE IF EXISTS host_channels;
 DROP TABLE IF EXISTS host;
-
 DROP TABLE IF EXISTS channels;
-DROP TABLE IF EXISTS package;
-
-DROP TABLE IF EXISTS cg_users;
-DROP TABLE IF EXISTS content_generator;
-
+DROP TABLE IF EXISTS sessions;
 DROP TABLE IF EXISTS user_groups;
 DROP TABLE IF EXISTS user_perms;
 DROP TABLE IF EXISTS permissions;
-
-DROP TABLE IF EXISTS sessions;
 DROP TABLE IF EXISTS users;
-
 DROP TABLE IF EXISTS event_labels;
 DROP TABLE IF EXISTS events;
+
 DROP FUNCTION IF EXISTS get_event();
 DROP FUNCTION IF EXISTS get_event_time(INTEGER);
 

From 5aa6ed48184e9b102e9c1d14aa2f982472970510 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Feb 05 2016 13:58:49 +0000
Subject: [PATCH 2/2] move table drops to schema-clear.sql


---

diff --git a/docs/schema-clear.sql b/docs/schema-clear.sql
new file mode 100644
index 0000000..cec4744
--- /dev/null
+++ b/docs/schema-clear.sql
@@ -0,0 +1,69 @@
+
+-- vim:noet:sw=8
+
+BEGIN;
+
+SELECT 'About to DELETE ALL DATA in koji database' as WARNING;
+SELECT pg_sleep(5);
+
+DROP TABLE IF EXISTS win_archives;
+DROP TABLE IF EXISTS buildroot_archives;
+DROP TABLE IF EXISTS image_archive_listing;
+DROP TABLE IF EXISTS image_listing;
+DROP TABLE IF EXISTS image_archives;
+DROP TABLE IF EXISTS maven_archives;
+DROP TABLE IF EXISTS archiveinfo;
+DROP TABLE IF EXISTS archivetypes;
+DROP TABLE IF EXISTS win_builds;
+DROP TABLE IF EXISTS maven_builds;
+DROP TABLE IF EXISTS build_notifications;
+DROP TABLE IF EXISTS log_messages;
+DROP TABLE IF EXISTS buildroot_listing;
+DROP TABLE IF EXISTS rpmsigs;
+DROP TABLE IF EXISTS rpminfo;
+DROP TABLE IF EXISTS group_package_listing;
+DROP TABLE IF EXISTS group_req_listing;
+DROP TABLE IF EXISTS group_config;
+DROP TABLE IF EXISTS groups;
+DROP TABLE IF EXISTS tag_packages;
+DROP TABLE IF EXISTS tag_listing;
+DROP TABLE IF EXISTS image_builds;
+DROP TABLE IF EXISTS buildroot_tools_info;
+DROP TABLE IF EXISTS standard_buildroot;
+DROP TABLE IF EXISTS buildroot;
+DROP TABLE IF EXISTS cg_users;
+DROP TABLE IF EXISTS content_generator;
+DROP TABLE IF EXISTS tag_external_repos;
+DROP TABLE IF EXISTS external_repo_config;
+DROP TABLE IF EXISTS external_repo;
+DROP TABLE IF EXISTS repo;
+DROP TABLE IF EXISTS build_target_config;
+DROP TABLE IF EXISTS build_target;
+DROP TABLE IF EXISTS tag_updates;
+DROP TABLE IF EXISTS tag_extra;
+DROP TABLE IF EXISTS tag_config;
+DROP TABLE IF EXISTS tag_inheritance;
+DROP TABLE IF EXISTS tag;
+DROP TABLE IF EXISTS build;
+DROP TABLE IF EXISTS volume;
+DROP TABLE IF EXISTS package;
+DROP TABLE IF EXISTS task;
+DROP TABLE IF EXISTS host_channels;
+DROP TABLE IF EXISTS host;
+DROP TABLE IF EXISTS channels;
+DROP TABLE IF EXISTS sessions;
+DROP TABLE IF EXISTS user_groups;
+DROP TABLE IF EXISTS user_perms;
+DROP TABLE IF EXISTS permissions;
+DROP TABLE IF EXISTS users;
+DROP TABLE IF EXISTS event_labels;
+DROP TABLE IF EXISTS events;
+
+DROP FUNCTION IF EXISTS get_event();
+DROP FUNCTION IF EXISTS get_event_time(INTEGER);
+
+
+SELECT 'About to commit table drops' as WARNING;
+SELECT pg_sleep(5);
+
+COMMIT;
diff --git a/docs/schema.sql b/docs/schema.sql
index a4afd05..3d57d33 100644
--- a/docs/schema.sql
+++ b/docs/schema.sql
@@ -1,61 +1,7 @@
 
 -- vim:noet:sw=8
 
-DROP TABLE IF EXISTS win_archives;
-DROP TABLE IF EXISTS buildroot_archives;
-DROP TABLE IF EXISTS image_archive_listing;
-DROP TABLE IF EXISTS image_listing;
-DROP TABLE IF EXISTS image_archives;
-DROP TABLE IF EXISTS maven_archives;
-DROP TABLE IF EXISTS archiveinfo;
-DROP TABLE IF EXISTS archivetypes;
-DROP TABLE IF EXISTS win_builds;
-DROP TABLE IF EXISTS maven_builds;
-DROP TABLE IF EXISTS build_notifications;
-DROP TABLE IF EXISTS log_messages;
-DROP TABLE IF EXISTS buildroot_listing;
-DROP TABLE IF EXISTS rpmsigs;
-DROP TABLE IF EXISTS rpminfo;
-DROP TABLE IF EXISTS group_package_listing;
-DROP TABLE IF EXISTS group_req_listing;
-DROP TABLE IF EXISTS group_config;
-DROP TABLE IF EXISTS groups;
-DROP TABLE IF EXISTS tag_packages;
-DROP TABLE IF EXISTS tag_listing;
-DROP TABLE IF EXISTS image_builds;
-DROP TABLE IF EXISTS buildroot_tools_info;
-DROP TABLE IF EXISTS standard_buildroot;
-DROP TABLE IF EXISTS buildroot;
-DROP TABLE IF EXISTS cg_users;
-DROP TABLE IF EXISTS content_generator;
-DROP TABLE IF EXISTS tag_external_repos;
-DROP TABLE IF EXISTS external_repo_config;
-DROP TABLE IF EXISTS external_repo;
-DROP TABLE IF EXISTS repo;
-DROP TABLE IF EXISTS build_target_config;
-DROP TABLE IF EXISTS build_target;
-DROP TABLE IF EXISTS tag_updates;
-DROP TABLE IF EXISTS tag_extra;
-DROP TABLE IF EXISTS tag_config;
-DROP TABLE IF EXISTS tag_inheritance;
-DROP TABLE IF EXISTS tag;
-DROP TABLE IF EXISTS build;
-DROP TABLE IF EXISTS volume;
-DROP TABLE IF EXISTS package;
-DROP TABLE IF EXISTS task;
-DROP TABLE IF EXISTS host_channels;
-DROP TABLE IF EXISTS host;
-DROP TABLE IF EXISTS channels;
-DROP TABLE IF EXISTS sessions;
-DROP TABLE IF EXISTS user_groups;
-DROP TABLE IF EXISTS user_perms;
-DROP TABLE IF EXISTS permissions;
-DROP TABLE IF EXISTS users;
-DROP TABLE IF EXISTS event_labels;
-DROP TABLE IF EXISTS events;
-
-DROP FUNCTION IF EXISTS get_event();
-DROP FUNCTION IF EXISTS get_event_time(INTEGER);
+-- drop statements for old data have moved to schema-clear.sql
 
 BEGIN WORK;
 

