Bugzilla (bugzilla.redhat.com) will be under maintenance for infrastructure upgrades and will not be unavailable on July 31st between 12:30 AM - 05:30 AM UTC. We appreciate your understanding and patience. You can follow status.redhat.com for details.
Bug 1409726 - Database creation fails with SQL error
Summary: Database creation fails with SQL error
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Bugzilla
Classification: Community
Component: Database
Version: 5.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jeff Fearn 🐞
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-01-03 07:13 UTC by Yuxiang Zhu
Modified: 2017-01-20 03:19 UTC (History)
3 users (show)

Fixed In Version: 5.0.3.rh22
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-01-20 03:19:57 UTC


Attachments (Terms of Use)

Description Yuxiang Zhu 2017-01-03 07:13:17 UTC
Description of problem:
Running /usr/share/rh-bugzilla/bin/rh-database-update.pl against an empty DB will get a SQL syntax error.

Version-Release number of selected component (if applicable):
5.0.3-rh20


Additional info:

Now filling the 'status_workflow' table with valid bug status transitions for Red Hat...
Adding new column 'last_used' to the 'namedquery_group_map' table...
DBD::Pg::db do failed: ERROR:  column "now" does not exist
<pre>
 at /var/www/html/bugzilla//Bugzilla/DB.pm line 667.
        Bugzilla::DB::bz_add_column('Bugzilla::DB::Pg=HASH(0x7d9d5b0)', 'namedquery_group_map', 'last_used', 'HASH(0x8054038)') called at /var/www/html/bugzilla/extensions/SchemaChange/Extension.pm line 224
        Bugzilla::Extension::SchemaChange::install_update_db('Bugzilla::Extension::SchemaChange=HASH(0x7c56b68)', undef) called at /var/www/html/bugzilla//Bugzilla/Hook.pm line 20
        Bugzilla::Hook::process('install_update_db') called at /var/www/html/bugzilla//Bugzilla/Install/DB.pm line 739
        Bugzilla::Install::DB::update_table_definitions('HASH(0x40f7ed8)') called at /usr/share/rh-bugzilla/bin/rh-database-update.pl line 59

</pre> at /var/www/html/bugzilla//Bugzilla/DB.pm line 667.

Since PostgreSQL doesn't allow omit the parentheses when using with DEFAULT, we have to add the parentheses explicitly:

From 9e71d7959b2e08f2fd69927b5cf72fc75d39a559 Mon Sep 17 00:00:00 2001
From: Yuxiang Zhu <vfreex+git@gmail.com>
Date: Tue, 3 Jan 2017 13:57:21 +0800
Subject: [PATCH] Fix a syntax error when performing DB schema migration.

Parentheses cannot be omitted if using with DEFAULT
(https://www.postgresql.org/docs/9.1/static/functions-datetime.html).
---
 extensions/SchemaChange/Extension.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extensions/SchemaChange/Extension.pm b/extensions/SchemaChange/Extension.pm
index 4d3a667..32fe1a3 100644
--- a/extensions/SchemaChange/Extension.pm
+++ b/extensions/SchemaChange/Extension.pm
@@ -222,7 +222,7 @@ sub install_update_db {
     # This will monitor when a saved search was lased used, so it can be
     # removed after an expiry period.
     $dbh->bz_add_column('namedquery_group_map', 'last_used',
-        { TYPE => 'DATETIME', 'DEFAULT' => 'now', NOTNULL => 1});
+        { TYPE => 'DATETIME', 'DEFAULT' => 'now()', NOTNULL => 1});
     # REDHAT EXTENSION END 523845
 
     # REDHAT EXTENSION START 876015
-- 
2.9.3

Comment 1 Rony Gong 🔥 2017-01-19 02:20:18 UTC
Tested on QA environment(5.0.3-rh22)
Result: Pass


Note You need to log in before you can comment on or make changes to this bug.