Closed Bug 290405 Opened 20 years ago Closed 20 years ago

bz_add_column needs a way to specify an initial value

Categories

(Bugzilla :: Installation & Upgrading, enhancement, P1)

2.19.2
enhancement

Tracking

()

RESOLVED FIXED
Bugzilla 2.20

People

(Reporter: mkanat, Assigned: mkanat)

References

Details

Attachments

(1 file, 1 obsolete file)

Right now, bz_add_column dies if you try to create a NOT NULL column with no default. This makes life really difficult, because it means that checksetup would be full of bz_add_column with a bz_alter_column immediately afterward. (Add the column with a default, and then immediately remove it.) That's not friendly to developers, and it also causes a few problems with certain types of columns. (For example, it's really difficult to call bz_alter_column on any column which is a PRIMARY KEY in MySQL, currently.) Instead, bz_add_column should be able to specify an "initial value" for the column. Then, Bugzilla::DB::Schema implementations can just create the column as NULL, set it to a default value, and then set it to NOT NULL. That's much cleaner from the caller's perspective.
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → Bugzilla 2.20
Attached patch Add the init_value parameter (obsolete) — Splinter Review
OK, this is directly part of bug 285722; I pretty much just edited the diff down.
Attachment #180758 - Flags: review?(Tomas.Kopal)
Comment on attachment 180758 [details] [diff] [review] Add the init_value parameter > # You can't add a NOT NULL column to a table with >- # no DEFAULT statement. >- if ($new_def->{NOTNULL} && !exists $new_def->{DEFAULT}) { >+ # no DEFAULT statement, unless you have an init_value. >+ if ( $new_def->{NOTNULL} && !exists $new_def->{DEFAULT} >+ && !defined $init_value) >+ { > die "Failed adding the column ${table}.${name}:\n You cannot add" >- . " a NOT NULL column with no default to an existing table.\n"; >+ . " a NOT NULL column with no default to an existing table,.\n" >+ . " unless you specify something for \$init_value." >+ # SERIAL types are an exception, though, because they can >+ # auto-populate. >+ unless $new_def->{TYPE} =~ /SERIAL/; Please, move this to the if condition above, it's a bit convoluted to have the condition split like this. >+ # XXX - Note that although this works for MySQL, most databases will fail >+ # before this point, if we haven't set a default. >+ (push(@statements, "UPDATE $table SET $column = $init_value")) >+ if defined $init_value; Judging by the XXX, this is something you plan to fix in the future? Or will this stay as it is an be fixed by overriding this method for every DB, as is the case of Pg? Why the XXX then?
Attachment #180758 - Flags: review?(Tomas.Kopal) → review-
(In reply to comment #2) > Judging by the XXX, this is something you plan to fix in the future? Or will > this stay as it is an be fixed by overriding this method for every DB, as is > the case of Pg? Why the XXX then? Yes, I do plan to fix it in the future, if it's ever necessary to fix. The comment is in the code so that if somebody runs into the bug when they're trying to implement the driver, they'll know what they have to do. It's not necessary to fix for 2.20, though.
Attached patch v2Splinter Review
OK, I fixed the condition. I agree; it's much clearer this way.
Attachment #180758 - Attachment is obsolete: true
Attachment #180761 - Flags: review?(Tomas.Kopal)
Attachment #180761 - Flags: review?(Tomas.Kopal) → review+
Flags: approval?
Flags: approval? → approval+
Checking in Bugzilla/DB.pm; /cvsroot/mozilla/webtools/bugzilla/Bugzilla/DB.pm,v <-- DB.pm new revision: 1.45; previous revision: 1.44 done Checking in Bugzilla/DB/Schema.pm; /cvsroot/mozilla/webtools/bugzilla/Bugzilla/DB/Schema.pm,v <-- Schema.pm new revision: 1.21; previous revision: 1.20 done Checking in Bugzilla/DB/Schema/Pg.pm; /cvsroot/mozilla/webtools/bugzilla/Bugzilla/DB/Schema/Pg.pm,v <-- Pg.pm new revision: 1.8; previous revision: 1.7 done
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: