<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>409234</bug_id>
          
          <creation_ts>2019-06-27 08:09:28 +0000</creation_ts>
          <short_desc>akonadi with qt5 5.13 is unable to initialize database when using the PostgreSQL backend</short_desc>
          <delta_ts>2020-03-22 19:26:50 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>Frameworks and Libraries</classification>
          <product>Akonadi</product>
          <component>server</component>
          <version>unspecified</version>
          <rep_platform>Arch Linux</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.kde.org/show_bug.cgi?id=409753</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="nl6720">bugs.kde.org</reporter>
          <assigned_to name="kdepim bugs">pim-bugs-null</assigned_to>
          <cc>arojas</cc>
    
    <cc>bugs.kde.org</cc>
    
    <cc>dvratil</cc>
    
    <cc>eclipseo</cc>
    
    <cc>heiko.becker</cc>
    
    <cc>v.pupillo</cc>
          
          <cf_commitlink>https://commits.kde.org/akonadi/74aed9542ba1ff1e6e93a550c42869647c4eba8e</cf_commitlink>
          <cf_versionfixedin>5.11.3</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1865834</commentid>
    <comment_count>0</comment_count>
    <who name="nl6720">bugs.kde.org</who>
    <bug_when>2019-06-27 08:09:28 +0000</bug_when>
    <thetext>SUMMARY

After upgrading qt5 packages to 5.13, akonadiserver is &quot;Unable to initialize database&quot; when using PostgreSQL.

The issue appears to be caused by https://github.com/qt/qtbase/commit/461ef575bcf778ba24b0be6b775098d4b80ae5e1 .

STEPS TO REPRODUCE
1. Configure akonadi to use PostgreSQL.
2. run `akonadictl start`.

OBSERVED RESULT

Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
org.kde.pim.akonadiserver: Starting up the Akonadi Server...
org.kde.pim.akonadiserver: Running DB initializer
org.kde.pim.akonadiserver: &quot;\nSql error: ERROR:  column \&quot;version\&quot; of relation \&quot;schemaversiontable\&quot; already exists\n(42701) QPSQL: Unable to create query\nQuery: ALTER TABLE SchemaVersionTable ADD COLUMN version INTEGER NOT NULL DEFAULT 0&quot;
org.kde.pim.akonadiserver: Unable to initialize database.
waiting for server to shut down.... done
server stopped
org.kde.pim.akonadiserver: Shutting down AkonadiServer...
org.kde.pim.akonadicontrol: Application &apos;/usr/bin/akonadiserver&apos; exited normally...

EXPECTED RESULT

org.kde.pim.akonadiserver: Starting up the Akonadi Server...                                                                                 
org.kde.pim.akonadiserver: Running DB initializer
org.kde.pim.akonadiserver: DB initializer done
...

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.16.2
KDE Frameworks Version: 5.59.0
Qt Version: 5.13.0

akonadi 19.04.2-3
qt5-base 5.13.0-4
postgresql 11.4-1

ADDITIONAL INFORMATION

Arch Linux bug: https://bugs.archlinux.org/task/62997</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1865901</commentid>
    <comment_count>1</comment_count>
      <attachid>121187</attachid>
    <who name="Daniel Vrátil">dvratil</who>
    <bug_when>2019-06-27 14:42:03 +0000</bug_when>
    <thetext>Created attachment 121187
Akonadi patch to fix compatibility with Qt 5.13 QPSQL driver

Would you (or anyone else using PSQL and Qt 5.13) be able to build Akonadi with the attached patch and test it?

I don&apos;t have access to a machine with Qt 5.13 right now, so I&apos;m just guessing from the Qt commit. If the patch doesn&apos;t work I&apos;ll try to update to 5.13 over the weekend...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1865911</commentid>
    <comment_count>2</comment_count>
    <who name="nl6720">bugs.kde.org</who>
    <bug_when>2019-06-27 15:09:26 +0000</bug_when>
    <thetext>akonadi-qt-5.13-psql-case-sensitivity.patch fixes the issue.
Akonadi successfully starts and runs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1866073</commentid>
    <comment_count>3</comment_count>
    <who name="Daniel Vrátil">dvratil</who>
    <bug_when>2019-06-28 14:04:56 +0000</bug_when>
    <thetext>Git commit 74aed9542ba1ff1e6e93a550c42869647c4eba8e by Daniel Vrátil.
Committed on 28/06/2019 at 14:04.
Pushed by dvratil into branch &apos;Applications/19.04&apos;.

Adapt DBInitializer to behavior change of QPSQL driver in Qt 5.13

Summary:
Since Qt 5.13 the QPSQL driver escapes table names, which makes them
case-sensitive, therefore QSqlDatabase::record() must be called with
a lower-case table name, otherwise it won&apos;t match.
FIXED-IN: 5.11.3

Test Plan:
Akonadi doesn&apos;t attempt to re-initialize all tables on each start when
using Qt 5.13

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D22133

M  +1    -1    src/server/storage/dbintrospector.cpp

