From 17cf16167f43217f8f878693347b1e170126daaa Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Wed, 5 Nov 2008 23:27:11 +0000 Subject: Bug 460421: [Oracle] Adding custom fields with type FIELD_TYPE_MULTI_SELECT requires a unique constraint on the "value" column Patch By Xiaoou Wu r=mkanat, a=mkanat --- Bugzilla/DB.pm | 2 +- Bugzilla/DB/Oracle.pm | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'Bugzilla') diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index cc4ddb9aa..ff3ea0d4c 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -684,7 +684,7 @@ sub bz_add_field_tables { if ($field->type == FIELD_TYPE_MULTI_SELECT) { my $ms_table = "bug_" . $field->name; $self->_bz_add_field_table($ms_table, - $self->_bz_schema->MULTI_SELECT_VALUE_TABLE); + $self->_bz_schema->MULTI_SELECT_VALUE_TABLE, $field->type); $self->bz_add_fk($ms_table, 'bug_id', {TABLE => 'bugs', COLUMN => 'bug_id', diff --git a/Bugzilla/DB/Oracle.pm b/Bugzilla/DB/Oracle.pm index c8195d4a7..854b72a43 100644 --- a/Bugzilla/DB/Oracle.pm +++ b/Bugzilla/DB/Oracle.pm @@ -208,6 +208,15 @@ sub sql_in { return "( " . join(" OR ", @in_str) . " )"; } +sub _bz_add_field_table { + my ($self, $name, $schema_ref, $type) = @_; + $self->SUPER::_bz_add_field_table($name, $schema_ref); + if (defined($type) && $type == FIELD_TYPE_MULTI_SELECT) { + my $uk_name = "UK_" . $self->_bz_schema->_hash_identifier($name . '_value'); + $self->do("ALTER TABLE $name ADD CONSTRAINT $uk_name UNIQUE(value)"); + } +} + sub bz_drop_table { my ($self, $name) = @_; my $table_exists = $self->bz_table_info($name); -- cgit v1.2.1