This file is indexed.

/usr/share/digikam/database/dbconfig.xml is in digikam-data 4:5.6.0-0ubuntu10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2009-07-28
 * Description : Databases SQL statements
 *
 * Copyright (C) 2009      by Holger Foerster <hamsi2k at freenet dot de>
 * Copyright (C) 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 * Copyright (C) 2010-2016 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * ============================================================
 -->

<databaseconfig>

    <defaultDB>QSQLITE</defaultDB>

    <!-- Increment this version number whenever you change this file.
         The DBCORECONFIG_XML_VERSION value is defined in the toplevel CMakeLists.txt file.
         On version mismatch, users will be warned.
    -->
    <version>3</version>

    <!-- =============================================================================================================== -->
    <!-- ========================================== SQLITE DATABASE STATEMENTS ========================================= -->
    <!-- =============================================================================================================== -->


    <database name="QSQLITE">

        <hostName>TestHost</hostName>
        <databaseName>DatabaseName</databaseName>
        <userName>UserName</userName>
        <password>Password</password>
        <port>Port</port>
        <connectoptions>ConnectOptions</connectoptions>

        <dbactions>

            <!-- SQlite check privileges rules -->

            <dbaction name="CheckPriv_CREATE_TRIGGER"><statement mode="plain">
                CREATE TRIGGER privcheck_trigger DELETE ON PrivCheck
                    BEGIN
                        SELECT * FROM PrivCheck;
                    END;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_DROP_TRIGGER"><statement mode="plain">
                DROP TRIGGER privcheck_trigger;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_CREATE_TABLE"><statement mode="plain">
                CREATE TABLE PrivCheck
                (
                    id   INT,
                    name VARCHAR(35)
                );
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_ALTER_TABLE"><statement mode="plain">
                ALTER TABLE PrivCheck ADD COLUMN addedColumn;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_DROP_TABLE"><statement mode="plain">
                DROP TABLE PrivCheck;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_Cleanup"><statement mode="plain">
                DROP TABLE IF EXISTS PrivCheck;
            </statement>
            </dbaction>

            <!-- SQlite Core Schema Database -->

            <dbaction name="CreateDB" mode="transaction"><statement mode="plain">CREATE TABLE AlbumRoots
                            (id INTEGER PRIMARY KEY,
                            label TEXT,
                            status INTEGER NOT NULL,
                            type INTEGER NOT NULL,
                            identifier TEXT,
                            specificPath TEXT,
                            UNIQUE(identifier, specificPath))</statement>
            <statement mode="plain">CREATE TABLE Albums
                            (id INTEGER PRIMARY KEY,
                            albumRoot INTEGER NOT NULL,
                            relativePath TEXT NOT NULL,
                            date DATE,
                            caption TEXT,
                            collection TEXT,
                            icon INTEGER,
                            UNIQUE(albumRoot, relativePath))</statement>
            <statement mode="plain"> CREATE TABLE Images
                            (id INTEGER PRIMARY KEY,
                            album INTEGER,
                            name TEXT NOT NULL,
                            status INTEGER NOT NULL,
                            category INTEGER NOT NULL,
                            modificationDate DATETIME,
                            fileSize INTEGER,
                            uniqueHash TEXT,
                            UNIQUE (album, name))</statement>
            <statement mode="plain">CREATE TABLE ImageHaarMatrix
                            (imageid INTEGER PRIMARY KEY,
                            modificationDate DATETIME,
                            uniqueHash TEXT,
                            matrix BLOB)</statement>
            <statement mode="plain">CREATE TABLE ImageInformation
                            (imageid INTEGER PRIMARY KEY,
                            rating INTEGER,
                            creationDate DATETIME,
                            digitizationDate DATETIME,
                            orientation INTEGER,
                            width INTEGER,
                            height INTEGER,
                            format TEXT,
                            colorDepth INTEGER,
                            colorModel INTEGER);</statement>
            <statement mode="plain"> CREATE TABLE ImageMetadata
                            (imageid INTEGER PRIMARY KEY,
                            make TEXT,
                            model TEXT,
                            lens TEXT,
                            aperture REAL,
                            focalLength REAL,
                            focalLength35 REAL,
                            exposureTime REAL,
                            exposureProgram INTEGER,
                            exposureMode INTEGER,
                            sensitivity INTEGER,
                            flash INTEGER,
                            whiteBalance INTEGER,
                            whiteBalanceColorTemperature INTEGER,
                            meteringMode INTEGER,
                            subjectDistance REAL,
                            subjectDistanceCategory INTEGER)</statement>
            <statement mode="plain"> CREATE TABLE VideoMetadata
                            (imageid INTEGER PRIMARY KEY,
                            aspectRatio TEXT,
                            audioBitRate TEXT,
                            audioChannelType TEXT,
                            audioCompressor TEXT,
                            duration TEXT,
                            frameRate TEXT,
                            exposureProgram INTEGER,
                            videoCodec TEXT)</statement>
            <statement mode="plain">CREATE TABLE ImagePositions
                            (imageid INTEGER PRIMARY KEY,
                            latitude TEXT,
                            latitudeNumber REAL,
                            longitude TEXT,
                            longitudeNumber REAL,
                            altitude REAL,
                            orientation REAL,
                            tilt REAL,
                            roll REAL,
                            accuracy REAL,
                            description TEXT)</statement>
            <statement mode="plain">CREATE TABLE ImageComments
                            (id INTEGER PRIMARY KEY,
                            imageid INTEGER,
                            type INTEGER,
                            language TEXT,
                            author TEXT,
                            date DATETIME,
                            comment TEXT,
                            UNIQUE(imageid, type, language, author))</statement>
            <statement mode="plain"> CREATE TABLE ImageCopyright
                            (id INTEGER PRIMARY KEY,
                            imageid INTEGER,
                            property TEXT,
                            value TEXT,
                            extraValue TEXT,
                            UNIQUE(imageid, property, value, extraValue))</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Tags
                            (id INTEGER PRIMARY KEY,
                            pid INTEGER,
                            name TEXT NOT NULL,
                            icon INTEGER,
                            iconkde TEXT,
                            UNIQUE (name, pid))</statement>
            <statement mode="plain"> CREATE TABLE IF NOT EXISTS TagsTree
                            (id INTEGER NOT NULL,
                            pid INTEGER NOT NULL,
                            UNIQUE (id, pid))</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageTags
                            (imageid INTEGER NOT NULL,
                            tagid INTEGER NOT NULL,
                            UNIQUE (imageid, tagid))</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageProperties
                            (imageid  INTEGER NOT NULL,
                            property TEXT    NOT NULL,
                            value    TEXT    NOT NULL,
                            UNIQUE (imageid, property))</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Searches
                            (id INTEGER PRIMARY KEY,
                            type INTEGER,
                            name TEXT NOT NULL,
                            query TEXT NOT NULL)</statement>
            <statement mode="plain">CREATE TABLE DownloadHistory
                            (id  INTEGER PRIMARY KEY,
                            identifier TEXT,
                            filename TEXT,
                            filesize INTEGER,
                            filedate DATETIME,
                            UNIQUE(identifier, filename, filesize, filedate))</statement>
            <statement mode="plain"> CREATE TABLE IF NOT EXISTS Settings
                            (keyword TEXT NOT NULL UNIQUE,
                            value TEXT)</statement>
            <statement mode="plain">CREATE TABLE ImageHistory
                            (imageid INTEGER PRIMARY KEY,
                             uuid TEXT,
                             history TEXT);</statement>
            <statement mode="plain">CREATE TABLE ImageRelations
                            (subject INTEGER,
                             object INTEGER,
                             type INTEGER,
                             UNIQUE(subject, object, type));</statement>
            <statement mode="plain">CREATE TABLE TagProperties
                            (tagid INTEGER,
                             property TEXT,
                             value TEXT);</statement>
            <statement mode="plain">CREATE TABLE ImageTagProperties
                            (imageid INTEGER,
                             tagid INTEGER,
                             property TEXT,
                             value TEXT);</statement>
            </dbaction>

            <!-- SQlite Core Indexes -->

            <dbaction name="CreateIndices" mode="transaction">
                <statement mode="plain">CREATE INDEX dir_index  ON Images (album);</statement>
                <statement mode="plain">CREATE INDEX hash_index ON Images (uniqueHash);</statement>
                <statement mode="plain">CREATE INDEX tag_index  ON ImageTags (tagid);</statement>
                <statement mode="plain">CREATE INDEX tag_id_index  ON ImageTags (imageid);</statement>
                <statement mode="plain">CREATE INDEX image_name_index ON Images (name);</statement>
                <statement mode="plain">CREATE INDEX creationdate_index ON ImageInformation (creationDate);</statement>
                <statement mode="plain">CREATE INDEX comments_imageid_index ON ImageComments (imageid);</statement>
                <statement mode="plain">CREATE INDEX copyright_imageid_index ON ImageCopyright (imageid);</statement>
                <statement mode="plain">CREATE INDEX uuid_index ON ImageHistory (uuid);</statement>
                <statement mode="plain">CREATE INDEX subject_relations_index ON ImageRelations (subject);</statement>
                <statement mode="plain">CREATE INDEX object_relations_index ON ImageRelations (object);</statement>
                <statement mode="plain">CREATE INDEX tagproperties_index ON TagProperties (tagid);</statement>
                <statement mode="plain">CREATE INDEX imagetagproperties_index ON ImageTagProperties (imageid, tagid);</statement>
                <statement mode="plain">CREATE INDEX imagetagproperties_imageid_index ON ImageTagProperties (imageid);</statement>
                <statement mode="plain">CREATE INDEX imagetagproperties_tagid_index ON ImageTagProperties (tagid);</statement>
            </dbaction>

            <!-- SQlite Core Triggers -->

            <dbaction name="CreateTriggers" mode="transaction">
                <statement mode="plain">CREATE TRIGGER delete_albumroot DELETE ON AlbumRoots
                BEGIN
                DELETE FROM Albums
                WHERE Albums.albumRoot = OLD.id;
                END;</statement>
                <statement mode="plain">CREATE TRIGGER delete_album DELETE ON Albums
                BEGIN
                DELETE FROM Images
                WHERE Images.album = OLD.id;
                END;</statement>
                <statement mode="plain">CREATE TRIGGER delete_image DELETE ON Images
                    BEGIN
                        DELETE FROM ImageTags          WHERE imageid=OLD.id;
                        DELETE From ImageHaarMatrix    WHERE imageid=OLD.id;
                        DELETE From ImageInformation   WHERE imageid=OLD.id;
                        DELETE From ImageMetadata      WHERE imageid=OLD.id;
                        DELETE From VideoMetadata      WHERE imageid=OLD.id;
                        DELETE From ImagePositions     WHERE imageid=OLD.id;
                        DELETE From ImageComments      WHERE imageid=OLD.id;
                        DELETE From ImageCopyright     WHERE imageid=OLD.id;
                        DELETE From ImageProperties    WHERE imageid=OLD.id;
                        DELETE From ImageHistory       WHERE imageid=OLD.id;
                        DELETE FROM ImageRelations     WHERE subject=OLD.id OR object=OLD.id;
                        DELETE FROM ImageTagProperties WHERE imageid=OLD.id;
                        UPDATE Albums SET icon=null    WHERE icon=OLD.id;
                        UPDATE Tags SET icon=null      WHERE icon=OLD.id;
                    END;
                </statement>
                <statement mode="plain">CREATE TRIGGER delete_tag DELETE ON Tags
                    BEGIN
                        DELETE FROM ImageTags WHERE tagid=OLD.id;
                        DELETE FROM TagProperties WHERE tagid=OLD.id;
                        DELETE FROM ImageTagProperties WHERE tagid=OLD.id;
                    END;
                </statement>
                <statement mode="plain">CREATE TRIGGER insert_tagstree AFTER INSERT ON Tags
                BEGIN
                INSERT INTO TagsTree
                    SELECT NEW.id, NEW.pid
                    UNION
                    SELECT NEW.id, pid FROM TagsTree WHERE id=NEW.pid;
                END;</statement>
                <statement mode="plain">CREATE TRIGGER delete_tagstree DELETE ON Tags
                BEGIN
                DELETE FROM Tags
                WHERE id  IN (SELECT id FROM TagsTree WHERE pid=OLD.id);
                DELETE FROM TagsTree
                WHERE id IN (SELECT id FROM TagsTree WHERE pid=OLD.id);
                DELETE FROM TagsTree
                    WHERE id=OLD.id;
                END;</statement>
                <statement mode="plain">CREATE TRIGGER move_tagstree UPDATE OF pid ON Tags
                BEGIN
                DELETE FROM TagsTree
                    WHERE
                    ((id = OLD.id)
                    OR
                    id IN (SELECT id FROM TagsTree WHERE pid=OLD.id))
                    AND
                    pid IN (SELECT pid FROM TagsTree WHERE id=OLD.id);
                INSERT INTO TagsTree
                    SELECT NEW.id, NEW.pid
                    UNION
                    SELECT NEW.id, pid FROM TagsTree WHERE id=NEW.pid
                    UNION
                    SELECT id, NEW.pid FROM TagsTree WHERE pid=NEW.id
                    UNION
                    SELECT A.id, B.pid FROM TagsTree A, TagsTree B
                    WHERE
                    A.pid = NEW.id AND B.id = NEW.pid;
                END;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumByItemName">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID ORDER BY Images.name COLLATE NOCASE;</statement>
            </dbaction>

            <!-- NOTE: Don't collate on the path - this is to maintain the same behavior
                       that happens when sort order is "By Path"
            -->
            <dbaction name="getItemURLsInAlbumByItemPath">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID ORDER BY Albums.relativePath,Images.name;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumByItemDate">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album INNER JOIN ImageInformation ON ImageInformation.imageid=Images.id WHERE Albums.id=:albumID ORDER BY ImageInformation.creationDate;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumByItemRating">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album INNER JOIN ImageInformation ON ImageInformation.imageid=Images.id WHERE Albums.id=:albumID ORDER BY ImageInformation.rating DESC;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumNoItemSorting">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID;</statement>
            </dbaction>

            <dbaction name="changeImageInformation" mode="transaction">
                 <statement mode="query">INSERT OR IGNORE INTO ImageInformation ( imageid, :fieldList ) VALUES ( :id, :valueList );</statement>
                 <statement mode="query">UPDATE ImageInformation SET :fieldValueList WHERE imageid=:id;</statement>
            </dbaction>

            <dbaction name="changeImageHistory" mode="transaction">
            <statement mode="query">INSERT OR IGNORE INTO ImageHistory ( imageid, :fieldList ) VALUES ( :id, :valueList );</statement>
            <statement mode="query">UPDATE ImageHistory SET :fieldValueList WHERE imageid=:id;</statement>
            </dbaction>

            <dbaction name="InsertTag">
                <statement mode="query">INSERT INTO Tags (pid, name) VALUES( :tagPID, :tagname);</statement>
            </dbaction>

            <dbaction name="DeleteTag"><statement mode="query">DELETE FROM Tags WHERE id=:tagID;</statement></dbaction>

            <dbaction name="deleteAlbumRoot">
                <statement mode="query">DELETE FROM Albums WHERE albumRoot=:albumRoot;</statement>
            </dbaction>

            <dbaction name="deleteAlbumRootPath">
                <statement mode="query">DELETE FROM Albums WHERE albumRoot=:albumRoot AND relativePath=:relativePath;</statement>
            </dbaction>

            <dbaction name="deleteAlbumID">
                <statement mode="query">DELETE FROM Albums WHERE Albums.id=:albumId;</statement>
            </dbaction>

            <dbaction name="GetItemURLsInTagRecursive">
            <statement mode="query">SELECT Albums.albumRoot, Albums.relativePath, Images.name
                            FROM Images JOIN Albums ON Albums.id=Images.album
                            WHERE Images.status=1 AND Images.id IN (SELECT imageid FROM ImageTags WHERE tagid=:tagID OR tagid IN (SELECT id FROM TagsTree WHERE pid=:tagID2)  );
            </statement>
            </dbaction>

            <dbaction name="GetItemURLsInTag">
            <statement mode="query">SELECT Albums.albumRoot, Albums.relativePath, Images.name
                                    FROM Images JOIN Albums ON Albums.id=Images.album
                                    WHERE Images.status=1 AND Images.id IN (SELECT imageid FROM ImageTags WHERE tagid=:tagID);
            </statement>
            </dbaction>

            <dbaction name="getItemIDsInTagRecursive">
            <statement mode="query">SELECT imageid FROM ImageTags JOIN Images ON ImageTags.imageid=Images.id
                                    WHERE Images.status=1 AND
                                    ( tagid=:tagID
                                    OR tagid IN (SELECT id FROM TagsTree WHERE pid=:tagPID) );
            </statement>
            </dbaction>

            <dbaction name="getItemIDsInTag">
            <statement mode="query">SELECT imageid FROM ImageTags JOIN Images ON ImageTags.imageid=Images.id
                                    WHERE Images.status=1 AND tagid=:tagID;
            </statement>
            </dbaction>

            <dbaction name="listTagRecursive">
            <statement mode="query">SELECT DISTINCT Images.id, Images.name, Images.album,
                                    Albums.albumRoot,
                                    ImageInformation.rating, Images.category,
                                    ImageInformation.format, ImageInformation.creationDate,
                                    Images.modificationDate, Images.fileSize,
                                    ImageInformation.width, ImageInformation.height
                                    FROM Images
                                    INNER JOIN ImageInformation ON Images.id=ImageInformation.imageid
                                    INNER JOIN Albums ON Albums.id=Images.album
                                    WHERE Images.status=1 AND Images.id IN
                                    (SELECT imageid FROM ImageTags
                                    WHERE tagid=:tagID OR tagid IN (SELECT id FROM TagsTree WHERE pid=:tagPID));
            </statement>
            </dbaction>

            <dbaction name="listTag">
            <statement mode="query">SELECT DISTINCT Images.id, Images.name, Images.album,
                                    Albums.albumRoot,
                                    ImageInformation.rating, Images.category,
                                    ImageInformation.format, ImageInformation.creationDate,
                                    Images.modificationDate, Images.fileSize,
                                    ImageInformation.width, ImageInformation.height
                                    FROM Images
                                    INNER JOIN ImageInformation ON Images.id=ImageInformation.imageid
                                    INNER JOIN Albums ON Albums.id=Images.album
                                    WHERE Images.status=1 AND Images.id IN
                                    (SELECT imageid FROM ImageTags
                                    WHERE tagid=:tagID );
            </statement>
            </dbaction>

            <!-- SQlite Thumbnails Schema Database -->

            <dbaction name="CreateThumbnailsDB" mode="transaction">
                    <statement mode="plain">CREATE TABLE Thumbnails
                            (id INTEGER PRIMARY KEY,
                            type INTEGER,
                            modificationDate DATETIME,
                            orientationHint INTEGER,
                            data BLOB)</statement>
                    <statement mode="plain">CREATE TABLE UniqueHashes
                            (uniqueHash TEXT,
                            fileSize INTEGER,
                            thumbId INTEGER,
                            UNIQUE(uniqueHash, fileSize))</statement>
                    <statement mode="plain">CREATE TABLE FilePaths
                            (path TEXT,
                            thumbId INTEGER,
                            UNIQUE(path))</statement>
                    <statement mode="plain">CREATE TABLE CustomIdentifiers
                            (identifier TEXT,
                            thumbId INTEGER,
                            UNIQUE(identifier))
                    </statement>
                    <statement mode="plain">CREATE TABLE IF NOT EXISTS Settings
                            (keyword TEXT NOT NULL UNIQUE,
                            value TEXT)
                    </statement>
                </dbaction>

                <!-- SQlite Thumbnails Indexes -->

                <dbaction name="CreateThumbnailsDBIndices" mode="transaction">
                    <statement mode="plain">CREATE INDEX id_uniqueHashes ON UniqueHashes (thumbId);</statement>
                    <statement mode="plain">CREATE INDEX id_filePaths ON FilePaths (thumbId);</statement>
                    <statement mode="plain">CREATE INDEX id_customIdentifiers ON CustomIdentifiers (thumbId);</statement>
                </dbaction>

                <!-- SQlite Thumbnails Trigger -->

                <dbaction name="CreateThumbnailsDBTrigger" mode="transaction">
                    <statement mode="plain">CREATE TRIGGER delete_thumbnails DELETE ON Thumbnails
                                BEGIN
                                DELETE FROM UniqueHashes WHERE UniqueHashes.thumbId = OLD.id;
                                DELETE FROM FilePaths WHERE FilePaths.thumbId = OLD.id;
                                DELETE FROM CustomIdentifiers WHERE CustomIdentifiers.thumbId = OLD.id;
                                END;
                    </statement>
                </dbaction>

                <!-- SQlite Thumbnails Queries -->

                <dbaction name="SelectThumbnailSetting">
                    <statement mode="query">SELECT value FROM Settings WHERE keyword=:keyword;</statement>
                </dbaction>

                <dbaction name="SelectThumbnailLegacySetting">
                    <statement mode="query">SELECT value FROM Settings WHERE keyword=:keyword;</statement>
                </dbaction>

                <dbaction name="ReplaceThumbnailSetting">
                    <statement mode="query">REPLACE INTO Settings VALUES (:keyword, :value);</statement>
                </dbaction>

            <!-- SQlite Face Schema Database -->

            <dbaction name="CreateFaceDB" mode="transaction">
                <statement mode="plain">
                    CREATE TABLE IF NOT EXISTS Settings
                    (keyword TEXT NOT NULL UNIQUE,
                    value TEXT)
                </statement>
                <statement mode="plain">
                    CREATE TABLE Identities
                    (id INTEGER PRIMARY KEY,
                    type INTEGER)
                </statement>
                <statement mode="plain">
                    CREATE TABLE IdentityAttributes
                    (id INTEGER,
                    attribute TEXT,
                    value TEXT)
                </statement>
            </dbaction>

            <dbaction name="CreateFaceDBOpenCVLBPH" mode="transaction">
                <statement mode="plain">
                    CREATE TABLE OpenCVLBPHRecognizer
                    (id INTEGER PRIMARY KEY,
                    version INTEGER,
                    radius INTEGER,
                    neighbors INTEGER,
                    grid_x INTEGER,
                    grid_y INTEGER)
                </statement>
                <statement mode="plain">
                    CREATE TABLE OpenCVLBPHistograms
                    (id INTEGER PRIMARY KEY,
                    recognizerid INTEGER,
                    identity INTEGER,
                    context TEXT,
                    type INTEGER,
                    rows INTEGER,
                    cols INTEGER,
                    data BLOB)
                </statement>
            </dbaction>

            <!-- SQlite Face Indexes -->

            <dbaction name="CreateFaceIndices" mode="transaction">
                <statement mode="plain">CREATE INDEX attribute_index  ON IdentityAttributes (id);</statement>
            </dbaction>

            <!-- SQlite Face Triggers -->

            <dbaction name="CreateFaceTriggers" mode="transaction">
                <statement mode="plain">
                    CREATE TRIGGER delete_identities DELETE ON Identities
                    BEGIN
                        DELETE FROM IdentityAttributes
                        WHERE IdentityAttributes.id = OLD.id;
                    END;
                </statement>
            </dbaction>

            <!-- SQlite Face Queries -->

            <dbaction name="SelectFaceSetting">
                <statement mode="query">SELECT value FROM Settings WHERE keyword=:keyword;</statement>
            </dbaction>

            <dbaction name="ReplaceFaceSetting">
                <statement mode="query">REPLACE INTO Settings VALUES (:keyword, :value);</statement>
            </dbaction>

            <!-- SQlite Migration Statements -->

            <!-- NOTE: Migrate_Cleanup_DB now it's done by the program except for cleanup prepare -->
            <dbaction name="Migrate_Cleanup_Prepare">
            </dbaction>

            <dbaction name="Migrate_Read_AlbumRoots"><statement mode="query">
                SELECT id, label, status, type, identifier, specificPath FROM AlbumRoots;
            </statement></dbaction>
            <dbaction name="Migrate_Write_AlbumRoots"><statement mode="query">
                INSERT INTO AlbumRoots (id, label, status, type, identifier, specificPath) VALUES (:id, :label, :status, :type, :identifier, :specificPath);
            </statement></dbaction>

            <!-- Note Albums with an icon set are setup after population of the Images table. -->
            <dbaction name="Migrate_Read_Albums"><statement mode="query">
                SELECT id, albumRoot, relativePath, date, caption, collection FROM Albums;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Albums"><statement mode="query">
                INSERT INTO Albums (id, albumRoot, relativePath, date, caption, collection, icon) VALUES (:id, :albumRoot, :relativePath, :date, :caption, :collection, NULL);
            </statement></dbaction>

            <!-- Populate the Albums icon where set. -->
            <dbaction name="Migrate_Read_AlbumsExtra"><statement mode="query">
                SELECT id, icon FROM Albums where icon IS NOT NULL AND icon != 0;
            </statement></dbaction>
            <dbaction name="Migrate_Write_AlbumsExtra"><statement mode="query">
                UPDATE Albums set icon = :icon WHERE id = :id;
            </statement></dbaction>

            <dbaction name="Migrate_Read_Images"><statement mode="query">
                SELECT id, album, name, status, category, modificationDate, fileSize, uniqueHash FROM Images;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Images"><statement mode="query">
                INSERT INTO Images (id, album, name, status, category, modificationDate, fileSize, uniqueHash) VALUES (:id, :album, :name, :status, :category, :modificationDate, :fileSize, :uniqueHash);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageHaarMatrix"><statement mode="query">
                SELECT imageid, modificationDate, uniqueHash, matrix FROM ImageHaarMatrix;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageHaarMatrix"><statement mode="query">
                INSERT INTO ImageHaarMatrix (imageid, modificationDate, uniqueHash, matrix) VALUES (:imageid, :modificationDate, :uniqueHash, :matrix);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageInformation"><statement mode="query">
                SELECT imageid, rating, creationDate, digitizationDate, orientation, width, height, format, colorDepth, colorModel FROM ImageInformation;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageInformation"><statement mode="query">
                INSERT INTO ImageInformation (imageid, rating, creationDate, digitizationDate, orientation, width, height, format, colorDepth, colorModel) VALUES (:imageid, :rating, :creationDate, :digitizationDate, :orientation, :width, :height, :format, :colorDepth, :colorModel);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageMetadata"><statement mode="query">
                SELECT imageid, make, model, lens, aperture, focalLength, focalLength35, exposureTime, exposureProgram, exposureMode, sensitivity, flash, whiteBalance, whiteBalanceColorTemperature, meteringMode, subjectDistance, subjectDistanceCategory FROM ImageMetadata;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageMetadata"><statement mode="query">
                INSERT INTO ImageMetadata (imageid, make, model, lens, aperture, focalLength, focalLength35, exposureTime, exposureProgram, exposureMode, sensitivity, flash, whiteBalance, whiteBalanceColorTemperature, meteringMode, subjectDistance, subjectDistanceCategory) VALUES (:imageid, :make, :model, :lens, :aperture, :focalLength, :focalLength35, :exposureTime, :exposureProgram, :exposureMode, :sensitivity, :flash, :whiteBalance, :whiteBalanceColorTemperature, :meteringMode, :subjectDistance, :subjectDistanceCategory);
            </statement></dbaction>

            <dbaction name="Migrate_Read_VideoMetadata"><statement mode="query">
                SELECT imageid, aspectRatio, audioBitRate, audioChannelType, audioCompressor, duration, frameRate, videoCodec FROM VideoMetadata;
            </statement></dbaction>
            <dbaction name="Migrate_Write_VideoMetadata"><statement mode="query">
                INSERT INTO VideoMetadata (imageid, aspectRatio, audioBitRate, audioChannelType, audioCompressor, duration, frameRate, videoCodec) VALUES (:imageid, :aspectRatio, :audioBitRate, :audioChannelType, :audioCompressor, :duration, :frameRate, :videoCodec);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageTagProperties"><statement mode="query">
                SELECT imageid, tagid, property, value FROM ImageTagProperties;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageTagProperties"><statement mode="query">
                INSERT INTO ImageTagProperties (imageid, tagid, property, value) VALUES (:imageid, :tagid, :property, :value);
            </statement></dbaction>

            <dbaction name="Migrate_Read_TagProperties"><statement mode="query">
                SELECT tagid, property, value FROM TagProperties;
            </statement></dbaction>
            <dbaction name="Migrate_Write_TagProperties"><statement mode="query">
                INSERT INTO TagProperties (tagid, property, value) VALUES (:tagid, :property, :value);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImagePositions"><statement mode="query">
                SELECT  imageid, latitude, latitudeNumber, longitude, longitudeNumber, altitude, orientation, tilt, roll, accuracy, description FROM ImagePositions;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImagePositions"><statement mode="query">
                INSERT INTO ImagePositions (imageid, latitude, latitudeNumber, longitude, longitudeNumber, altitude, orientation, tilt, roll, accuracy, description) VALUES (:imageid, :latitude, :latitudeNumber, :longitude, :longitudeNumber, :altitude, :orientation, :tilt, :roll, :accuracy, :description);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageComments"><statement mode="query">
                SELECT  id, imageid, type, language, author, date, comment FROM ImageComments;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageComments"><statement mode="query">
                INSERT INTO ImageComments (id, imageid, type, language, author, date, comment) VALUES (:id, :imageid, :type, :language, :author, :date, :comment);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageCopyright"><statement mode="query">
                SELECT  id, imageid, property, value, extraValue FROM ImageCopyright;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageCopyright"><statement mode="query">
                INSERT INTO ImageCopyright (id, imageid, property, value, extraValue) VALUES (:id, :imageid, :property, :value, :extraValue);
            </statement></dbaction>

            <dbaction name="Migrate_Read_Tags"><statement mode="query">
                SELECT  id, pid, name, CASE WHEN icon = 0 THEN NULL ELSE icon END AS icon, iconkde FROM Tags WHERE id != 0;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Tags"><statement mode="query">
                INSERT INTO Tags (id, pid, name, icon, iconkde) VALUES (:id, :pid, :name, :icon, :iconkde);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageTags"><statement mode="query">
                SELECT  imageid, tagid FROM ImageTags;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageTags"><statement mode="query">
                INSERT INTO ImageTags (imageid, tagid) VALUES (:imageid, :tagid);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageProperties"><statement mode="query">
                SELECT  imageid, property, value FROM ImageProperties;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageProperties"><statement mode="query">
                INSERT INTO ImageProperties (imageid, property, value) VALUES (:imageid, :property, :value);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageHistory"><statement mode="query">
                SELECT  imageid, uuid, history FROM ImageHistory;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageHistory"><statement mode="query">
                INSERT INTO ImageHistory (imageid, uuid, history) VALUES (:imageid, :uuid, :history);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageRelations"><statement mode="query">
                SELECT  subject, object, type FROM ImageRelations;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageRelations"><statement mode="query">
                INSERT INTO ImageRelations (subject, object, type) VALUES (:subject, :object, :type);
            </statement></dbaction>

            <dbaction name="Migrate_Read_Searches"><statement mode="query">
                SELECT  id, type, name, query FROM Searches;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Searches"><statement mode="query">
                INSERT INTO Searches (id, type, name, query) VALUES (:id, :type, :name, :query);
            </statement></dbaction>

            <dbaction name="Migrate_Read_DownloadHistory"><statement mode="query">
                SELECT id, identifier, filename, filesize, filedate FROM DownloadHistory;
            </statement></dbaction>
            <dbaction name="Migrate_Write_DownloadHistory"><statement mode="query">
                INSERT INTO DownloadHistory (id, identifier, filename, filesize, filedate) VALUES (:id, :identifier, :filename, :filesize, :filedate);
            </statement></dbaction>

            <dbaction name="Migrate_Read_Settings"><statement mode="query">
                SELECT keyword, value FROM Settings;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Settings"><statement mode="query">
                INSERT INTO Settings (keyword, value) VALUES (:keyword, :value);
            </statement></dbaction>

            <dbaction name="Delete_Thumbnail_ByPath"><statement mode="query">
                DELETE FROM Thumbnails WHERE id IN (SELECT thumbId FROM FilePaths WHERE path=:path);
            </statement></dbaction>

            <dbaction name="Delete_Thumbnail_ByUniqueHashId"><statement mode="query">
                DELETE FROM Thumbnails WHERE id IN (SELECT thumbId FROM UniqueHashes WHERE uniqueHash=:uniqueHash AND fileSize=:filesize);
            </statement></dbaction>

            <dbaction name="Delete_Thumbnail_ByCustomIdentifier"><statement mode="query">
                DELETE FROM Thumbnails WHERE id IN (SELECT thumbId FROM CustomIdentifiers WHERE identifier=:identifier);
            </statement></dbaction>

            <!-- SQlite Migration from Database Version 5 (0.10 - 1.4) to Version 6 (1.5-) -->

            <dbaction name="UpdateSchemaFromV5ToV6" mode="transaction">
                <statement mode="plain">CREATE TABLE ImageHistory
                            (imageid INTEGER PRIMARY KEY,
                             uuid TEXT,
                             history TEXT);</statement>
                <statement mode="plain">CREATE TABLE ImageRelations
                            (subject INTEGER,
                             object INTEGER,
                             type INTEGER,
                             UNIQUE(subject, object, type));</statement>
                <statement mode="plain">CREATE TABLE TagProperties
                            (tagid INTEGER,
                             property TEXT,
                             value TEXT);</statement>
                <statement mode="plain">CREATE TABLE ImageTagProperties
                            (imageid INTEGER,
                             tagid INTEGER,
                             property TEXT,
                             value TEXT);</statement>
                <statement mode="plain">CREATE INDEX tag_id_index  ON ImageTags (imageid);</statement>
                <statement mode="plain">CREATE INDEX image_name_index ON Images (name);</statement>
                <statement mode="plain">CREATE INDEX creationdate_index ON ImageInformation (creationDate);</statement>
                <statement mode="plain">CREATE INDEX comments_imageid_index ON ImageComments (imageid);</statement>
                <statement mode="plain">CREATE INDEX copyright_imageid_index ON ImageCopyright (imageid);</statement>
                <statement mode="plain">CREATE INDEX uuid_index ON ImageHistory (uuid);</statement>
                <statement mode="plain">CREATE INDEX subject_relations_index ON ImageRelations (subject);</statement>
                <statement mode="plain">CREATE INDEX object_relations_index ON ImageRelations (object);</statement>
                <statement mode="plain">CREATE INDEX tagproperties_index ON TagProperties (tagid);</statement>
                <statement mode="plain">CREATE INDEX imagetagproperties_index ON ImageTagProperties (imageid, tagid);</statement>
                <statement mode="plain">CREATE INDEX imagetagproperties_imageid_index ON ImageTagProperties (imageid);</statement>
                <statement mode="plain">CREATE INDEX imagetagproperties_tagid_index ON ImageTagProperties (tagid);</statement>
                <statement mode="plain">DROP TRIGGER delete_image;</statement>
                <statement mode="plain">CREATE TRIGGER delete_image DELETE ON Images
                    BEGIN
                        DELETE FROM ImageTags          WHERE imageid=OLD.id;
                        DELETE From ImageHaarMatrix    WHERE imageid=OLD.id;
                        DELETE From ImageInformation   WHERE imageid=OLD.id;
                        DELETE From ImageMetadata      WHERE imageid=OLD.id;
                        DELETE From VideoMetadata      WHERE imageid=OLD.id;
                        DELETE From ImagePositions     WHERE imageid=OLD.id;
                        DELETE From ImageComments      WHERE imageid=OLD.id;
                        DELETE From ImageCopyright     WHERE imageid=OLD.id;
                        DELETE From ImageProperties    WHERE imageid=OLD.id;
                        DELETE From ImageHistory       WHERE imageid=OLD.id;
                        DELETE FROM ImageRelations     WHERE subject=OLD.id OR object=OLD.id;
                        DELETE FROM ImageTagProperties WHERE imageid=OLD.id;
                        UPDATE Albums SET icon=null    WHERE icon=OLD.id;
                        UPDATE Tags SET icon=null      WHERE icon=OLD.id;
                    END;
                </statement>
                <statement mode="plain">DROP TRIGGER delete_tag;</statement>
                <statement mode="plain">CREATE TRIGGER delete_tag DELETE ON Tags
                            BEGIN
                            DELETE FROM ImageTags WHERE tagid=OLD.id;
                            DELETE FROM TagProperties WHERE tagid=OLD.id;
                            DELETE FROM ImageTagProperties WHERE tagid=OLD.id;
                            END;
                </statement>
            </dbaction>

            <dbaction name="UpdateSchemaFromV6ToV7" mode="transaction">
                <statement mode="plain"> CREATE TABLE VideoMetadata
                            (imageid INTEGER PRIMARY KEY,
                            aspectRatio TEXT,
                            audioBitRate TEXT,
                            audioChannelType TEXT,
                            audioCompressor TEXT,
                            duration TEXT,
                            frameRate TEXT,
                            exposureProgram INTEGER,
                            videoCodec TEXT)</statement>
                <statement mode="plain">DROP TRIGGER delete_image;</statement>
                <statement mode="plain">CREATE TRIGGER delete_image DELETE ON Images
                    BEGIN
                        DELETE FROM ImageTags          WHERE imageid=OLD.id;
                        DELETE From ImageHaarMatrix    WHERE imageid=OLD.id;
                        DELETE From ImageInformation   WHERE imageid=OLD.id;
                        DELETE From ImageMetadata      WHERE imageid=OLD.id;
                        DELETE From VideoMetadata      WHERE imageid=OLD.id;
                        DELETE From ImagePositions     WHERE imageid=OLD.id;
                        DELETE From ImageComments      WHERE imageid=OLD.id;
                        DELETE From ImageCopyright     WHERE imageid=OLD.id;
                        DELETE From ImageProperties    WHERE imageid=OLD.id;
                        DELETE From ImageHistory       WHERE imageid=OLD.id;
                        DELETE FROM ImageRelations     WHERE subject=OLD.id OR object=OLD.id;
                        DELETE FROM ImageTagProperties WHERE imageid=OLD.id;
                        UPDATE Albums SET icon=null    WHERE icon=OLD.id;
                        UPDATE Tags SET icon=null      WHERE icon=OLD.id;
                    END;
                </statement>
            </dbaction>

            <dbaction name="UpdateSchemaFromV7ToV8" mode="transaction">
                <!-- Nothing to do for SQLite -->
            </dbaction>

            <dbaction name="UpdateThumbnailsDBSchemaFromV1ToV2" mode="transaction">
                <statement mode="plain">CREATE TABLE CustomIdentifiers
                        (identifier TEXT,
                        thumbId INTEGER,
                        UNIQUE(identifier))
                </statement>
                <statement mode="plain">CREATE INDEX id_customIdentifiers ON CustomIdentifiers (thumbId);</statement>
                <statement mode="plain">DROP TRIGGER delete_thumbnails;</statement>
                <statement mode="plain">CREATE TRIGGER delete_thumbnails DELETE ON Thumbnails
                            BEGIN
                            DELETE FROM UniqueHashes WHERE UniqueHashes.thumbId = OLD.id;
                            DELETE FROM FilePaths WHERE FilePaths.thumbId = OLD.id;
                            DELETE FROM CustomIdentifiers WHERE CustomIdentifiers.thumbId = OLD.id;
                            END;
                </statement>
            </dbaction>

            <dbaction name="UpdateThumbnailsDBSchemaFromV2ToV3" mode="transaction">
                <!-- Nothing to do for SQLite -->
            </dbaction>

            <!-- 
              statements for shrinking the databases. We need actions for each database since MySQL has only vacuum
              and integtrity check for tables. Thus, MySQL needs at least one action per table.
              Vacuum (SQLite) creates a temporary database that replaces the current one on successful vacuuming.
            -->

            <dbaction name="vacuumCoreDB">
                <statement mode="query">VACUUM;</statement>
            </dbaction>

            <dbaction name="vacuumThumbnailsDB">
                <statement mode="query">VACUUM;</statement>
            </dbaction>

            <dbaction name="vacuumRecognitionDB">
                <statement mode="query">VACUUM;</statement>
            </dbaction>

            <dbaction name="checkCoreDbIntegrity">
                <statement mode="query">pragma integrity_check;</statement>
            </dbaction>

            <dbaction name="checkThumbnailsDbIntegrity">
                <statement mode="query">pragma integrity_check;</statement>
            </dbaction>

            <dbaction name="checkRecognitionDbIntegrity">
                <statement mode="query">pragma integrity_check;</statement>
            </dbaction>

        </dbactions>

    </database>



    <!-- =============================================================================================================== -->
    <!-- ========================================== MYSQL DATABASE STATEMENTS ========================================== -->
    <!-- =============================================================================================================== -->



    <database name="QMYSQL">

        <!-- NOTE: default settings for Mysql Internal server -->
        <hostName>$$DBHOSTNAME$$</hostName>
        <databaseName>digikam</databaseName>
        <userName>root</userName>
        <password></password>
        <port>$$DBPORT$$</port>
        <connectoptions>$$DBOPTIONS$$</connectoptions>

        <dbactions>

            <!-- Mysql check privileges rules -->

            <dbaction name="CheckPriv_CREATE_TRIGGER">
            </dbaction>

            <dbaction name="CheckPriv_DROP_TRIGGER">
            </dbaction>

            <dbaction name="CheckPriv_CREATE_TABLE"><statement mode="plain">
                CREATE TABLE IF NOT EXISTS PrivCheck
                (
                   id   INT,
                   name VARCHAR(35)
                ) ENGINE InnoDB;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_ALTER_TABLE"><statement mode="plain">
                ALTER TABLE PrivCheck DROP COLUMN name;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_DROP_TABLE"><statement mode="plain">
                DROP TABLE PrivCheck;
            </statement>
            </dbaction>

            <dbaction name="CheckPriv_Cleanup"><statement mode="plain">
                DROP TABLE IF EXISTS PrivCheck;
            </statement>
            </dbaction>

            <!-- Mysql Core Schema Database -->

            <dbaction name="CreateDB" mode="transaction">
            <statement mode="plain">  CREATE TABLE IF NOT EXISTS AlbumRoots
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            label LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            status INTEGER NOT NULL,
                            type INTEGER NOT NULL,
                            identifier LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            specificPath LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            UNIQUE(identifier(127), specificPath(128)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Albums
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            albumRoot INTEGER NOT NULL,
                            relativePath LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            date DATE,
                            caption LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            collection LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            icon INTEGER,
                            CONSTRAINT Albums_AlbumRoots FOREIGN KEY (albumRoot) REFERENCES AlbumRoots (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE(albumRoot, relativePath(255)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Images
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            album INTEGER,
                            name LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            status INTEGER NOT NULL,
                            category INTEGER NOT NULL,
                            modificationDate DATETIME,
                            fileSize BIGINT,
                            uniqueHash VARCHAR(128),
                            CONSTRAINT Images_Albums FOREIGN KEY (album) REFERENCES Albums (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE (album, name(255)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">ALTER TABLE Albums
                            ADD CONSTRAINT Albums_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageHaarMatrix
                            (imageid INTEGER PRIMARY KEY,
                            modificationDate DATETIME,
                            uniqueHash LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            matrix LONGBLOB,
                            CONSTRAINT ImageHaarMatrix_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageInformation
                            (imageid INTEGER PRIMARY KEY,
                            rating INTEGER,
                            creationDate DATETIME,
                            digitizationDate DATETIME,
                            orientation INTEGER,
                            width INTEGER,
                            height INTEGER,
                            format LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            colorDepth INTEGER,
                            colorModel INTEGER,
                            CONSTRAINT ImageInformation_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageMetadata
                            (imageid INTEGER PRIMARY KEY,
                            make LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            model LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            lens LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            aperture REAL,
                            focalLength REAL,
                            focalLength35 REAL,
                            exposureTime REAL,
                            exposureProgram INTEGER,
                            exposureMode INTEGER,
                            sensitivity INTEGER,
                            flash INTEGER,
                            whiteBalance INTEGER,
                            whiteBalanceColorTemperature INTEGER,
                            meteringMode INTEGER,
                            subjectDistance REAL,
                            subjectDistanceCategory INTEGER,
                            CONSTRAINT ImageMetadata_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS VideoMetadata
                            (imageid INTEGER PRIMARY KEY,
                            aspectRatio TEXT,
                            audioBitRate TEXT,
                            audioChannelType TEXT,
                            audioCompressor TEXT,
                            duration TEXT,
                            frameRate TEXT,
                            exposureProgram INTEGER,
                            videoCodec TEXT,
                            CONSTRAINT VideoMetadata_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImagePositions
                            (imageid INTEGER PRIMARY KEY,
                            latitude LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            latitudeNumber REAL,
                            longitude LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            longitudeNumber REAL,
                            altitude REAL,
                            orientation REAL,
                            tilt REAL,
                            roll REAL,
                            accuracy REAL,
                            description LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            CONSTRAINT ImagePositions_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageComments
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            imageid INTEGER,
                            type INTEGER,
                            language VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_bin,
                            author LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            date DATETIME,
                            comment LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            CONSTRAINT ImageComments_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE(imageid, type, language, author(202)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageCopyright
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            imageid INTEGER,
                            property LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            extraValue LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            CONSTRAINT ImageCopyright_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE(imageid, property(110), value(111), extraValue(111)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Tags
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            pid INTEGER,
                            name LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            icon INTEGER,
                            iconkde LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            lft INT NOT NULL,
                            rgt INT NOT NULL,
                            CONSTRAINT Tags_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE,
                            UNIQUE(pid, name(100)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageTags
                            (imageid INTEGER NOT NULL,
                            tagid INTEGER NOT NULL,
                            CONSTRAINT ImageTags_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            CONSTRAINT ImageTags_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE (imageid, tagid))
                            ENGINE InnoDB;</statement>
            <statement mode="plain"> CREATE TABLE IF NOT EXISTS ImageProperties
                            (imageid  INTEGER NOT NULL,
                            property LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            value    LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            CONSTRAINT ImageProperties_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE (imageid, property(255)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Searches
                            (id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            type INTEGER,
                            name LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            query LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS DownloadHistory
                            (id  INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
                            identifier LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            filename LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            filesize BIGINT,
                            filedate DATETIME,
                            UNIQUE(identifier(164), filename(165), filesize, filedate))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS Settings
                            (keyword LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            UNIQUE(keyword(255)))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageHistory
                            (imageid INTEGER PRIMARY KEY,
                             uuid VARCHAR(128),
                             history LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                             CONSTRAINT ImageHistory_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageRelations
                            (subject INTEGER,
                             object INTEGER,
                             type INTEGER,
                             CONSTRAINT ImageRelations_ImagesS FOREIGN KEY (subject) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                             CONSTRAINT ImageRelations_ImagesO FOREIGN KEY (object) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                             UNIQUE(subject, object, type))
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS TagProperties
                            (tagid INTEGER,
                             property TEXT CHARACTER SET utf8 COLLATE utf8_bin,
                             value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                             CONSTRAINT TagProperties_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageTagProperties
                            (imageid INTEGER,
                             tagid INTEGER,
                             property TEXT CHARACTER SET utf8 COLLATE utf8_bin,
                             value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                             CONSTRAINT ImageTagProperties_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                             CONSTRAINT ImageTagProperties_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE)
                            ENGINE InnoDB;</statement>
            <statement mode="plain">
                            CREATE OR REPLACE VIEW TagsTree 
                            AS
                            SELECT id, pid
                            FROM Tags;</statement>
            </dbaction>

            <!-- Mysql Core Indexes -->

            <dbaction name="CreateIndices" mode="transaction">
                <statement mode="plain">
                    DROP PROCEDURE IF EXISTS create_index_if_not_exists;
                </statement>
                <statement mode="plain">
                    CREATE PROCEDURE create_index_if_not_exists(table_name_vc varchar(50), index_name_vc varchar(50), field_list_vc varchar(1024))
                    BEGIN

                    set @Index_cnt = (
                        SELECT COUNT(1) cnt
                        FROM INFORMATION_SCHEMA.STATISTICS
                        WHERE CONVERT(DATABASE() USING latin1) = CONVERT(TABLE_SCHEMA USING latin1)
                        AND CONVERT(table_name USING latin1) = CONVERT(table_name_vc USING latin1)
                        AND CONVERT(index_name USING latin1) = CONVERT(index_name_vc USING latin1)
                    );

                    IF IFNULL(@Index_cnt, 0) = 0 THEN
                        set @index_sql = CONCAT( 
                            CONVERT( 'ALTER TABLE ' USING latin1),
                            CONVERT( table_name_vc USING latin1),
                            CONVERT( ' ADD INDEX ' USING latin1),
                            CONVERT( index_name_vc USING latin1),
                            CONVERT( '(' USING latin1),
                            CONVERT( field_list_vc USING latin1),
                            CONVERT( ');' USING latin1)
                        );
                        PREPARE stmt FROM @index_sql;
                        EXECUTE stmt;
                        DEALLOCATE PREPARE stmt;
                    END IF;
                    END;
                </statement>
                <statement mode="plain">CALL create_index_if_not_exists('Images','dir_index','album');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('Images','hash_index','uniqueHash');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageTags','tag_index','tagid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageTags','tag_id_index','imageid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('Images','image_name_index','name(255)');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageInformation','creationdate_index','creationDate');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageComments','comments_imageid_index','imageid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageCopyright','copyright_imageid_index','imageid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageHistory','uuid_index','uuid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageRelations','subject_relations_index','subject');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageRelations','object_relations_index','object');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('TagProperties','tagproperties_index','tagid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageTagProperties','imagetagproperties_index','imageid, tagid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageTagProperties','imagetagproperties_imageid_index','imageid');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('ImageTagProperties','imagetagproperties_tagid_index','tagid');</statement>
            </dbaction>

            <!-- Mysql Core Triggers -->

            <dbaction name="CreateTriggers" mode="transaction">
<!-- Note move_tagstree does not exist for mysql
            <statement mode="plain">DROP TRIGGER IF EXISTS move_tagstree;</statement>
-->

            <statement mode="plain">SELECT 
                    @minLeft := IF(ISNULL(MIN(lft)), 1, MIN(lft)-1),
                    @maxRight := IF(ISNULL(MAX(rgt)), 2, MAX(rgt)+1)
                FROM Tags 
                WHERE id >= 0 AND pid>=0;
            </statement>
            <statement mode="plain">SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';</statement>
            <statement mode="plain">REPLACE INTO Tags
                (id, pid, name, icon, iconkde, lft, rgt)
                VALUES
                (0, -1, '_Digikam_root_tag_', NULL, NULL, @minLeft, @maxRight )
            </statement>
            <statement mode="plain">SET SQL_MODE=@OLD_SQL_MODE;</statement>
            </dbaction>

            <dbaction name="checkIfDatabaseExists">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID ORDER BY Images.name;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumByItemName">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID ORDER BY Images.name;</statement>
            </dbaction>

            <!-- NOTE: Don't collate on the path - this is to maintain the same behavior
                       that happens when sort order is "By Path"
            -->
            <dbaction name="getItemURLsInAlbumByItemPath">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID ORDER BY Albums.relativePath,Images.name;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumByItemDate">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album INNER JOIN ImageInformation ON ImageInformation.imageid=Images.id WHERE Albums.id=:albumID ORDER BY ImageInformation.creationDate;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumByItemRating">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album INNER JOIN ImageInformation ON ImageInformation.imageid=Images.id WHERE Albums.id=:albumID ORDER BY ImageInformation.rating DESC;</statement>
            </dbaction>

            <dbaction name="getItemURLsInAlbumNoItemSorting">
                <statement mode="query">SELECT Albums.relativePath, Images.name FROM Images INNER JOIN Albums ON Albums.id=Images.album WHERE Albums.id=:albumID;</statement>
            </dbaction>

            <dbaction name="changeImageInformation">
            <statement mode="query">INSERT INTO ImageInformation ( imageid, :fieldList ) VALUES ( :id, :valueList ) ON DUPLICATE KEY UPDATE :fieldValueList;</statement>
            </dbaction>

            <dbaction name="changeImageHistory">
            <statement mode="query">INSERT INTO ImageHistory( imageid, :fieldList ) VALUES ( :id, :valueList ) ON DUPLICATE KEY UPDATE :fieldValueList;</statement>
            </dbaction>

            <dbaction name="InsertTag" mode="transaction">
                <statement mode="plain">LOCK TABLE Tags WRITE;</statement>
                <statement mode="query">SELECT @myLeft := lft FROM Tags WHERE id = :tagPID;</statement>
                <statement mode="query">SELECT @myLeft := IF (@myLeft is null, 0, @myLeft);</statement>
                <statement mode="query">UPDATE Tags SET rgt = rgt + 2 WHERE rgt > @myLeft;</statement>
                <statement mode="query">UPDATE Tags SET lft = lft + 2 WHERE lft > @myLeft;</statement>
                <statement mode="query">INSERT INTO Tags(name, pid, lft, rgt) VALUES(:tagname, :tagPID, @myLeft + 1, @myLeft + 2);</statement>
                <statement mode="plain">UNLOCK TABLES;</statement>
            </dbaction>

            <dbaction name="DeleteTag" mode="transaction">
            <statement mode="plain">LOCK TABLE Tags WRITE;</statement>
            <statement mode="query">SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1
                                    FROM Tags
                                    WHERE id = :tagID;</statement>
            <statement mode="query">DELETE FROM Tags WHERE lft BETWEEN @myLeft AND @myRight;</statement>
            <statement mode="query">UPDATE Tags SET rgt = rgt - @myWidth WHERE rgt > @myRight;</statement>
            <statement mode="query">UPDATE Tags SET lft = lft - @myWidth WHERE lft > @myRight;</statement>
            <statement mode="plain">UNLOCK TABLES;</statement></dbaction>

            <dbaction name="deleteAlbumRoot" mode="transaction">
                <statement mode="query">SELECT @albumID:=id FROM Albums WHERE albumRoot=:albumRoot;</statement>
                <statement mode="query">DELETE FROM Albums WHERE albumRoot=:albumRoot;</statement>
                <statement mode="query">DELETE FROM Images WHERE Images.album=@albumID;</statement>
            </dbaction>

            <dbaction name="deleteAlbumRootPath" mode="transaction">
                <statement mode="query">SELECT @albumID:=id FROM Albums WHERE albumRoot=:albumRoot AND relativePath=:relativePath;</statement>
                <statement mode="query">DELETE FROM Albums WHERE albumRoot=:albumRoot AND relativePath=:relativePath;</statement>
                <statement mode="query">DELETE FROM Images WHERE Images.album=@albumID;</statement>
            </dbaction>

            <dbaction name="deleteAlbumID" mode="transaction">
            <statement mode="query">SELECT @albumID:=id FROM Albums WHERE Albums.id=:albumId;</statement>
            <statement mode="query">DELETE FROM Albums WHERE Albums.id=:albumId;</statement>
            <statement mode="query">DELETE FROM Images WHERE Images.album=@albumID;</statement>
            </dbaction>

            <dbaction name="GetItemURLsInTagRecursive">
            <statement mode="query">
SELECT DISTINCT alb.albumRoot, alb.relativePath, img.name
FROM (
       Images AS img
  JOIN Albums AS alb
    ON alb.id = img.album
  JOIN ImageTags AS ita
    ON ita.imageid = img.id
) JOIN (
  Tags As tp
  JOIN Tags As tc
    ON tc.lft BETWEEN tp.lft AND tp.rgt
)
ON tc.id = ita.tagID
WHERE img.status = 1 
  AND tp.id = :tagID
  /* AND tp.id = :tagID2 */
ORDER BY img.name
;
            </statement>
            </dbaction>

            <dbaction name="GetItemURLsInTag">
            <statement mode="query">
SELECT alb.albumRoot, alb.relativePath, img.name
FROM Albums AS alb 
JOIN Images AS img
  ON alb.id = img.album
JOIN ImageTags AS it
  ON it.imageid = img.id
WHERE img.status = 1 
  AND it.tagid = :tagID
;
            </statement>
            </dbaction>

            <dbaction name="getItemIDsInTagRecursive">
            <statement mode="query">
SELECT DISTINCT ita.imageid
FROM (
  Images AS img
  JOIN ImageTags AS ita
    ON ita.imageid = img.id
) JOIN (
  Tags As tp
  JOIN Tags As tc
    ON tc.lft BETWEEN tp.lft AND tp.rgt
)
ON tc.id = ita.tagID
WHERE img.status = 1 
  AND tp.id = :tagID
ORDER BY img.name
;
            </statement>
            </dbaction>

            <dbaction name="getItemIDsInTag">
            <statement mode="query">SELECT imageid FROM ImageTags JOIN Images ON ImageTags.imageid=Images.id
                                    WHERE Images.status=1 AND tagid=:tagID;
            </statement>
            </dbaction>

            <dbaction name="listTagRecursive">
            <statement mode="query">
SELECT DISTINCT 
    img.id, img.name, img.album,
    alb.albumRoot,
    inf.rating, img.category,
    inf.format, inf.creationDate,
    img.modificationDate, img.fileSize,
    inf.width, inf.height
FROM (
  Images AS img
  JOIN ImageInformation AS inf 
    ON img.id=inf.imageid
  JOIN Albums AS alb
    ON alb.id=img.album
  JOIN ImageTags AS ita
    ON ita.imageid = img.id
) JOIN (
  Tags As tp
  JOIN Tags As tc
    ON tc.lft BETWEEN tp.lft AND tp.rgt
)
ON tc.id = ita.tagID
WHERE img.status = 1 
  AND tp.id = :tagID
ORDER BY inf.rating DESC, img.name ASC
;
            </statement>
            </dbaction>

            <dbaction name="listTag">
            <statement mode="query">
SELECT DISTINCT 
    img.id, img.name, img.album,
    alb.albumRoot,
    inf.rating, img.category,
    inf.format, inf.creationDate,
    img.modificationDate, img.fileSize,
    inf.width, inf.height
FROM
  Images AS img
  JOIN ImageInformation AS inf 
    ON img.id=inf.imageid
  JOIN Albums AS alb
    ON alb.id=img.album
  JOIN ImageTags AS ita
    ON ita.imageid = img.id
WHERE img.status = 1 
  AND ita.tagID = :tagID
ORDER BY inf.rating DESC, img.name ASC
;
            </statement>
            </dbaction>

            <!-- Mysql Thumbnails Schema Database -->

            <dbaction name="CreateThumbnailsDB" mode="transaction">
                <statement mode="plain">CREATE TABLE IF NOT EXISTS Thumbnails
                            (id INTEGER PRIMARY KEY AUTO_INCREMENT,
                            type INTEGER,
                            modificationDate DATETIME,
                            orientationHint INTEGER,
                            data LONGBLOB) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS UniqueHashes
                            (uniqueHash VARCHAR(128),
                            fileSize INTEGER,
                            thumbId INTEGER,
                            CONSTRAINT UniqueHashes_Thumbnails FOREIGN KEY (thumbId) REFERENCES Thumbnails (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE(uniqueHash, fileSize)) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS FilePaths
                            (path VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin,
                            thumbId INTEGER,
                            CONSTRAINT FilePaths_Thumbnails FOREIGN KEY (thumbId) REFERENCES Thumbnails (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE(path(255))) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS CustomIdentifiers
                            (identifier VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin,
                            thumbId INTEGER,
                            CONSTRAINT CustomIdentifiers_Thumbnails FOREIGN KEY (thumbId) REFERENCES Thumbnails (id) ON DELETE CASCADE ON UPDATE CASCADE,
                            UNIQUE(identifier(255))) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS ThumbSettings
                            (keyword VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            UNIQUE(keyword(255))) ENGINE InnoDB;
                </statement>
            </dbaction>

            <!-- Mysql Thumbnails Indexes -->

            <dbaction name="CreateThumbnailsDBIndices" mode="transaction">
                <statement mode="plain">
                    DROP PROCEDURE IF EXISTS create_index_if_not_exists;
                </statement>
                <statement mode="plain">
                    CREATE PROCEDURE create_index_if_not_exists(table_name_vc varchar(50), index_name_vc varchar(50), field_list_vc varchar(1024))
                    BEGIN

                    set @Index_cnt = (
                        SELECT COUNT(1) cnt
                        FROM INFORMATION_SCHEMA.STATISTICS
                        WHERE CONVERT(DATABASE() USING latin1) = CONVERT(TABLE_SCHEMA USING latin1)
                        AND CONVERT(table_name USING latin1) = CONVERT(table_name_vc USING latin1)
                        AND CONVERT(index_name USING latin1) = CONVERT(index_name_vc USING latin1)
                    );

                    IF IFNULL(@Index_cnt, 0) = 0 THEN
                        set @index_sql = CONCAT( 
                            CONVERT( 'ALTER TABLE ' USING latin1),
                            CONVERT( table_name_vc USING latin1),
                            CONVERT( ' ADD INDEX ' USING latin1),
                            CONVERT( index_name_vc USING latin1),
                            CONVERT( '(' USING latin1),
                            CONVERT( field_list_vc USING latin1),
                            CONVERT( ');' USING latin1)
                        );
                        PREPARE stmt FROM @index_sql;
                        EXECUTE stmt;
                        DEALLOCATE PREPARE stmt;
                    END IF;
                    END;
                </statement>
                <statement mode="plain">CALL create_index_if_not_exists('UniqueHashes','id_uniqueHashes','thumbId');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('FilePaths','id_filePaths','thumbId');</statement>
                <statement mode="plain">CALL create_index_if_not_exists('CustomIdentifiers','id_customIdentifiers','thumbId');</statement>
            </dbaction>

            <!-- Mysql Thumbnails Trigger -->

            <dbaction name="CreateThumbnailsDBTrigger" mode="transaction"></dbaction>

            <!-- Mysql Thumbnails Queries -->

            <dbaction name="SelectThumbnailSetting">
                <statement mode="query">SELECT value FROM ThumbSettings WHERE keyword=:keyword;</statement>
            </dbaction>

            <dbaction name="SelectThumbnailLegacySetting">
                <statement mode="query">SELECT value FROM Settings WHERE keyword=:keyword;</statement>
            </dbaction>

            <dbaction name="ReplaceThumbnailSetting">
                <statement mode="query">REPLACE INTO ThumbSettings VALUES (:keyword, :value);</statement>
            </dbaction>

            <!-- Mysql Face Schema Database -->

            <dbaction name="CreateFaceDB" mode="transaction">
                <statement mode="plain">CREATE TABLE IF NOT EXISTS Identities
                            (id INTEGER PRIMARY KEY AUTO_INCREMENT,
                            type INTEGER) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS IdentityAttributes
                            (id INTEGER,
                            type INTEGER,
                            attribute TEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            value TEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            CONSTRAINT IdentityAttributes_Identities FOREIGN KEY (id) REFERENCES Identities (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS FaceSettings
                            (keyword LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                            value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            UNIQUE(keyword(255))) ENGINE InnoDB;
                </statement>
            </dbaction>

            <dbaction name="CreateFaceDBOpenCVLBPH" mode="transaction">
                <statement mode="plain">CREATE TABLE IF NOT EXISTS OpenCVLBPHRecognizer
                            (id INTEGER PRIMARY KEY AUTO_INCREMENT,
                            version INTEGER,
                            radius INTEGER,
                            neighbors INTEGER,
                            grid_x INTEGER,
                            grid_y INTEGER) ENGINE InnoDB;
                </statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS OpenCVLBPHistograms
                            (id INTEGER PRIMARY KEY AUTO_INCREMENT,
                            recognizerid INTEGER,
                            identity INTEGER,
                            context TEXT CHARACTER SET utf8 COLLATE utf8_bin,
                            type INTEGER,
                            rows INTEGER,
                            cols INTEGER,
                            data BLOB) ENGINE InnoDB;
                </statement>
            </dbaction>

            <!-- Mysql face Indexes -->

            <dbaction name="CreateFaceIndices" mode="transaction">
                <statement mode="plain">
                    DROP PROCEDURE IF EXISTS create_index_if_not_exists;
                </statement>
                <statement mode="plain">
                    CREATE PROCEDURE create_index_if_not_exists(table_name_vc varchar(50), index_name_vc varchar(50), field_list_vc varchar(1024))
                    BEGIN

                    set @Index_cnt = (
                        SELECT COUNT(1) cnt
                        FROM INFORMATION_SCHEMA.STATISTICS
                        WHERE CONVERT(DATABASE() USING latin1) = CONVERT(TABLE_SCHEMA USING latin1)
                        AND CONVERT(table_name USING latin1) = CONVERT(table_name_vc USING latin1)
                        AND CONVERT(index_name USING latin1) = CONVERT(index_name_vc USING latin1)
                    );

                    IF IFNULL(@Index_cnt, 0) = 0 THEN
                        set @index_sql = CONCAT( 
                            CONVERT( 'ALTER TABLE ' USING latin1),
                            CONVERT( table_name_vc USING latin1),
                            CONVERT( ' ADD INDEX ' USING latin1),
                            CONVERT( index_name_vc USING latin1),
                            CONVERT( '(' USING latin1),
                            CONVERT( field_list_vc USING latin1),
                            CONVERT( ');' USING latin1)
                        );
                        PREPARE stmt FROM @index_sql;
                        EXECUTE stmt;
                        DEALLOCATE PREPARE stmt;
                    END IF;
                    END;
                </statement>
                <statement mode="plain">CALL create_index_if_not_exists('IdentityAttributes','identityattributes_index','id');</statement>
            </dbaction>

            <!-- Mysql Face Triggers -->

            <dbaction name="CreateFaceTriggers" mode="transaction">
            </dbaction>

            <!-- Mysql Face Queries -->

            <dbaction name="SelectFaceSetting">
                <statement mode="query">SELECT value FROM FaceSettings WHERE keyword=:keyword;</statement>
            </dbaction>

            <dbaction name="ReplaceFaceSetting">
                <statement mode="query">REPLACE INTO FaceSettings VALUES (:keyword, :value);</statement>
            </dbaction>

            <!-- Mysql Migration Statements -->

            <!-- NOTE: Migrate_Cleanup_DB now it's done by the program except for cleanup prepare -->
            <dbaction name="Migrate_Cleanup_Prepare"><statement mode="transaction">
                ALTER TABLE Albums DROP FOREIGN KEY Albums_Images;
            </statement></dbaction>

            <dbaction name="Migrate_Read_AlbumRoots"><statement mode="query">
                SELECT id, label, status, type, identifier, specificPath FROM AlbumRoots;
            </statement></dbaction>
            <dbaction name="Migrate_Write_AlbumRoots" mode="transaction"><statement mode="query">
                INSERT INTO AlbumRoots (id, label, status, type, identifier, specificPath) VALUES (:id, :label, :status, :type, :identifier, :specificPath);
            </statement></dbaction>
            <!-- Note Albums with an icon set are setup after population of the Images table. -->
            <dbaction name="Migrate_Read_Albums"><statement mode="query">
                SELECT id, albumRoot, relativePath, date, caption, collection FROM Albums;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Albums" mode="transaction"><statement mode="query">
                INSERT INTO Albums (id, albumRoot, relativePath, date, caption, collection, icon) VALUES (:id, :albumRoot, :relativePath, :date, :caption, :collection, NULL);
            </statement></dbaction>
            <!-- Populate the Albums icon where set. -->
            <dbaction name="Migrate_Read_AlbumsExtra"><statement mode="query">
                SELECT id, icon FROM Albums where icon IS NOT NULL AND icon != 0;
            </statement></dbaction>
            <dbaction name="Migrate_Write_AlbumsExtra" mode="transaction"><statement mode="query">
                UPDATE Albums set icon = :icon WHERE id = :id;
            </statement></dbaction>
            <dbaction name="Migrate_Read_Images"><statement mode="query">
                SELECT id, album, name, status, category, modificationDate, fileSize, uniqueHash FROM Images;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Images" mode="transaction"><statement mode="query">
                INSERT INTO Images (id, album, name, status, category, modificationDate, fileSize, uniqueHash) VALUES (:id, :album, :name, :status, :category, :modificationDate, :fileSize, :uniqueHash);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageHaarMatrix"><statement mode="query">
                SELECT imageid, modificationDate, uniqueHash, matrix FROM ImageHaarMatrix;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageHaarMatrix" mode="transaction"><statement mode="query">
                INSERT INTO ImageHaarMatrix (imageid, modificationDate, uniqueHash, matrix) VALUES (:imageid, :modificationDate, :uniqueHash, :matrix);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageInformation"><statement mode="query">
                SELECT imageid, rating, creationDate, digitizationDate, orientation, width, height, format, colorDepth, colorModel FROM ImageInformation;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageInformation" mode="transaction"><statement mode="query">
                INSERT INTO ImageInformation (imageid, rating, creationDate, digitizationDate, orientation, width, height, format, colorDepth, colorModel) VALUES (:imageid, :rating, :creationDate, :digitizationDate, :orientation, :width, :height, :format, :colorDepth, :colorModel);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageMetadata"><statement mode="query">
                SELECT imageid, make, model, lens, aperture, focalLength, focalLength35, exposureTime, exposureProgram, exposureMode, sensitivity, flash, whiteBalance, whiteBalanceColorTemperature, meteringMode, subjectDistance, subjectDistanceCategory FROM ImageMetadata;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageMetadata" mode="transaction"><statement mode="query">
                INSERT INTO ImageMetadata (imageid, make, model, lens, aperture, focalLength, focalLength35, exposureTime, exposureProgram, exposureMode, sensitivity, flash, whiteBalance, whiteBalanceColorTemperature, meteringMode, subjectDistance, subjectDistanceCategory) VALUES (:imageid, :make, :model, :lens, :aperture, :focalLength, :focalLength35, :exposureTime, :exposureProgram, :exposureMode, :sensitivity, :flash, :whiteBalance, :whiteBalanceColorTemperature, :meteringMode, :subjectDistance, :subjectDistanceCategory);
            </statement></dbaction>

            <dbaction name="Migrate_Read_VideoMetadata"><statement mode="query">
                SELECT imageid, aspectRatio, audioBitRate, audioChannelType, audioCompressor, duration, frameRate, videoCodec FROM VideoMetadata;
            </statement></dbaction>
            <dbaction name="Migrate_Write_VideoMetadata" mode="transaction"><statement mode="query">
                INSERT INTO VideoMetadata (imageid, aspectRatio, audioBitRate, audioChannelType, audioCompressor, duration, frameRate, videoCodec) VALUES (:imageid, :aspectRatio, :audioBitRate, :audioChannelType, :audioCompressor, :duration, :frameRate, :videoCodec);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageTagProperties"><statement mode="query">
                SELECT imageid, tagid, property, value FROM ImageTagProperties;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageTagProperties"><statement mode="query">
                INSERT INTO ImageTagProperties (imageid, tagid, property, value) VALUES (:imageid, :tagid, :property, :value);
            </statement></dbaction>

            <dbaction name="Migrate_Read_TagProperties"><statement mode="query">
                SELECT tagid, property, value FROM TagProperties;
            </statement></dbaction>
            <dbaction name="Migrate_Write_TagProperties"><statement mode="query">
                INSERT INTO TagProperties (tagid, property, value) VALUES (:tagid, :property, :value);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImagePositions"><statement mode="query">
                SELECT  imageid, latitude, latitudeNumber, longitude, longitudeNumber, altitude, orientation, tilt, roll, accuracy, description FROM ImagePositions;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImagePositions" mode="transaction"><statement mode="query">
                INSERT INTO ImagePositions (imageid, latitude, latitudeNumber, longitude, longitudeNumber, altitude, orientation, tilt, roll, accuracy, description) VALUES (:imageid, :latitude, :latitudeNumber, :longitude, :longitudeNumber, :altitude, :orientation, :tilt, :roll, :accuracy, :description);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageComments"><statement mode="query">
                SELECT  id, imageid, type, language, author, date, comment FROM ImageComments;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageComments" mode="transaction"><statement mode="query">
                INSERT INTO ImageComments (id, imageid, type, language, author, date, comment) VALUES (:id, :imageid, :type, :language, :author, :date, :comment);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageCopyright"><statement mode="query">
                SELECT  id, imageid, property, value, extraValue FROM ImageCopyright;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageCopyright" mode="transaction"><statement mode="query">
                INSERT INTO ImageCopyright (id, imageid, property, value, extraValue) VALUES (:id, :imageid, :property, :value, :extraValue);
            </statement></dbaction>

            <dbaction name="Migrate_Read_Tags"><statement mode="query">
                SELECT  id, IF(Tags.pid = 0, -1, Tags.pid) AS pid, name, CASE WHEN icon = 0 THEN NULL ELSE icon END AS icon, iconkde FROM Tags WHERE id != 0;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Tags" mode="transaction">
                <statement mode="plain">LOCK TABLE Tags WRITE;</statement>
                <statement mode="query">SELECT @myLeft := lft FROM Tags WHERE id = :pid;</statement>
                <statement mode="query">SELECT @myLeft := IF (@myLeft is null, 0, @myLeft);</statement>
                <statement mode="query">UPDATE Tags SET rgt = rgt + 2 WHERE rgt > @myLeft;</statement>
                <statement mode="query">UPDATE Tags SET lft = lft + 2 WHERE lft > @myLeft;</statement>
                <statement mode="query">INSERT INTO Tags(id, pid, name, icon, iconkde, lft, rgt) VALUES(:id, :pid, :name, :icon, :iconkde, @myLeft + 1, @myLeft + 2);</statement>
                <statement mode="plain">UNLOCK TABLES;</statement>
            </dbaction>

            <dbaction name="Migrate_Read_ImageTags"><statement mode="query">
                SELECT  imageid, tagid FROM ImageTags;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageTags" mode="transaction"><statement mode="query">
                INSERT INTO ImageTags (imageid, tagid) VALUES (:imageid, :tagid);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageProperties"><statement mode="query">
                SELECT  imageid, property, value FROM ImageProperties;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageProperties" mode="transaction"><statement mode="query">
                INSERT INTO ImageProperties (imageid, property, value) VALUES (:imageid, :property, :value);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageHistory"><statement mode="query">
                SELECT  imageid, uuid, history FROM ImageHistory;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageHistory"><statement mode="query">
                INSERT INTO ImageHistory (imageid, uuid, history) VALUES (:imageid, :uuid, :history);
            </statement></dbaction>

            <dbaction name="Migrate_Read_ImageRelations"><statement mode="query">
                SELECT  subject, object, type FROM ImageRelations;
            </statement></dbaction>
            <dbaction name="Migrate_Write_ImageRelations"><statement mode="query">
                INSERT INTO ImageRelations (subject, object, type) VALUES (:subject, :object, :type);
            </statement></dbaction>

            <dbaction name="Migrate_Read_Searches"><statement mode="query">
                SELECT  id, type, name, query FROM Searches;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Searches" mode="transaction"><statement mode="query">
                INSERT INTO Searches (id, type, name, query) VALUES (:id, :type, :name, :query);
            </statement></dbaction>

            <dbaction name="Migrate_Read_DownloadHistory"><statement mode="query">
                SELECT id, identifier, filename, filesize, filedate FROM DownloadHistory;
            </statement></dbaction>
            <dbaction name="Migrate_Write_DownloadHistory" mode="transaction"><statement mode="query">
                INSERT INTO DownloadHistory (id, identifier, filename, filesize, filedate) VALUES (:id, :identifier, :filename, :filesize, :filedate);
            </statement></dbaction>

            <dbaction name="Migrate_Read_Settings"><statement mode="query">
                SELECT keyword, value FROM Settings;
            </statement></dbaction>
            <dbaction name="Migrate_Write_Settings" mode="transaction"><statement mode="query">
                INSERT INTO Settings (keyword, value) VALUES (:keyword, :value);
            </statement></dbaction>

            <dbaction name="Delete_Thumbnail_ByPath" mode="query">
                <statement mode="query">
                    SELECT @thumbsId := thumbId FROM FilePaths WHERE path=:path;
                </statement>
                <statement mode="query">
                    DELETE FROM UniqueHashes WHERE UniqueHashes.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM FilePaths WHERE FilePaths.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM Thumbnails WHERE id = @thumbsId;
                </statement>
            </dbaction>

            <dbaction name="Delete_Thumbnail_ByUniqueHashId" mode="query">
                <statement mode="query">
                    SELECT @thumbsId := thumbId FROM UniqueHashes WHERE uniqueHash=:uniqueHash AND fileSize=:filesize;
                </statement>
                <statement mode="query">
                    DELETE FROM UniqueHashes WHERE UniqueHashes.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM FilePaths WHERE FilePaths.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM Thumbnails WHERE id = @thumbsId;
                </statement>
            </dbaction>

            <dbaction name="Delete_Thumbnail_ByCustomIdentifier" mode="query">
                <statement mode="query">
                    SELECT @thumbsId := thumbId FROM CustomIdentifiers WHERE identifier=:identifier;
                </statement>
                <statement mode="query">
                    DELETE FROM UniqueHashes WHERE UniqueHashes.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM FilePaths WHERE FilePaths.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM CustomIdentifiers WHERE CustomIdentifiers.thumbId = @thumbsId;
                </statement>
                <statement mode="query">
                    DELETE FROM Thumbnails WHERE id = @thumbsId;
                </statement>
            </dbaction>

            <!-- Mysql Migration from Database Version 5 (0.10 - 1.4) to Version 6 (1.5-) -->

            <dbaction name="UpdateSchemaFromV5ToV6" mode="transaction">
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageHistory
                            (imageid INTEGER PRIMARY KEY,
                             uuid VARCHAR(128),
                             history LONGTEXT CHARACTER SET utf8);</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageRelations
                            (subject INTEGER,
                             object INTEGER,
                             type INTEGER,
                             UNIQUE(subject, object, type));</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS TagProperties
                            (tagid INTEGER,
                             property TEXT CHARACTER SET utf8,
                             value LONGTEXT CHARACTER SET utf8);</statement>
            <statement mode="plain">CREATE TABLE IF NOT EXISTS ImageTagProperties
                            (imageid INTEGER,
                             tagid INTEGER,
                             property TEXT CHARACTER SET utf8,
                             value LONGTEXT CHARACTER SET utf8);</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageTags','tag_id_index','imageid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('Images','image_name_index','name(255)');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageInformation','creationdate_index','creationDate');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageComments','comments_imageid_index','imageid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageCopyright','copyright_imageid_index','imageid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageHistory','uuid_index','uuid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageRelations','subject_relations_index','subject');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageRelations','object_relations_index','object');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('TagProperties','tagproperties_index','tagid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageTagProperties','imagetagproperties_index','imageid,tagid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageTagProperties','imagetagproperties_imageid_index','imageid');</statement>
            <statement mode="plain">CALL create_index_if_not_exists('ImageTagProperties','imagetagproperties_tagid_index','tagid');</statement>
            <statement mode="plain">ALTER TABLE Images CHANGE uniqueHash uniqueHash VARCHAR(128);</statement>
            <statement mode="plain">DROP TRIGGER IF EXISTS delete_image;</statement>
            <statement mode="plain">CREATE TRIGGER delete_image AFTER DELETE ON Images
                    FOR EACH ROW BEGIN
                        DELETE FROM ImageTags          WHERE imageid=OLD.id;
                        DELETE From ImageHaarMatrix    WHERE imageid=OLD.id;
                        DELETE From ImageInformation   WHERE imageid=OLD.id;
                        DELETE From ImageMetadata      WHERE imageid=OLD.id;
                        DELETE From VideoMetadata      WHERE imageid=OLD.id;
                        DELETE From ImagePositions     WHERE imageid=OLD.id;
                        DELETE From ImageComments      WHERE imageid=OLD.id;
                        DELETE From ImageCopyright     WHERE imageid=OLD.id;
                        DELETE From ImageProperties    WHERE imageid=OLD.id;
                        DELETE From ImageHistory       WHERE imageid=OLD.id;
                        DELETE FROM ImageRelations     WHERE subject=OLD.id OR object=OLD.id;
                        DELETE FROM ImageTagProperties WHERE imageid=OLD.id;
                        UPDATE Albums SET icon=null    WHERE icon=OLD.id;
                        UPDATE Tags SET icon=null      WHERE icon=OLD.id;
                    END;
            </statement>
            <statement mode="plain">DROP TRIGGER IF EXISTS delete_tag;</statement>
            <statement mode="plain">CREATE TRIGGER delete_tag AFTER DELETE ON Tags
                FOR EACH ROW BEGIN
                    DELETE FROM ImageTags          WHERE tagid=OLD.id;
                    DELETE FROM TagProperties      WHERE tagid=OLD.id;
                    DELETE FROM ImageTagProperties WHERE tagid=OLD.id;
                END;
            </statement>
            </dbaction>
            <dbaction name="UpdateSchemaFromV6ToV7" mode="transaction">
                <statement mode="plain">CREATE TABLE IF NOT EXISTS VideoMetadata
                                (imageid INTEGER PRIMARY KEY,
                                aspectRatio TEXT,
                                audioBitRate TEXT,
                                audioChannelType TEXT,
                                audioCompressor TEXT,
                                duration TEXT,
                                frameRate TEXT,
                                exposureProgram INTEGER,
                                videoCodec TEXT);</statement>
                <statement mode="plain">DROP TRIGGER IF EXISTS delete_image;</statement>
                <statement mode="plain">CREATE TRIGGER delete_image AFTER DELETE ON Images
                        FOR EACH ROW BEGIN
                            DELETE FROM ImageTags          WHERE imageid=OLD.id;
                            DELETE From ImageHaarMatrix    WHERE imageid=OLD.id;
                            DELETE From ImageInformation   WHERE imageid=OLD.id;
                            DELETE From ImageMetadata      WHERE imageid=OLD.id;
                            DELETE From VideoMetadata      WHERE imageid=OLD.id;
                            DELETE From ImagePositions     WHERE imageid=OLD.id;
                            DELETE From ImageComments      WHERE imageid=OLD.id;
                            DELETE From ImageCopyright     WHERE imageid=OLD.id;
                            DELETE From ImageProperties    WHERE imageid=OLD.id;
                            DELETE From ImageHistory       WHERE imageid=OLD.id;
                            DELETE FROM ImageRelations     WHERE subject=OLD.id OR object=OLD.id;
                            DELETE FROM ImageTagProperties WHERE imageid=OLD.id;
                            UPDATE Albums SET icon=null    WHERE icon=OLD.id;
                            UPDATE Tags SET icon=null      WHERE icon=OLD.id;
                        END;
                </statement>
            </dbaction>

            <dbaction name="UpdateSchemaFromV7ToV8" mode="transaction">
                <statement mode="plain">ALTER TABLE AlbumRoots MODIFY COLUMN label LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE AlbumRoots MODIFY COLUMN identifier LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE AlbumRoots MODIFY COLUMN specificPath LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE Albums MODIFY COLUMN relativePath LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE Albums MODIFY COLUMN caption LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE Albums MODIFY COLUMN collection LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE Images MODIFY COLUMN name LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE Images MODIFY COLUMN fileSize BIGINT;</statement>
                <statement mode="plain">ALTER TABLE ImageHaarMatrix MODIFY COLUMN uniqueHash LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageInformation MODIFY COLUMN format LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageMetadata MODIFY COLUMN make LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageMetadata MODIFY COLUMN model LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageMetadata MODIFY COLUMN lens LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImagePositions MODIFY COLUMN latitude LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImagePositions MODIFY COLUMN longitude LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImagePositions MODIFY COLUMN description LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageComments MODIFY COLUMN language VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageComments MODIFY COLUMN author LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageComments MODIFY COLUMN comment LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageCopyright MODIFY COLUMN property LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageCopyright MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageCopyright MODIFY COLUMN extraValue LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE Tags MODIFY COLUMN name LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE Tags MODIFY COLUMN iconkde LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageProperties MODIFY COLUMN property LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE ImageProperties MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE Searches MODIFY COLUMN name LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE Searches MODIFY COLUMN query LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE DownloadHistory MODIFY COLUMN identifier LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE DownloadHistory MODIFY COLUMN filename LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE DownloadHistory MODIFY COLUMN filesize BIGINT;</statement>
                <statement mode="plain">ALTER TABLE Settings MODIFY COLUMN keyword LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;</statement>
                <statement mode="plain">ALTER TABLE Settings MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageHistory MODIFY COLUMN history LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE TagProperties MODIFY COLUMN property TEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE TagProperties MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageTagProperties MODIFY COLUMN property TEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ImageTagProperties MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">DROP TRIGGER IF EXISTS delete_image;</statement>
                <statement mode="plain">DROP TRIGGER IF EXISTS delete_tag;</statement>
                <statement mode="plain">DROP TRIGGER IF EXISTS move_tagstree;</statement>
                <statement mode="plain">ALTER TABLE AlbumRoots
                                        DROP INDEX IF EXISTS identifier;</statement>
                <statement mode="plain">ALTER TABLE AlbumRoots
                                        ADD UNIQUE (identifier(127), specificPath(128)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE Albums
                                        DROP FOREIGN KEY IF EXISTS Albums_AlbumRoots,
                                        DROP INDEX IF EXISTS albumRoot;</statement>
                <statement mode="plain">ALTER TABLE Albums
                                        ADD CONSTRAINT Albums_AlbumRoots FOREIGN KEY (albumRoot) REFERENCES AlbumRoots (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD UNIQUE (albumRoot, relativePath(255)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE Images
                                        DROP FOREIGN KEY IF EXISTS Images_Albums,
                                        DROP INDEX IF EXISTS album;</statement>
                <statement mode="plain">ALTER TABLE Images
                                        ADD CONSTRAINT Images_Albums FOREIGN KEY (album) REFERENCES Albums (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD UNIQUE (album, name(255)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">UPDATE Albums SET icon = null where icon = 0;</statement>
                <statement mode="plain">ALTER TABLE Albums
                                        DROP FOREIGN KEY IF EXISTS Albums_Images;</statement>
                <statement mode="plain">ALTER TABLE Albums
                                        ADD CONSTRAINT Albums_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE;</statement>
                <statement mode="plain">ALTER TABLE ImageHaarMatrix
                                        DROP FOREIGN KEY IF EXISTS ImageHaarMatrix_Images;</statement>
                <statement mode="plain">ALTER TABLE ImageHaarMatrix
                                        ADD CONSTRAINT ImageHaarMatrix_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageInformation
                                        DROP FOREIGN KEY IF EXISTS ImageInformation_Images;</statement>
                <statement mode="plain">ALTER TABLE ImageInformation
                                        ADD CONSTRAINT ImageInformation_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageMetadata
                                        DROP FOREIGN KEY IF EXISTS ImageMetadata_Images;</statement>
                <statement mode="plain">ALTER TABLE ImageMetadata
                                        ADD CONSTRAINT ImageMetadata_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE VideoMetadata
                                        DROP FOREIGN KEY IF EXISTS VideoMetadata_Images;</statement>
                <statement mode="plain">ALTER TABLE VideoMetadata
                                        ADD CONSTRAINT VideoMetadata_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImagePositions
                                        DROP FOREIGN KEY IF EXISTS ImagePositions_Images;</statement>
                <statement mode="plain">ALTER TABLE ImagePositions
                                        ADD CONSTRAINT ImagePositions_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageComments
                                        DROP FOREIGN KEY IF EXISTS ImageComments_Images,
                                        DROP INDEX IF EXISTS imageid;</statement>
                <statement mode="plain">ALTER TABLE ImageComments
                                        ADD CONSTRAINT ImageComments_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD UNIQUE(imageid, type, language, author(202)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageCopyright
                                        DROP FOREIGN KEY IF EXISTS ImageCopyright_Images,
                                        DROP INDEX IF EXISTS imageid;</statement>
                <statement mode="plain">ALTER TABLE ImageCopyright
                                        ADD CONSTRAINT ImageCopyright_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD UNIQUE(imageid, property(110), value(111), extraValue(111)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';</statement>
                <statement mode="plain">REPLACE INTO Tags (id, pid, name, icon, iconkde, lft, rgt) VALUES (0, -1, '_Digikam_root_tag_', NULL, NULL,
                                        (SELECT MIN(tl.lft) FROM Tags AS tl),
                                        (SELECT MAX(tr.rgt) FROM Tags AS tr));</statement>
                <statement mode="plain">SET SQL_MODE=@OLD_SQL_MODE;</statement>
                <statement mode="plain">UPDATE Tags set icon = null where icon = 0;</statement>
                <statement mode="plain">ALTER TABLE Tags
                                        DROP FOREIGN KEY IF EXISTS Tags_Images,
                                        DROP INDEX IF EXISTS pid;</statement>
                <statement mode="plain">ALTER TABLE Tags
                                        ADD CONSTRAINT Tags_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE,
                                        ADD UNIQUE(pid, name(100)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageTags
                                        DROP FOREIGN KEY IF EXISTS ImageTags_Images,
                                        DROP FOREIGN KEY IF EXISTS ImageTags_Tags;</statement>
                <statement mode="plain">ALTER TABLE ImageTags
                                        ADD CONSTRAINT ImageTags_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD CONSTRAINT ImageTags_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageProperties
                                        DROP FOREIGN KEY IF EXISTS ImageProperties_Images,
                                        DROP INDEX IF EXISTS imageid;</statement>
                <statement mode="plain">ALTER TABLE ImageProperties
                                        ADD CONSTRAINT ImageProperties_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD UNIQUE (imageid, property(255)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE Searches
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE DownloadHistory
                                        DROP INDEX IF EXISTS identifier;</statement>
                <statement mode="plain">ALTER TABLE DownloadHistory
                                        ADD UNIQUE(identifier(164), filename(165), filesize, filedate),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE Settings
                                        DROP INDEX IF EXISTS keyword;</statement>
                <statement mode="plain">ALTER TABLE Settings
                                        ADD UNIQUE(keyword(255)),
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageHistory
                                        DROP FOREIGN KEY IF EXISTS ImageHistory_Images;</statement>
                <statement mode="plain">ALTER TABLE ImageHistory
                                        ADD CONSTRAINT ImageHistory_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageRelations
                                        DROP FOREIGN KEY IF EXISTS ImageRelations_ImagesS,
                                        DROP FOREIGN KEY IF EXISTS ImageRelations_ImagesO;</statement>
                <statement mode="plain">ALTER TABLE ImageRelations
                                        ADD CONSTRAINT ImageRelations_ImagesS FOREIGN KEY (subject) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD CONSTRAINT ImageRelations_ImagesO FOREIGN KEY (object) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE TagProperties
                                        DROP FOREIGN KEY IF EXISTS TagProperties_Tags;</statement>
                <statement mode="plain">ALTER TABLE TagProperties
                                        ADD CONSTRAINT TagProperties_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE ImageTagProperties
                                        DROP FOREIGN KEY IF EXISTS ImageTagProperties_Images,
                                        DROP FOREIGN KEY IF EXISTS ImageTagProperties_Tags;</statement>
                <statement mode="plain">ALTER TABLE ImageTagProperties
                                        ADD CONSTRAINT ImageTagProperties_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ADD CONSTRAINT ImageTagProperties_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
                                        ENGINE InnoDB;</statement>
            </dbaction>

            <dbaction name="UpdateThumbnailsDBSchemaFromV1ToV2" mode="transaction">
                <statement mode="plain">ALTER TABLE UniqueHashes CHANGE uniqueHash uniqueHash VARCHAR(128);</statement>
                <statement mode="plain">CREATE TABLE IF NOT EXISTS CustomIdentifiers
                            (identifier LONGTEXT CHARACTER SET utf8,
                            thumbId INTEGER,
                            UNIQUE(identifier(333)));
                </statement>
                <statement mode="plain">CALL create_index_if_not_exists('CustomIdentifiers','id_customIdentifiers','thumbId');</statement>
            </dbaction>
            <dbaction name="UpdateThumbnailsDBSchemaFromV2ToV3" mode="transaction">
                <statement mode="plain">ALTER TABLE Settings RENAME ThumbSettings;</statement>
                <statement mode="plain">ALTER TABLE ThumbSettings
                                                      MODIFY COLUMN keyword VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin,
                                                      MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE ThumbSettings ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE Thumbnails ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE UniqueHashes ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE FilePaths MODIFY COLUMN path VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE FilePaths ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE CustomIdentifiers MODIFY COLUMN identifier VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;</statement>
                <statement mode="plain">ALTER TABLE CustomIdentifiers ENGINE InnoDB;</statement>
                <statement mode="plain">ALTER TABLE UniqueHashes
                            ADD CONSTRAINT UniqueHashes_Thumbnails FOREIGN KEY (thumbId) REFERENCES Thumbnails (id) ON DELETE CASCADE ON UPDATE CASCADE;
                </statement>
                <statement mode="plain">ALTER TABLE FilePaths
                            ADD CONSTRAINT FilePaths_Thumbnails FOREIGN KEY (thumbId) REFERENCES Thumbnails (id) ON DELETE CASCADE ON UPDATE CASCADE;
                </statement>
                <statement mode="plain">ALTER TABLE CustomIdentifiers
                            ADD CONSTRAINT CustomIdentifiers_Thumbnails FOREIGN KEY (thumbId) REFERENCES Thumbnails (id) ON DELETE CASCADE ON UPDATE CASCADE;
                </statement>
            </dbaction>

            <!-- statements for shrinking the databases -->

            <dbaction name="vacuumCoreDB">
                <statement mode="query">OPTIMIZE TABLE Albums, Images, ImageHaarMatrix, ImageInformation, ImageMetadata, VideoMetadata, ImagePositions, ImageComments, ImageCopyright, ImageProperties, ImageHistory, ImageRelations, Tags, ImageTags, ImageTagProperties;</statement>
            </dbaction>

            <dbaction name="vacuumThumbnailsDB">
                <statement mode="query">OPTIMIZE TABLE Thumbnails, UniqueHashes, FilePaths, CustomIdentifiers;</statement>
            </dbaction>

            <dbaction name="vacuumRecognitionDB">
                <statement mode="query">OPTIMIZE TABLE Identities, IdentityAttributes;</statement>
            </dbaction>
            
            <dbaction name="checkCoreDbIntegrity"> 
                <statement mode="unprepared">CHECK TABLE Albums, Images, ImageHaarMatrix, ImageInformation, ImageMetadata, VideoMetadata, ImagePositions, ImageComments, ImageCopyright, ImageProperties, ImageHistory, ImageRelations, Tags, ImageTags, ImageTagProperties;</statement>
            </dbaction>

            <dbaction name="checkThumbnailsDbIntegrity">
                <statement mode="unprepared">CHECK TABLE Thumbnails, UniqueHashes, FilePaths, CustomIdentifiers;</statement>
            </dbaction>

            <dbaction name="checkRecognitionDbIntegrity">
                <statement mode="unprepared">CHECK TABLE Identities, IdentityAttributes;</statement>
            </dbaction>

        </dbactions>

    </database>

</databaseconfig>