https://commits.kde.org/akonadi/74aed9542ba1ff1e6e93a550c42869647c4eba8e</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1869238</commentid>
    <comment_count>4</comment_count>
    <who name="Antonio Rojas">arojas</who>
    <bug_when>2019-07-16 13:28:18 +0000</bug_when>
    <thetext>This causes a regression in mysql for some users: https://bugs.kde.org/show_bug.cgi?id=409753</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1871036</commentid>
    <comment_count>5</comment_count>
    <who name="Daniel Vrátil">dvratil</who>
    <bug_when>2019-07-26 11:32:43 +0000</bug_when>
    <thetext>Git commit 8b8db29d10b2ef92deb2d87ff613f3d7f39af34e by Daniel Vrátil.
Committed on 26/07/2019 at 11:32.
Pushed by dvratil into branch &apos;Applications/19.04&apos;.

Fix compatibility with QMYSQL driver after 74aed95

Summary:
QPSQL requires the table name passed to QSqlDatabase::record() to be lowercase
since Qt 5.13, but doing that breaks QMYSQL, so only adjust the name when
using QPSQL.

Reviewers: #kde_pim, vkrause

Reviewed By: #kde_pim, vkrause

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D22677

M  +4    -1    src/server/storage/dbintrospector.cpp

https://commits.kde.org/akonadi/8b8db29d10b2ef92deb2d87ff613f3d7f39af34e</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1892021</commentid>
    <comment_count>6</comment_count>
    <who name="">v.pupillo</who>
    <bug_when>2019-11-17 12:54:53 +0000</bug_when>
    <thetext>Same Issue here after upgrade from Fedora 30 to Fedora 31 ( It appears the akonadi version in Fedora 31 is missing this commit) . I&apos;m use a MariaDB server with many database, for my work. Usually I use the same server for Akonadi, Digikam and all the application that can use mysql/maridb as database. lower_case_table_names=1 breakes the others db. It&apos;s not possible to migrate the tables name from &quot;CamelCase&quot; to a &quot;snake_case&quot;? This solution works in all database server I knowns, even Oracle, DB2 and so on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1892026</commentid>
    <comment_count>7</comment_count>
    <who name="Christophe Marin">christophe</who>
    <bug_when>2019-11-17 13:38:58 +0000</bug_when>
    <thetext>(In reply to v.pupillo from comment #6)
&gt; Same Issue here [...] . I&apos;m use a MariaDB server with many database, for my work.

Hardly the same issue. This report is about the Postgres backend.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1892260</commentid>
    <comment_count>8</comment_count>
    <who name="">v.pupillo</who>
    <bug_when>2019-11-18 21:02:19 +0000</bug_when>
    <thetext>Yes, the backend is different but the problem is the same, it&apos;s a case problem. After upgrade to Fedora 31 (with lower_case_table_names=0), Akonadi said: 
org.kde.pim.akonadiserver: &quot;Sql error: Duplicate column name &apos;id&apos; QMYSQL: Unable to execute query\nQuery: ALTER TABLE CollectionTable ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY&quot;
org.kde.pim.akonadiserver: Unable to initialize database.

Then I dropped the akonadi database and created a new one. With lower_case_table_names=0, Akonadi start and recreate the database. Work fine for a day. The next day Akonadi says: 

org.kde.pim.akonadiserver: &quot;\nSql error: Duplicate column name &apos;id&apos; QMYSQL: Unable to execute query\nQuery: ALTER TABLE CollectionTable ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY&quot;. 

Then I tried with lower_case_table_names=1, akonadi says: 
org.kde.pim.akonadiserver: &quot;\nSql error: Can&apos;t create table `akonadi_vin_new`.`collectiontable` (errno: 121 \&quot;Duplicate key on write or update\&quot;) QMYSQL: Unable to execute query\nQuery: CREATE TABLE CollectionTable (id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, remoteId VARBINARY(255), remoteRevision VARBINARY(255), name VARBINARY(255) NOT NULL, parentId BIGINT, resourceId BIGINT NOT NULL, enabled BOOL NOT NULL DEFAULT true, syncPref TINYINT DEFAULT 2, displayPref TINYINT DEFAULT 2, indexPref TINYINT DEFAULT 2, referenced BOOL NOT NULL DEFAULT false, cachePolicyInherit BOOL NOT NULL DEFAULT true, cachePolicyCheckInterval INTEGER NOT NULL DEFAULT -1, cachePolicyCacheTimeout INTEGER NOT NULL DEFAULT -1, cachePolicySyncOnDemand BOOL NOT NULL DEFAULT false, cachePolicyLocalParts VARBINARY(255), queryString VARBINARY(32768), queryAttributes VARBINARY(255), queryCollections VARBINARY(255), isVirtual BOOL DEFAULT false, FOREIGN KEY (parentId) REFERENCES CollectionTable(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (resourceId) REFERENCES ResourceTable(id) ON UPDATE CASCADE ON DELETE CASCADE)  COLLATE=utf8_general_ci DEFAULT CHARSET=utf8&quot;

This is why I suggest to switch to snake_case tables and columns name, works with all the databases.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1917492</commentid>
    <comment_count>9</comment_count>
    <who name="Robert-André Mauchin">eclipseo</who>
    <bug_when>2020-03-22 17:28:41 +0000</bug_when>
    <thetext>This issue is marked as fixed but I have this bug on Fedora 32 using akonadictl 5.13.2 (19.12.2)

org.kde.pim.akonadiserver: Starting up the Akonadi Server...                                                    18:19:24
org.kde.pim.akonadiserver: Running DB initializer
org.kde.pim.akonadiserver: &quot;\nSql error: ERROR:  column \&quot;version\&quot; of relation \&quot;schemaversiontable\&quot; already exists\n(42701) QPSQL: Unable to create query\nQuery: ALTER TABLE SchemaVersionTable ADD COLUMN version INTEGER NOT NULL DEFAULT 0&quot;
org.kde.pim.akonadiserver: Unable to initialize database.


Can anyone explain why?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1917543</commentid>
    <comment_count>10</comment_count>
    <who name="Robert-André Mauchin">eclipseo</who>
    <bug_when>2020-03-22 19:26:50 +0000</bug_when>
    <thetext>(In reply to Robert-André Mauchin from comment #9)
&gt; This issue is marked as fixed but I have this bug on Fedora 32 using
&gt; akonadictl 5.13.2 (19.12.2)
&gt; 
&gt; org.kde.pim.akonadiserver: Starting up the Akonadi Server...                
&gt; 18:19:24
&gt; org.kde.pim.akonadiserver: Running DB initializer
&gt; org.kde.pim.akonadiserver: &quot;\nSql error: ERROR:  column \&quot;version\&quot; of
&gt; relation \&quot;schemaversiontable\&quot; already exists\n(42701) QPSQL: Unable to
&gt; create query\nQuery: ALTER TABLE SchemaVersionTable ADD COLUMN version
&gt; INTEGER NOT NULL DEFAULT 0&quot;
&gt; org.kde.pim.akonadiserver: Unable to initialize database.
&gt; 
&gt; 
&gt; Can anyone explain why?

Fixed by backporting https://codereview.qt-project.org/c/qt/qtbase/+/277205 to qt5-qtbase 5.13.2</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>121187</attachid>
            <date>2019-06-27 14:42:03 +0000</date>
            <delta_ts>2019-06-27 14:42:03 +0000</delta_ts>
            <desc>Akonadi patch to fix compatibility with Qt 5.13 QPSQL driver</desc>
            <filename>akonadi-qt-5.13-psql-case-sensitivity.patch</filename>
            <type>text/plain</type>
            <size>671</size>
            <attacher name="Daniel Vrátil">dvratil</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL3NyYy9zZXJ2ZXIvc3RvcmFnZS9kYmludHJvc3BlY3Rvci5jcHAgYi9zcmMv
c2VydmVyL3N0b3JhZ2UvZGJpbnRyb3NwZWN0b3IuY3BwCmluZGV4IDIyNGZhZjdmOC4uNzBkOTUy
YTZmIDEwMDY0NAotLS0gYS9zcmMvc2VydmVyL3N0b3JhZ2UvZGJpbnRyb3NwZWN0b3IuY3BwCisr
KyBiL3NyYy9zZXJ2ZXIvc3RvcmFnZS9kYmludHJvc3BlY3Rvci5jcHAKQEAgLTc2LDcgKzc2LDcg
QEAgYm9vbCBEYkludHJvc3BlY3Rvcjo6aGFzQ29sdW1uKGNvbnN0IFFTdHJpbmcgJnRhYmxlTmFt
ZSwgY29uc3QgUVN0cmluZyAmY29sdW1uTmEKICAgICBRU3RyaW5nTGlzdCBjb2x1bW5zID0gbV9j
b2x1bW5DYWNoZS52YWx1ZSh0YWJsZU5hbWUpOwogCiAgICAgaWYgKGNvbHVtbnMuaXNFbXB0eSgp
KSB7Ci0gICAgICAgIGNvbnN0IFFTcWxSZWNvcmQgdGFibGUgPSBtX2RhdGFiYXNlLnJlY29yZCh0
YWJsZU5hbWUpOworICAgICAgICBjb25zdCBRU3FsUmVjb3JkIHRhYmxlID0gbV9kYXRhYmFzZS5y
ZWNvcmQodGFibGVOYW1lLnRvTG93ZXIoKSk7CiAgICAgICAgIGNvbnN0IGludCBudW1UYWJsZXMg
PSB0YWJsZS5jb3VudCgpOwogICAgICAgICBjb2x1bW5zLnJlc2VydmUobnVtVGFibGVzKTsKICAg
ICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBudW1UYWJsZXM7ICsraSkgewo=
</data>

          </attachment>
      

    </bug>

</bugzilla>