Closed
Bug 328063
Opened 19 years ago
Closed 19 years ago
[PostgreSQL] Bugzilla::DB::Pg does not support adding a new SERIAL-type column to a table
Categories
(Bugzilla :: Installation & Upgrading, defect)
Tracking
()
RESOLVED
FIXED
Bugzilla 3.0
People
(Reporter: LpSolit, Assigned: mkanat)
References
Details
(Keywords: regression)
Attachments
(1 file)
2.86 KB,
patch
|
LpSolit
:
review+
|
Details | Diff | Splinter Review |
Here is what I get, on PostgreSQL only:
checksetup.pl: NOT NULL columns must have a DEFAULT or an init_value. at Bugzilla/DB/Schema/Pg.pm line 122.
This is probably a regression due to bug 225221.
Reporter | ||
Updated•19 years ago
|
Version: 2.21 → 2.23
Assignee | ||
Comment 1•19 years ago
|
||
This *should* be happening on all DBs. That code is supposed to be present in the base DB.pm.
Severity: normal → critical
Summary: Upgrading to 2.23 on PostgreSQL generates an error → [PostgreSQL] Upgrading to 2.23 on PostgreSQL generates an error
Assignee | ||
Updated•19 years ago
|
Summary: [PostgreSQL] Upgrading to 2.23 on PostgreSQL generates an error → [PostgreSQL] Bugzilla::DB::Pg does not support adding a new SERIAL-type Primary Key to a table
Assignee | ||
Comment 2•19 years ago
|
||
Okay, here's the problem:
$dbh->bz_add_column('longdescs', 'comment_id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
And in Pg.pm:
if ($definition->{NOTNULL}) {
# Handle rows that were NULL when we added the column.
# We *must* have a DEFAULT. This check is usually handled
# at a higher level than this code, but I figure it can't
# hurt to have it here.
die "NOT NULL columns must have a DEFAULT or an init_value."
unless (exists $definition->{DEFAULT} || defined $init_value);
push(@statements, "UPDATE $table SET $column = $default");
push(@statements, "ALTER TABLE $table ALTER COLUMN $column "
. " SET NOT NULL");
}
What the code doesn't realize is that these SERIAL fields should be somehow automatically adding themselves and numbering things. How that happens in Pg, I'm really not sure.
Assignee | ||
Comment 3•19 years ago
|
||
Okay, even fixing that, the problem is:
[Tue Feb 21 14:17:35 2006] checksetup.pl: DBD::Pg::db do failed: ERROR: adding columns with defaults is not implemented [for Statement "ALTER TABLE longdescs ADD COLUMN comment_id serial unique"] at Bugzilla/DB.pm line 374
[Tue Feb 21 14:17:35 2006] checksetup.pl: Bugzilla::DB::bz_add_column('Bugzilla::DB::Pg=HASH(0xa23dae4)', 'longdescs', 'comment_id', 'HASH(0xa3699f8)') called at ./checksetup.pl line 4274
Basically, Pg 7.x doesn't support what we're trying to do. It can be done, though, I just have to work around it slightly.
Assignee | ||
Updated•19 years ago
|
Summary: [PostgreSQL] Bugzilla::DB::Pg does not support adding a new SERIAL-type Primary Key to a table → [PostgreSQL] Bugzilla::DB::Pg does not support adding a new SERIAL-type column to a table
Assignee | ||
Comment 4•19 years ago
|
||
Okay, so here's what the problem was:
In PostgreSQL, a SERIAL type is actually translated to: "DEFAULT nextval('$table_$column_seq')" -- but Pg 7.x can't add a column that has a DEFAULT. You have to ALTER TABLE the column to add the default later.
So now for SERIAL types we fix this.
I also noticed that get_add_column_ddl for PostgreSQL didn't support adding a PRIMARY KEY, so I fixed that, too (it was just a small syntax error).
Finally, I dclone($definition), because otherwise the changes in $definition would have been passed back on to the caller and stored in bz_schema (which we don't want).
Reporter | ||
Comment 5•19 years ago
|
||
Comment on attachment 212653 [details] [diff] [review]
v1 (Fix Pg Backend to be able to add SERIAL types)
Tested on both an existing and a new installation. Works fine! r=LpSolit
Attachment #212653 -
Flags: review?(LpSolit) → review+
Reporter | ||
Updated•19 years ago
|
Flags: approval?
Updated•19 years ago
|
Flags: approval? → approval+
Assignee | ||
Comment 6•19 years ago
|
||
Checking in Bugzilla/DB/Schema/Pg.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/DB/Schema/Pg.pm,v <-- Pg.pm
new revision: 1.10; previous revision: 1.9
done
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•