summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/DB.pm31
-rw-r--r--Bugzilla/DB/Oracle.pm23
-rw-r--r--Bugzilla/DB/Schema.pm6
-rw-r--r--Bugzilla/DB/Schema/Mysql.pm6
-rw-r--r--Bugzilla/DB/Schema/Oracle.pm29
-rw-r--r--Bugzilla/Install/Util.pm2
6 files changed, 82 insertions, 15 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 49692eec0..f97273e1a 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -504,6 +504,19 @@ sub bz_setup_foreign_keys {
}
}
+# This is used by contrib/bzdbcopy.pl, mostly.
+sub bz_drop_foreign_keys {
+ my ($self) = @_;
+
+ my @tables = $self->_bz_real_schema->get_table_list();
+ foreach my $table (@tables) {
+ my @columns = $self->_bz_real_schema->get_table_columns($table);
+ foreach my $column (@columns) {
+ $self->bz_drop_fk($table, $column);
+ }
+ }
+}
+
#####################################################################
# Schema Modification Methods
#####################################################################
@@ -749,6 +762,24 @@ sub bz_drop_column {
}
}
+sub bz_drop_fk {
+ my ($self, $table, $column) = @_;
+
+ my $col_def = $self->bz_column_info($table, $column);
+ if ($col_def && exists $col_def->{REFERENCES}) {
+ my $def = $col_def->{REFERENCES};
+ print get_text('install_fk_drop',
+ { table => $table, column => $column, fk => $def })
+ . "\n" if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
+ my @sql = $self->_bz_real_schema->get_drop_fk_sql($table,$column,$def);
+ $self->do($_) foreach @sql;
+ delete $col_def->{REFERENCES};
+ $self->_bz_real_schema->set_column($table, $column, $col_def);
+ $self->_bz_store_real_schema;
+ }
+
+}
+
sub bz_drop_index {
my ($self, $table, $name) = @_;
diff --git a/Bugzilla/DB/Oracle.pm b/Bugzilla/DB/Oracle.pm
index 509dedaa1..a970e3193 100644
--- a/Bugzilla/DB/Oracle.pm
+++ b/Bugzilla/DB/Oracle.pm
@@ -406,7 +406,30 @@ sub quote_identifier {
return $id;
}
+#####################################################################
+# Protected "Real Database" Schema Information Methods
+#####################################################################
+sub bz_table_columns_real {
+ my ($self, $table) = @_;
+ $table = uc($table);
+ my @cols = $self->SUPER::bz_table_columns_real($table);
+ return map { lc($_) } @cols;
+}
+
+sub bz_table_list_real {
+ my ($self) = @_;
+ # Oracle only accepts the username in uppercase.
+ my $db_user = uc(Bugzilla->localconfig->{db_user});
+ my $table_sth = $self->table_info(undef, $db_user, undef, "TABLE");
+ my @tables = @{$self->selectcol_arrayref($table_sth, { Columns => [3] })};
+ # Oracle returns uppercase table names, but Bugzilla expects lowercase
+ # names.
+ @tables = map { lc($_) } @tables;
+ # Oracle has certain tables that start with DR$_IDX.
+ @tables = grep { $_ !~ /^dr\$/ } @tables;
+ return @tables;
+}
#####################################################################
# Custom Database Setup
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm
index 023f01860..2be64cab3 100644
--- a/Bugzilla/DB/Schema.pm
+++ b/Bugzilla/DB/Schema.pm
@@ -1533,9 +1533,9 @@ sub get_add_fk_sql {
return ("ALTER TABLE $table ADD $fk_string");
}
-sub _get_drop_fk_sql {
- my ($self, $table, $column, $old_def) = @_;
- my $fk_name = $self->_get_fk_name($table, $column, $old_def->{REFERENCES});
+sub get_drop_fk_sql {
+ my ($self, $table, $column, $references) = @_;
+ my $fk_name = $self->_get_fk_name($table, $column, $references);
return ("ALTER TABLE $table DROP CONSTRAINT $fk_name");
}
diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm
index 300b1a0f1..2f4bc42b2 100644
--- a/Bugzilla/DB/Schema/Mysql.pm
+++ b/Bugzilla/DB/Schema/Mysql.pm
@@ -193,9 +193,9 @@ sub get_alter_column_ddl {
return @statements;
}
-sub _get_drop_fk_sql {
- my ($self, $table, $column, $old_def) = @_;
- my $fk_name = $self->_get_fk_name($table, $column, $old_def->{REFERENCES});
+sub get_drop_fk_sql {
+ my ($self, $table, $column, $references) = @_;
+ my $fk_name = $self->_get_fk_name($table, $column, $references);
my @sql = ("ALTER TABLE $table DROP FOREIGN KEY $fk_name");
my $dbh = Bugzilla->dbh;
diff --git a/Bugzilla/DB/Schema/Oracle.pm b/Bugzilla/DB/Schema/Oracle.pm
index 77024507b..8f0f880be 100644
--- a/Bugzilla/DB/Schema/Oracle.pm
+++ b/Bugzilla/DB/Schema/Oracle.pm
@@ -93,7 +93,7 @@ sub get_table_ddl {
}
# Create sequences and triggers to emulate SERIAL datatypes.
if ( $field_info->{TYPE} =~ /SERIAL/i ) {
- push (@ddl, _get_create_seq_ddl($table, $field_name));
+ push (@ddl, $self->_get_create_seq_ddl($table, $field_name));
}
}
return @ddl;
@@ -140,17 +140,17 @@ sub get_fk_ddl {
$fk_string = $fk_string . " ON DELETE $delete" if $delete;
if ( $update =~ /CASCADE/i ){
- my $tr_str = "CREATE OR REPLACE TRIGGER ". $table . "_uc"
+ my $tr_str = "CREATE OR REPLACE TRIGGER ${fk_name}_UC"
. " AFTER UPDATE ON ". $table
. " REFERENCING "
. " NEW AS NEW "
. " OLD AS OLD "
. " FOR EACH ROW "
. " BEGIN "
- . " UPDATE ". $to_table
- . " SET ". $to_column . " = :NEW.". $column
- . " WHERE ". $to_column . " = :OLD.". $column . ";"
- . " END ". $table . "_uc;";
+ . " UPDATE $to_table"
+ . " SET $to_column = :NEW.$column"
+ . " WHERE $to_column = :OLD.$column;"
+ . " END ${fk_name}_UC;";
my $dbh = Bugzilla->dbh;
$dbh->do($tr_str);
}
@@ -158,6 +158,18 @@ sub get_fk_ddl {
return $fk_string;
}
+sub get_drop_fk_sql {
+ my $self = shift;
+ my ($table, $column, $references) = @_;
+ my $fk_name = $self->_get_fk_name(@_);
+ my @sql;
+ if (!$references->{UPDATE} || $references->{UPDATE} =~ /CASCADE/i) {
+ push(@sql, "DROP TRIGGER ${fk_name}_uc");
+ }
+ push(@sql, $self->SUPER::get_drop_fk_sql(@_));
+ return @sql;
+}
+
sub _get_fk_name {
my ($self, $table, $column, $references) = @_;
my $to_table = $references->{TABLE};
@@ -185,12 +197,13 @@ sub _get_notnull_trigger_ddl {
}
sub _get_create_seq_ddl {
- my ($table, $column) = @_;
+ my ($self, $table, $column, $start_with) = @_;
+ $start_with ||= 1;
my @ddl;
my $seq_name = "${table}_${column}_SEQ";
my $seq_sql = "CREATE SEQUENCE $seq_name "
. " INCREMENT BY 1 "
- . " START WITH 1 "
+ . " START WITH $start_with "
. " NOMAXVALUE "
. " NOCYCLE "
. " NOCACHE";
diff --git a/Bugzilla/Install/Util.pm b/Bugzilla/Install/Util.pm
index 3942aa82a..67aeb4873 100644
--- a/Bugzilla/Install/Util.pm
+++ b/Bugzilla/Install/Util.pm
@@ -80,7 +80,7 @@ sub indicate_progress {
my $every = $params->{every} || 1;
print "." if !($current % $every);
- if ($current % ($every * 60) == 0) {
+ if ($current == $total || $current % ($every * 60) == 0) {
print "$current/$total (" . int($current * 100 / $total) . "%)\n";
}
}