Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Ivlev
bugzilla
Commits
89edfad4
Commit
89edfad4
authored
Nov 01, 2006
by
mkanat%bugzilla.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 358956: [PostgreSQL] Sequences need to be renamed when their field is renamed
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=myk
parent
e698452f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
Pg.pm
Bugzilla/DB/Pg.pm
+19
-0
Pg.pm
Bugzilla/DB/Schema/Pg.pm
+10
-2
No files found.
Bugzilla/DB/Pg.pm
View file @
89edfad4
...
...
@@ -207,6 +207,15 @@ sub bz_unlock_tables {
}
}
# Tell us whether or not a particular sequence exists in the DB.
sub
bz_sequence_exists
{
my
(
$self
,
$seq_name
)
=
@_
;
my
$exists
=
$self
->
selectrow_array
(
'SELECT 1 FROM pg_statio_user_sequences WHERE relname = ?'
,
undef
,
$seq_name
);
return
$exists
||
0
;
}
#####################################################################
# Custom Database Setup
#####################################################################
...
...
@@ -236,6 +245,16 @@ sub bz_setup_database {
_fix_case_differences
(
'products'
,
'name'
);
$self
->
bz_add_index
(
'products'
,
'products_name_lower_idx'
,
{
FIELDS
=>
[
'LOWER(name)'
],
TYPE
=>
'UNIQUE'
});
# bz_rename_column didn't correctly rename the sequence.
if
(
$self
->
bz_column_info
(
'fielddefs'
,
'id'
)
&&
$self
->
bz_sequence_exists
(
'fielddefs_fieldid_seq'
))
{
print
"Fixing fielddefs_fieldid_seq sequence...\n"
;
$self
->
do
(
"ALTER TABLE fielddefs_fieldid_seq RENAME TO fielddefs_id_seq"
);
$self
->
do
(
"ALTER TABLE fielddefs ALTER COLUMN id
SET DEFAULT NEXTVAL('fielddefs_id_seq')"
);
}
}
# Renames things that differ only in case.
...
...
Bugzilla/DB/Schema/Pg.pm
View file @
89edfad4
...
...
@@ -92,8 +92,16 @@ sub _initialize {
sub
get_rename_column_ddl
{
my
(
$self
,
$table
,
$old_name
,
$new_name
)
=
@_
;
return
(
"ALTER TABLE $table RENAME COLUMN $old_name TO $new_name"
);
my
@sql
=
(
"ALTER TABLE $table RENAME COLUMN $old_name TO $new_name"
);
my
$def
=
$self
->
get_column_abstract
(
$table
,
$old_name
);
if
(
$def
->
{
TYPE
}
=~
/SERIAL/i
)
{
# We have to rename the series also, and fix the default of the series.
push
(
@sql
,
"ALTER TABLE ${table}_${old_name}_seq
RENAME TO ${table}_${new_name}_seq"
);
push
(
@sql
,
"ALTER TABLE $table ALTER COLUMN $new_name
SET DEFAULT NEXTVAL('${table}_${new_name}_seq')"
);
}
return
@sql
;
}
sub
_get_alter_type_sql
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment