Bug 237878 - SCHEMA : add foreign keys support
Summary: SCHEMA : add foreign keys support
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Database-Schema (show other bugs)
Version: 1.3.0
Platform: Ubuntu Unspecified
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-16 22:16 UTC by Alessandro Rossini
Modified: 2016-07-21 06:36 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.1.0


Attachments
Database schema with foreign keys (4.49 KB, application/octet-stream)
2010-05-16 22:19 UTC, Alessandro Rossini
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alessandro Rossini 2010-05-16 22:16:41 UTC
Version:            (using KDE 4.4.3)
Installed from:    Ubuntu Packages

I think that adding foreign keys would avoid many of the current triggers in the database schema, and I guess that the database would be more efficient.

I have added foreign keys to the current database schema (see attachment). I have not added a foreign key from the icon column of the Albums table to the id column of the Images table since this would introduce a circular dependency between the Albums and Images tables. However, this would be easily solved by adding a new AlbumIcon table or similar. Note that SQLite version 3.6.19+ is needed to execute these statements (see http://www.sqlite.org/foreignkeys.html).

I have migrated my current database to the updated schema and it seems to work without problems with Digikam 1.2.0.

Best regards.
Comment 1 Alessandro Rossini 2010-05-16 22:19:32 UTC
Created attachment 43648 [details]
Database schema with foreign keys
Comment 2 caulier.gilles 2010-05-17 09:23:54 UTC
digiKam 1.3.0 will support MySQL too. SQlite still supported of course. In settings panel, you can choose the DB backend.

Your DB schema with foreign keys will be fine with MySQL ?

Note : later, PostgreSQL will be supported too...

Gilles Caulier
Comment 3 Marcel Wiesweg 2010-05-17 18:31:05 UTC
I think Holger already removed a number of Triggers with his MySQL port.

Please note that 3.6.19 is released only last October. Even on my system, which is fairly recent, 3.6.16 is installed. We cannot expect cutting-edge versions of this library.
Comment 4 Alessandro Rossini 2010-05-21 12:52:01 UTC
(In reply to comment #2)
> digiKam 1.3.0 will support MySQL too. SQlite still supported of course. In
> settings panel, you can choose the DB backend.
> 
> Your DB schema with foreign keys will be fine with MySQL ?

MySQL has supported foreign keys since version 3.23.44:
http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
With some minor changes to the syntax, my database schema should work fine with MySQL.

> Note : later, PostgreSQL will be supported too...

As far as I remember, PostgreSQL has always supported foreign keys:
http://www.postgresql.org/docs/8.4/static/ddl-constraints.html#DDL-CONSTRAINTS-FK
Also in this case, my database schema should work fine with PostgreSQL.

If you can post or send me the current database schema proposed by Holger, I can define and test database schemata on SQLite, MySQL and PostgreSQL.

Best regards.
Comment 5 Alessandro Rossini 2010-05-21 13:32:51 UTC
(In reply to comment #3)
> Please note that 3.6.19 is released only last October. Even on my system, which
> is fairly recent, 3.6.16 is installed. We cannot expect cutting-edge versions
> of this library.

Ubuntu 10.04 and Fedora 13 already ship SQLite 3.6.22:
http://packages.ubuntu.com/search?keywords=sqlite3&searchon=names&suite=lucid&section=all
https://admin.fedoraproject.org/pkgdb/builds/search/repo:F-13*%20sqlite
openSUSE 11.3, which is to be released in July, will ship SQLite 3.6.23:
http://download.opensuse.org/factory/repo/oss/suse/i586/
PCLinuxOS 2010.1 and Arch Linux 2010.05 also already ship SQLite 3.6.23.

Considering that the major distributions all ship SQLite 3.6.19+, there should be no problem in adding a dependency to it.

Best regards.
Comment 6 Francesco Riosa 2011-06-28 21:35:17 UTC
Note:
Mysql does not support foreign keys with myisam tables only with innodb ones
Comment 7 Alessandro Rossini 2011-07-04 14:54:17 UTC
(In reply to comment #6)
> Note:
> Mysql does not support foreign keys with myisam tables only with innodb ones

That is correct, but InnoDB is the default storage engine starting in MySQL 5.5:
http://dev.mysql.com/tech-resources/articles/introduction-to-mysql-55.html

Again, considering that the upcoming releases of the major distributions will all ship MySQL 5.5 as default, there should be no issue in including foreign keys in the database schema.

Best regards,
Alessandro Rossini
Comment 8 caulier.gilles 2014-08-08 08:12:20 UTC
Marcel,

I look if we can include foreign keys in database schema

- SQlite3 support it since 3.6.19 : 

http://www.sqlite.org/foreignkeys.html

Sqlite current version is 3.8.5

- Mysql support it since 5.5 :

http://dev.mysql.com/doc/refman/5.1/en/create-table-foreign-keys.html

Mysql current version is 5.6.20

- MariaDb support it but i cannot see since which version exactly ?

- Postgresql support it too

Gilles
Comment 9 caulier.gilles 2014-08-08 08:18:40 UTC
Alessandro,

The database schema is common to sqlite and mysql. It defined into an XML file here :

https://projects.kde.org/projects/extragear/graphics/digikam/repository/revisions/master/entry/data/database/dbconfig.xml.cmake.in

We need a patch against this file to include foreign keys.

Gilles Caulier
Comment 10 swatilodha27 2016-06-02 21:38:38 UTC
Foreign keys support now exists in digiKam5.0.0-beta6 version.

(It supports use of MySQL Internal & Remote both.)
Comment 11 caulier.gilles 2016-06-02 22:07:07 UTC
Richard,

Can we considering this file is implemented for next 5.0.0 release, following all your patches applied to the code last winter ?

Gilles Caulier
Comment 12 Richard Mortimer 2016-06-24 07:54:53 UTC
Gilles,

I think we can say that we have the basic support there but there are still bugs to be worked out. I know Swati is working on those.

Richard
Comment 13 caulier.gilles 2016-06-24 08:16:46 UTC
Richard,

Please look the story on this entry

https://bugs.kde.org/show_bug.cgi?id=363697

... and give us your viewpoint about the solution given in patch about foreign keys and all other pending questions, especially the comment #5.

Thanks in advance.

Gilles
Comment 14 swatilodha27 2016-07-16 21:06:02 UTC
digiKam latest version 5.0.0 very well uses the foreign keys support. Here, SQLite and MySQL both support foreign keys well. It is not only essential for data consistency, but also to make sure that wrong queries aren't executed. So it's definitely an advantage to include it in DB schema.

Richard,
Can this file be closed now after improving MySQL support ?

Thanks.
Comment 15 Richard Mortimer 2016-07-19 12:17:25 UTC
Yes. I think this can now be considered resolved.
Comment 16 caulier.gilles 2016-07-21 06:36:48 UTC
Thanks Richard. I close this file now.

Gilles Caulier