summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Schema
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-03-18 12:21:33 +0100
committermkanat%kerio.com <>2005-03-18 12:21:33 +0100
commit17844d976d7036582f7b8204bdde7ac2429b1a38 (patch)
tree1bca6a2642d1c62ab135b73c969c3fe1f4f5c582 /Bugzilla/DB/Schema
parent524e72e5ed46ceddc650c33dcbb759125b80ed83 (diff)
downloadbugzilla-17844d976d7036582f7b8204bdde7ac2429b1a38.tar.gz
bugzilla-17844d976d7036582f7b8204bdde7ac2429b1a38.tar.xz
Bug 285723: Cross-DB bz_add_column (Part of Bug 285111)
Patch By Max Kanat-Alexander <mkanat@kerio.com> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB/Schema')
-rw-r--r--Bugzilla/DB/Schema/Pg.pm42
1 files changed, 39 insertions, 3 deletions
diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm
index 795ad53ff..3a45744bb 100644
--- a/Bugzilla/DB/Schema/Pg.pm
+++ b/Bugzilla/DB/Schema/Pg.pm
@@ -44,12 +44,14 @@ sub _initialize {
if ($self->{schema}{$table}{INDEXES}) {
foreach my $index (@{ $self->{schema}{$table}{INDEXES} }) {
if (ref($index) eq 'HASH') {
- delete($index->{TYPE}) if ($index->{TYPE} eq 'FULLTEXT');
+ delete($index->{TYPE}) if (exists $index->{TYPE}
+ && $index->{TYPE} eq 'FULLTEXT');
}
}
foreach my $index (@{ $self->{abstract_schema}{$table}{INDEXES} }) {
if (ref($index) eq 'HASH') {
- delete($index->{TYPE}) if ($index->{TYPE} eq 'FULLTEXT');
+ delete($index->{TYPE}) if (exists $index->{TYPE}
+ && $index->{TYPE} eq 'FULLTEXT');
}
}
}
@@ -85,5 +87,39 @@ sub _initialize {
return $self;
} #eosub--_initialize
-#------------------------------------------------------------------------------
+#--------------------------------------------------------------------
+
+# Overridden because Pg has such weird ALTER TABLE problems.
+sub get_add_column_ddl {
+ my ($self, $table, $column, $definition) = @_;
+
+ my @statements;
+ my $specific = $self->{db_specific};
+
+ my $type = $definition->{TYPE};
+ $type = $specific->{$type} if exists $specific->{$type};
+ push(@statements, "ALTER TABLE $table ADD COLUMN $column $type");
+
+ my $default = $definition->{DEFAULT};
+ # Replace any abstract default value (such as 'TRUE' or 'FALSE')
+ # with its database-specific implementation.
+ if (defined $default) {
+ $default = $specific->{$default} if exists $specific->{$default};
+ push(@statements, "ALTER TABLE $table ALTER COLUMN $column "
+ . " SET DEFAULT $default");
+ }
+
+ if ($definition->{NOTNULL}) {
+ push(@statements, "ALTER TABLE $table ALTER COLUMN $column "
+ . " SET NOT NULL");
+ }
+
+ if ($definition->{PRIMARYKEY}) {
+ push(@statements, "ALTER TABLE $table ALTER COLUMN $column "
+ . " SET ADD PRIMARY KEY");
+ }
+
+ return @statements;
+}
+
1;