[PATCH] Drop tables and functions only if exist

Dan HorĂ¡k dan at danny.cz
Thu Aug 20 08:37:05 UTC 2015


On Thu, 20 Aug 2015 10:22:26 +0200
Pavol Babincak <pbabinca at redhat.com> wrote:

> Can anybody review this patch and merge if it is ok?

In my opinion a script for creating a DB schema shouldn't start with
dropping table it wants to create later at all and expect a fresh and
empty DB.

But otherwise using IF EXISTS makes it cleaner, so ACK.


		Dan

> On 03/06/2015 06:18 PM, Pavol Babincak wrote:
> > At the time of first initialization of Koji database tables and
> > functions don't exist. This isn't really a problem as SQL commands
> > later in the script create them.
> >
> > For non-existent tables or functions psql prints NOTICE instead of
> > an ERROR. Therefore one can check if database was initialized
> > correctly with ON_ERROR_STOP set (see psql(1)):
> >
> >      psql returns 3 if an error occurred in a script and the
> > variable ON_ERROR_STOP was set.
> > ---
> >   docs/schema.sql | 70 +++++++++++++++++++++++++++
> > +----------------------------- 1 file changed, 35 insertions(+), 35
> > deletions(-)
> >
> > diff --git a/docs/schema.sql b/docs/schema.sql
> > index 56418c9..7a46f7f 100644
> > --- a/docs/schema.sql
> > +++ b/docs/schema.sql
> > @@ -1,56 +1,56 @@
> >
> >   -- vim:noet:sw=8
> >   -- still needs work
> > -DROP TABLE build_notifications;
> > +DROP TABLE IF EXISTS build_notifications;
> >
> > -DROP TABLE log_messages;
> > +DROP TABLE IF EXISTS log_messages;
> >
> > -DROP TABLE buildroot_listing;
> > -DROP TABLE image_listing;
> > +DROP TABLE IF EXISTS buildroot_listing;
> > +DROP TABLE IF EXISTS image_listing;
> >
> > -DROP TABLE rpminfo;
> > -DROP TABLE image_builds;
> > -DROP TABLE image_archives;
> > +DROP TABLE IF EXISTS rpminfo;
> > +DROP TABLE IF EXISTS image_builds;
> > +DROP TABLE IF EXISTS image_archives;
> >
> > -DROP TABLE group_package_listing;
> > -DROP TABLE group_req_listing;
> > -DROP TABLE group_config;
> > -DROP TABLE groups;
> > +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 tag_listing;
> > -DROP TABLE tag_packages;
> > +DROP TABLE IF EXISTS tag_listing;
> > +DROP TABLE IF EXISTS tag_packages;
> >
> > -DROP TABLE buildroot;
> > -DROP TABLE repo;
> > +DROP TABLE IF EXISTS buildroot;
> > +DROP TABLE IF EXISTS repo;
> >
> > -DROP TABLE build_target_config;
> > -DROP TABLE build_target;
> > +DROP TABLE IF EXISTS build_target_config;
> > +DROP TABLE IF EXISTS build_target;
> >
> > -DROP TABLE tag_config;
> > -DROP TABLE tag_inheritance;
> > -DROP TABLE tag;
> > +DROP TABLE IF EXISTS tag_config;
> > +DROP TABLE IF EXISTS tag_inheritance;
> > +DROP TABLE IF EXISTS tag;
> >
> > -DROP TABLE build;
> > +DROP TABLE IF EXISTS build;
> >
> > -DROP TABLE task;
> > +DROP TABLE IF EXISTS task;
> >
> > -DROP TABLE host_channels;
> > -DROP TABLE host;
> > +DROP TABLE IF EXISTS host_channels;
> > +DROP TABLE IF EXISTS host;
> >
> > -DROP TABLE channels;
> > -DROP TABLE package;
> > +DROP TABLE IF EXISTS channels;
> > +DROP TABLE IF EXISTS package;
> >
> > -DROP TABLE user_groups;
> > -DROP TABLE user_perms;
> > -DROP TABLE permissions;
> > +DROP TABLE IF EXISTS user_groups;
> > +DROP TABLE IF EXISTS user_perms;
> > +DROP TABLE IF EXISTS permissions;
> >
> > -DROP TABLE sessions;
> > -DROP TABLE users;
> > +DROP TABLE IF EXISTS sessions;
> > +DROP TABLE IF EXISTS users;
> >
> > -DROP TABLE event_labels;
> > -DROP TABLE events;
> > -DROP FUNCTION get_event();
> > -DROP FUNCTION get_event_time(INTEGER);
> > +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);
> >
> >   BEGIN WORK;
> >
> >
> 
> 
> -- 
> Pavol Babincak
> Release Engineering, Red Hat
> --
> buildsys mailing list
> buildsys at lists.fedoraproject.org
> https://admin.fedoraproject.org/mailman/listinfo/buildsys


More information about the buildsys mailing list