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)
Tracking
()
RESOLVED
FIXED
Bugzilla 2.20
People
(Reporter: mkanat, Assigned: mkanat)
References
Details
Attachments
(1 file, 1 obsolete file)
|
5.92 KB,
patch
|
Tomas.Kopal
:
review+
|
Details | Diff | Splinter Review |
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.
| Assignee | ||
Updated•20 years ago
|
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → Bugzilla 2.20
| Assignee | ||
Comment 1•20 years ago
|
||
OK, this is directly part of bug 285722; I pretty much just edited the diff
down.
Attachment #180758 -
Flags: review?(Tomas.Kopal)
Comment 2•20 years ago
|
||
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-
| Assignee | ||
Comment 3•20 years ago
|
||
(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.
| Assignee | ||
Comment 4•20 years ago
|
||
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)
Comment 5•20 years ago
|
||
Comment on attachment 180761 [details] [diff] [review]
v2
Nice.
Attachment #180761 -
Flags: review?(Tomas.Kopal) → review+
| Assignee | ||
Updated•20 years ago
|
Flags: approval?
Updated•20 years ago
|
Flags: approval? → approval+
| Assignee | ||
Comment 6•20 years ago
|
||
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.
Description
•