From b7fc842dfeb73d153db0edb92d0561a89365f41c Mon Sep 17 00:00:00 2001 From: mprahl Date: May 16 2018 12:13:57 +0000 Subject: Allow longer Build Target names --- diff --git a/docs/schema-upgrade-1.16-1.17.sql b/docs/schema-upgrade-1.16-1.17.sql new file mode 100644 index 0000000..9ee2254 --- /dev/null +++ b/docs/schema-upgrade-1.16-1.17.sql @@ -0,0 +1,10 @@ +-- upgrade script to migrate the Koji database schema +-- from version 1.16 to 1.17 + + +BEGIN; + +-- Change VARCHAR field for build_target names to TEXT to allow longer names +ALTER TABLE build_target ALTER COLUMN name TYPE TEXT; + +COMMIT; diff --git a/docs/schema.sql b/docs/schema.sql index e418a77..e525e86 100644 --- a/docs/schema.sql +++ b/docs/schema.sql @@ -408,7 +408,7 @@ CREATE INDEX tag_updates_by_event ON tag_updates (update_event); -- and how to tag it afterwards. CREATE TABLE build_target ( id SERIAL NOT NULL PRIMARY KEY, - name VARCHAR(50) UNIQUE NOT NULL + name TEXT UNIQUE NOT NULL ) WITHOUT OIDS; diff --git a/hub/kojihub.py b/hub/kojihub.py index af87e77..3087e88 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -2669,10 +2669,18 @@ def set_tag_update(tag_id, utype, event_id=None, user_id=None): insert = InsertProcessor('tag_updates', data=data) insert.execute() +def _validate_build_target_name(name): + """ A helper function that validates a build target name. """ + max_name_length = 256 + if len(name) > max_name_length: + raise koji.GenericError("Build target name %s is too long. Max length " + "is %s characters" % (name, max_name_length)) + def create_build_target(name, build_tag, dest_tag): """Create a new build target""" context.session.assertPerm('admin') + _validate_build_target_name(name) # Does a target with this name already exist? if get_build_targets(info=name): @@ -2702,6 +2710,7 @@ def create_build_target(name, build_tag, dest_tag): def edit_build_target(buildTargetInfo, name, build_tag, dest_tag): """Set the build_tag and dest_tag of an existing build_target to new values""" context.session.assertPerm('admin') + _validate_build_target_name(name) target = lookup_build_target(buildTargetInfo) if not target: