Commit 85938288 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Rename Part.external bool column to Part.storage enum

For now the enum only has Internal and External values,
but we will extend this eventually with another value.
parent d257ae7c
...@@ -431,13 +431,13 @@ void ProtocolTest::testPartMetaData() ...@@ -431,13 +431,13 @@ void ProtocolTest::testPartMetaData()
in.setName("PLD:HEAD"); in.setName("PLD:HEAD");
in.setSize(42); in.setSize(42);
in.setVersion(1); in.setVersion(1);
in.setIsExternal(true); in.setStorageType(PartMetaData::External);
const PartMetaData out = serializeAndDeserialize(in); const PartMetaData out = serializeAndDeserialize(in);
QCOMPARE(out.name(), QByteArray("PLD:HEAD")); QCOMPARE(out.name(), QByteArray("PLD:HEAD"));
QCOMPARE(out.size(), 42); QCOMPARE(out.size(), 42);
QCOMPARE(out.version(), 1); QCOMPARE(out.version(), 1);
QCOMPARE(out.isExternal(), true); QCOMPARE(out.storageType(), PartMetaData::External);
QCOMPARE(out, in); QCOMPARE(out, in);
const bool notEquals = (in != out); const bool notEquals = (in != out);
QVERIFY(!notEquals); QVERIFY(!notEquals);
......
...@@ -84,18 +84,18 @@ public: ...@@ -84,18 +84,18 @@ public:
struct PartHelper struct PartHelper
{ {
PartHelper(const QString &type_, const QByteArray &data_, int size_, bool external_ = false, int version_ = 0) PartHelper(const QString &type_, const QByteArray &data_, int size_, Part::Storage storage_ = Part::Internal, int version_ = 0)
: type(type_) : type(type_)
, data(data_) , data(data_)
, size(size_) , size(size_)
, external(external_) , storage(storage_)
, version(version_) , version(version_)
{ {
} }
QString type; QString type;
QByteArray data; QByteArray data;
int size; int size;
bool external; Part::Storage storage;
int version; int version;
}; };
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
part.setPartType(PartType(types[1], types[0])); part.setPartType(PartType(types[1], types[0]));
part.setData(helper.data); part.setData(helper.data);
part.setDatasize(helper.size); part.setDatasize(helper.size);
part.setExternal(helper.external); part.setStorage(helper.storage);
part.setVersion(helper.version); part.setVersion(helper.version);
parts << part; parts << part;
} }
...@@ -760,7 +760,7 @@ private Q_SLOTS: ...@@ -760,7 +760,7 @@ private Q_SLOTS:
QCOMPARE(QString::fromUtf8(actualPart.data()), QString::fromUtf8(part.data())); QCOMPARE(QString::fromUtf8(actualPart.data()), QString::fromUtf8(part.data()));
QCOMPARE(actualPart.data(), part.data()); QCOMPARE(actualPart.data(), part.data());
QCOMPARE(actualPart.datasize(), part.datasize()); QCOMPARE(actualPart.datasize(), part.datasize());
QCOMPARE(actualPart.external(), part.external()); QCOMPARE(actualPart.storage(), part.storage());
} }
} }
} }
......
...@@ -39,6 +39,7 @@ using namespace Akonadi; ...@@ -39,6 +39,7 @@ using namespace Akonadi;
using namespace Akonadi::Server; using namespace Akonadi::Server;
Q_DECLARE_METATYPE(Akonadi::Server::PimItem) Q_DECLARE_METATYPE(Akonadi::Server::PimItem)
Q_DECLARE_METATYPE(Akonadi::Server::Part::Storage)
class PartStreamerTest : public QObject class PartStreamerTest : public QObject
{ {
...@@ -81,7 +82,7 @@ private Q_SLOTS: ...@@ -81,7 +82,7 @@ private Q_SLOTS:
QTest::addColumn<QByteArray>("expectedFileData"); QTest::addColumn<QByteArray>("expectedFileData");
QTest::addColumn<qint64>("expectedPartSize"); QTest::addColumn<qint64>("expectedPartSize");
QTest::addColumn<bool>("expectedChanged"); QTest::addColumn<bool>("expectedChanged");
QTest::addColumn<bool>("isExternal"); QTest::addColumn<Part::Storage>("storage");
QTest::addColumn<PimItem>("pimItem"); QTest::addColumn<PimItem>("pimItem");
PimItem item; PimItem item;
...@@ -110,7 +111,7 @@ private Q_SLOTS: ...@@ -110,7 +111,7 @@ private Q_SLOTS:
<< TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA", "123")) << TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA", "123"))
<< TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 1)); << TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 1));
QTest::newRow("item 1, internal") << scenarios << QByteArray("PLD:DATA") << QByteArray("123") << QByteArray() << 3ll << true << false << item; QTest::newRow("item 1, internal") << scenarios << QByteArray("PLD:DATA") << QByteArray("123") << QByteArray() << 3ll << true << Part::Internal << item;
} }
{ {
...@@ -123,7 +124,7 @@ private Q_SLOTS: ...@@ -123,7 +124,7 @@ private Q_SLOTS:
<< TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA")) << TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA"))
<< TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 2)); << TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 2));
QTest::newRow("item 1, change to external") << scenarios << QByteArray("PLD:DATA") << QByteArray("15_r0") << QByteArray("123456789") << 9ll << true << true << item; QTest::newRow("item 1, change to external") << scenarios << QByteArray("PLD:DATA") << QByteArray("15_r0") << QByteArray("123456789") << 9ll << true << Part::External << item;
} }
{ {
...@@ -136,7 +137,7 @@ private Q_SLOTS: ...@@ -136,7 +137,7 @@ private Q_SLOTS:
<< TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA")) << TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA"))
<< TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 3)); << TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 3));
QTest::newRow("item 1, update external") << scenarios << QByteArray("PLD:DATA") << QByteArray("15_r1") << QByteArray("987654321") << 9ll << true << true << item; QTest::newRow("item 1, update external") << scenarios << QByteArray("PLD:DATA") << QByteArray("15_r1") << QByteArray("987654321") << 9ll << true << Part::External << item;
} }
{ {
...@@ -149,7 +150,7 @@ private Q_SLOTS: ...@@ -149,7 +150,7 @@ private Q_SLOTS:
<< TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA")) << TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA"))
<< TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 4)); << TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 4));
QTest::newRow("item 1, external, no change") << scenarios << QByteArray("PLD:DATA") << QByteArray("15_r2") << QByteArray("987654321") << 9ll << false << true << item; QTest::newRow("item 1, external, no change") << scenarios << QByteArray("PLD:DATA") << QByteArray("15_r2") << QByteArray("987654321") << 9ll << false << Part::External << item;
} }
{ {
...@@ -162,7 +163,7 @@ private Q_SLOTS: ...@@ -162,7 +163,7 @@ private Q_SLOTS:
<< TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA", "1234")) << TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA", "1234"))
<< TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 5)); << TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 5));
QTest::newRow("item 1, change to internal") << scenarios << QByteArray("PLD:DATA") << QByteArray("1234") << QByteArray() << 4ll << true << false << item; QTest::newRow("item 1, change to internal") << scenarios << QByteArray("PLD:DATA") << QByteArray("1234") << QByteArray() << 4ll << true << Part::Internal << item;
} }
{ {
...@@ -175,7 +176,7 @@ private Q_SLOTS: ...@@ -175,7 +176,7 @@ private Q_SLOTS:
<< TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA", "1234")) << TestScenario::create(5, TestScenario::ClientCmd, Protocol::StreamPayloadResponse("PLD:DATA", "1234"))
<< TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 6)); << TestScenario::create(5, TestScenario::ServerCmd, Protocol::ModifyItemsResponse(item.id(), 6));
QTest::newRow("item 1, internal, no change") << scenarios << QByteArray("PLD:DATA") << QByteArray("1234") << QByteArray() << 4ll << false << false << item; QTest::newRow("item 1, internal, no change") << scenarios << QByteArray("PLD:DATA") << QByteArray("1234") << QByteArray() << 4ll << false << Part::Internal << item;
} }
} }
...@@ -186,10 +187,10 @@ private Q_SLOTS: ...@@ -186,10 +187,10 @@ private Q_SLOTS:
QFETCH(QByteArray, expectedPartData); QFETCH(QByteArray, expectedPartData);
QFETCH(QByteArray, expectedFileData); QFETCH(QByteArray, expectedFileData);
QFETCH(qint64, expectedPartSize); QFETCH(qint64, expectedPartSize);
QFETCH(bool, isExternal); QFETCH(Part::Storage, storage);
QFETCH(PimItem, pimItem); QFETCH(PimItem, pimItem);
if (isExternal) { if (storage == Part::External) {
// Create the payload file now, since don't have means to react // Create the payload file now, since don't have means to react
// directly to the streaming command // directly to the streaming command
QFile file(ExternalPartStorage::resolveAbsolutePath(expectedPartData)); QFile file(ExternalPartStorage::resolveAbsolutePath(expectedPartData));
...@@ -206,10 +207,10 @@ private Q_SLOTS: ...@@ -206,10 +207,10 @@ private Q_SLOTS:
QVERIFY(parts.count() == 1); QVERIFY(parts.count() == 1);
const Part part = parts[0]; const Part part = parts[0];
QCOMPARE(part.datasize(), expectedPartSize); QCOMPARE(part.datasize(), expectedPartSize);
QCOMPARE(part.external(), isExternal); QCOMPARE(part.storage(), storage);
const QByteArray data = part.data(); const QByteArray data = part.data();
if (isExternal) { if (storage == Part::External) {
QCOMPARE(data, expectedPartData); QCOMPARE(data, expectedPartData);
QFile file(ExternalPartStorage::resolveAbsolutePath(data)); QFile file(ExternalPartStorage::resolveAbsolutePath(data));
QVERIFY(file.exists()); QVERIFY(file.exists());
......
...@@ -476,14 +476,15 @@ Item ProtocolHelper::parseItemFetchResult(const Protocol::FetchItemsResponse &da ...@@ -476,14 +476,15 @@ Item ProtocolHelper::parseItemFetchResult(const Protocol::FetchItemsResponse &da
Q_FOREACH (const Protocol::StreamPayloadResponse &part, data.parts()) { Q_FOREACH (const Protocol::StreamPayloadResponse &part, data.parts()) {
ProtocolHelper::PartNamespace ns; ProtocolHelper::PartNamespace ns;
const QByteArray plainKey = decodePartIdentifier(part.payloadName(), ns); const QByteArray plainKey = decodePartIdentifier(part.payloadName(), ns);
const auto metaData = part.metaData();
switch (ns) { switch (ns) {
case ProtocolHelper::PartPayload: case ProtocolHelper::PartPayload:
ItemSerializer::deserialize(item, plainKey, part.data(), part.metaData().version(), part.metaData().isExternal()); ItemSerializer::deserialize(item, plainKey, part.data(), metaData.version(), metaData.storageType());
break; break;
case ProtocolHelper::PartAttribute: { case ProtocolHelper::PartAttribute: {
Attribute *attr = AttributeFactory::createAttribute(plainKey); Attribute *attr = AttributeFactory::createAttribute(plainKey);
Q_ASSERT(attr); Q_ASSERT(attr);
if (part.metaData().isExternal()) { if (metaData.storageType() == Protocol::PartMetaData::External) {
const QString filename = ExternalPartStorage::resolveAbsolutePath(part.data()); const QString filename = ExternalPartStorage::resolveAbsolutePath(part.data());
QFile file(filename); QFile file(filename);
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
......
...@@ -1062,12 +1062,12 @@ class PartMetaDataPrivate : public QSharedData ...@@ -1062,12 +1062,12 @@ class PartMetaDataPrivate : public QSharedData
{ {
public: public:
PartMetaDataPrivate(const QByteArray &name = QByteArray(), qint64 size = 0, PartMetaDataPrivate(const QByteArray &name = QByteArray(), qint64 size = 0,
int version = 0, bool external = false) int version = 0, PartMetaData::StorageType storageType = PartMetaData::Internal)
: QSharedData() : QSharedData()
, name(name) , name(name)
, size(size) , size(size)
, version(version) , version(version)
, external(external) , storageType(storageType)
{} {}
PartMetaDataPrivate(const PartMetaDataPrivate &other) PartMetaDataPrivate(const PartMetaDataPrivate &other)
...@@ -1075,13 +1075,13 @@ public: ...@@ -1075,13 +1075,13 @@ public:
, name(other.name) , name(other.name)
, size(other.size) , size(other.size)
, version(other.version) , version(other.version)
, external(other.external) , storageType(other.storageType)
{} {}
QByteArray name; QByteArray name;
qint64 size; qint64 size;
int version; int version;
bool external; PartMetaData::StorageType storageType;
}; };
PartMetaData::PartMetaData() PartMetaData::PartMetaData()
...@@ -1089,8 +1089,9 @@ PartMetaData::PartMetaData() ...@@ -1089,8 +1089,9 @@ PartMetaData::PartMetaData()
{ {
} }
PartMetaData::PartMetaData(const QByteArray &name, qint64 size, int version, bool external) PartMetaData::PartMetaData(const QByteArray &name, qint64 size, int version,
: d(new PartMetaDataPrivate(name, size, version, external)) StorageType storageType)
: d(new PartMetaDataPrivate(name, size, version, storageType))
{ {
} }
...@@ -1126,7 +1127,7 @@ bool PartMetaData::operator==(const PartMetaData &other) const ...@@ -1126,7 +1127,7 @@ bool PartMetaData::operator==(const PartMetaData &other) const
|| (d->name == other.d->name || (d->name == other.d->name
&& d->size == other.d->size && d->size == other.d->size
&& d->version == other.d->version && d->version == other.d->version
&& d->external == other.d->external); && d->storageType == other.d->storageType);
} }
bool PartMetaData::operator!=(const PartMetaData &other) const bool PartMetaData::operator!=(const PartMetaData &other) const
...@@ -1166,13 +1167,14 @@ int PartMetaData::version() const ...@@ -1166,13 +1167,14 @@ int PartMetaData::version() const
return d->version; return d->version;
} }
void PartMetaData::setIsExternal(bool external) void PartMetaData::setStorageType(StorageType storageType)
{ {
d->external = external; d->storageType = storageType;
} }
bool PartMetaData::isExternal() const
PartMetaData::StorageType PartMetaData::storageType() const
{ {
return d->external; return d->storageType;
} }
DataStream &operator<<(DataStream &stream, const PartMetaData &part) DataStream &operator<<(DataStream &stream, const PartMetaData &part)
...@@ -1180,7 +1182,7 @@ DataStream &operator<<(DataStream &stream, const PartMetaData &part) ...@@ -1180,7 +1182,7 @@ DataStream &operator<<(DataStream &stream, const PartMetaData &part)
return stream << part.d->name return stream << part.d->name
<< part.d->size << part.d->size
<< part.d->version << part.d->version
<< part.d->external; << part.d->storageType;
} }
DataStream &operator>>(DataStream &stream, PartMetaData &part) DataStream &operator>>(DataStream &stream, PartMetaData &part)
...@@ -1188,7 +1190,7 @@ DataStream &operator>>(DataStream &stream, PartMetaData &part) ...@@ -1188,7 +1190,7 @@ DataStream &operator>>(DataStream &stream, PartMetaData &part)
return stream >> part.d->name return stream >> part.d->name
>> part.d->size >> part.d->size
>> part.d->version >> part.d->version
>> part.d->external; >> part.d->storageType;
} }
/******************************************************************************/ /******************************************************************************/
...@@ -3205,7 +3207,13 @@ public: ...@@ -3205,7 +3207,13 @@ public:
Q_FOREACH (const StreamPayloadResponse &part, parts) { Q_FOREACH (const StreamPayloadResponse &part, parts) {
blck.beginBlock(part.payloadName()); blck.beginBlock(part.payloadName());
blck.write("Size", part.metaData().size()); blck.write("Size", part.metaData().size());
blck.write("External", part.metaData().isExternal()); blck.write("External", [](PartMetaData::StorageType storage) {
switch (storage) {
case PartMetaData::Internal: return QStringLiteral("Internal");
case PartMetaData::External: return QStringLiteral("External");
case PartMetaData::Foreign: return QStringLiteral("Foreign");
}; Q_UNREACHABLE();
}(part.metaData().storageType()));
blck.write("Version", part.metaData().version()); blck.write("Version", part.metaData().version());
blck.write("Data", part.data()); blck.write("Data", part.data());
blck.endBlock(); blck.endBlock();
......
...@@ -362,9 +362,15 @@ class PartMetaDataPrivate; ...@@ -362,9 +362,15 @@ class PartMetaDataPrivate;
class AKONADIPRIVATE_EXPORT PartMetaData class AKONADIPRIVATE_EXPORT PartMetaData
{ {
public: public:
enum StorageType {
Internal,
External,
Foreign
};
explicit PartMetaData(); explicit PartMetaData();
PartMetaData(const QByteArray &name, qint64 size, int version = 0, PartMetaData(const QByteArray &name, qint64 size, int version = 0,
bool external = false); StorageType storageType = Internal);
PartMetaData(PartMetaData &&other); PartMetaData(PartMetaData &&other);
PartMetaData(const PartMetaData &other); PartMetaData(const PartMetaData &other);
~PartMetaData(); ~PartMetaData();
...@@ -386,8 +392,8 @@ public: ...@@ -386,8 +392,8 @@ public:
void setVersion(int version); void setVersion(int version);
int version() const; int version() const;
void setIsExternal(bool isExternal); void setStorageType(StorageType storage);
bool isExternal() const; StorageType storageType() const;
private: private:
QSharedDataPointer<PartMetaDataPrivate> d; QSharedDataPointer<PartMetaDataPrivate> d;
......
...@@ -48,7 +48,7 @@ bool Copy::copyItem(const PimItem &item, const Collection &target) ...@@ -48,7 +48,7 @@ bool Copy::copyItem(const PimItem &item, const Collection &target)
parts.reserve(item.parts().count()); parts.reserve(item.parts().count());
Q_FOREACH (const Part &part, item.parts()) { Q_FOREACH (const Part &part, item.parts()) {
Part newPart(part); Part newPart(part);
newPart.setData(PartHelper::translateData(newPart.data(), part.external())); newPart.setData(PartHelper::translateData(newPart.data(), part.storage()));
newPart.setPimItemId(-1); newPart.setPimItemId(-1);
parts << newPart; parts << newPart;
} }
......
...@@ -81,7 +81,7 @@ enum PartQueryColumns { ...@@ -81,7 +81,7 @@ enum PartQueryColumns {
PartQueryPimIdColumn, PartQueryPimIdColumn,
PartQueryTypeIdColumn, PartQueryTypeIdColumn,
PartQueryDataColumn, PartQueryDataColumn,
PartQueryExternalColumn, PartQueryStorageColumn,
PartQueryVersionColumn, PartQueryVersionColumn,
PartQueryDataSizeColumn PartQueryDataSizeColumn
}; };
...@@ -96,7 +96,7 @@ QSqlQuery FetchHelper::buildPartQuery(const QVector<QByteArray> &partList, bool ...@@ -96,7 +96,7 @@ QSqlQuery FetchHelper::buildPartQuery(const QVector<QByteArray> &partList, bool
partQuery.addColumn(PimItem::idFullColumnName()); partQuery.addColumn(PimItem::idFullColumnName());
partQuery.addColumn(Part::partTypeIdFullColumnName()); partQuery.addColumn(Part::partTypeIdFullColumnName());
partQuery.addColumn(Part::dataFullColumnName()); partQuery.addColumn(Part::dataFullColumnName());
partQuery.addColumn(Part::externalFullColumnName()); partQuery.addColumn(Part::storageFullColumnName());
partQuery.addColumn(Part::versionFullColumnName()); partQuery.addColumn(Part::versionFullColumnName());
partQuery.addColumn(Part::datasizeFullColumnName()); partQuery.addColumn(Part::datasizeFullColumnName());
...@@ -575,7 +575,8 @@ bool FetchHelper::fetchItems() ...@@ -575,7 +575,8 @@ bool FetchHelper::fetchItems()
skipItem = true; skipItem = true;
break; break;
} }
metaPart.setIsExternal(partQuery.value(PartQueryExternalColumn).toBool()); metaPart.setStorageType(static_cast<Protocol::PartMetaData::StorageType>(
partQuery.value(PartQueryStorageColumn).toInt()));
if (data.isEmpty()) { if (data.isEmpty()) {
partData.setData(QByteArray("")); partData.setData(QByteArray(""));
} else { } else {
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<comment>Contains the schema version of the database.</comment> <comment>Contains the schema version of the database.</comment>
<column name="version" type="int" default="0" allowNull="false"/> <column name="version" type="int" default="0" allowNull="false"/>
<column name="generation" type="int" default="0" allowNull="false" /> <column name="generation" type="int" default="0" allowNull="false" />
<data columns="version" values="34"/> <data columns="version" values="35"/>
</table> </table>
<table name="Resource"> <table name="Resource">
...@@ -166,13 +166,17 @@ ...@@ -166,13 +166,17 @@
</table> </table>
<table name="Part"> <table name="Part">
<enum name="Storage">
<value name="Internal"/>
<value name="External"/>
</enum>
<column name="id" type="qint64" allowNull="false" isAutoIncrement="true" isPrimaryKey="true"/> <column name="id" type="qint64" allowNull="false" isAutoIncrement="true" isPrimaryKey="true"/>
<column name="pimItemId" type="qint64" refTable="PimItem" refColumn="id" allowNull="false"/> <column name="pimItemId" type="qint64" refTable="PimItem" refColumn="id" allowNull="false"/>
<column name="partTypeId" type="qint64" refTable="PartType" refColumn="id" allowNull="false" noUpdate="true" /> <column name="partTypeId" type="qint64" refTable="PartType" refColumn="id" allowNull="false" noUpdate="true" />
<column name="data" type="QByteArray"/> <column name="data" type="QByteArray"/>
<column name="datasize" type="qint64" allowNull="false"/> <column name="datasize" type="qint64" allowNull="false"/>
<column name="version" type="int" default="0"/> <column name="version" type="int" default="0"/>
<column name="external" type="bool" default="false" /> <column name="storage" type="enum" enumType="Part::Storage" default="Part::Internal"/>
<index name="pimItemIdTypeIndex" columns="pimItemId,partTypeId" unique="true"/> <index name="pimItemIdTypeIndex" columns="pimItemId,partTypeId" unique="true"/>
<index name="pimItemIdSortIndex" columns="pimItemId" unique="false" sort="DESC"/> <index name="pimItemIdSortIndex" columns="pimItemId" unique="false" sort="DESC"/>
</table> </table>
......
...@@ -790,7 +790,7 @@ bool DataStore::cleanupCollection(Collection &collection) ...@@ -790,7 +790,7 @@ bool DataStore::cleanupCollection(Collection &collection)
qb.addJoin(QueryBuilder::InnerJoin, PimItem::tableName(), Part::pimItemIdFullColumnName(), PimItem::idFullColumnName()); qb.addJoin(QueryBuilder::InnerJoin, PimItem::tableName(), Part::pimItemIdFullColumnName(), PimItem::idFullColumnName());
qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), PimItem::collectionIdFullColumnName(), Collection::idFullColumnName()); qb.addJoin(QueryBuilder::InnerJoin, Collection::tableName(), PimItem::collectionIdFullColumnName(), Collection::idFullColumnName());
qb.addValueCondition(Collection::idFullColumnName(), Query::Equals, collection.id()); qb.addValueCondition(Collection::idFullColumnName(), Query::Equals, collection.id());
qb.addValueCondition(Part::externalFullColumnName(), Query::Equals, true); qb.addValueCondition(Part::storageFullColumnName(), Query::Equals, Part::External);
qb.addValueCondition(Part::dataFullColumnName(), Query::IsNot, QVariant()); qb.addValueCondition(Part::dataFullColumnName(), Query::IsNot, QVariant());
if (!qb.exec()) { if (!qb.exec()) {
return false; return false;
......
...@@ -320,4 +320,9 @@ ...@@ -320,4 +320,9 @@
<raw-sql backends="psql">SELECT setval('tagtypetable_id_seq', (SELECT max(id) FROM TagTypeTable))</raw-sql> <raw-sql backends="psql">SELECT setval('tagtypetable_id_seq', (SELECT max(id) FROM TagTypeTable))</raw-sql>
<raw-sql backends="psql">SELECT setval('relationtypetable_id_seq', (SELECT max(id) FROM RelationTypeTable))</raw-sql> <raw-sql backends="psql">SELECT setval('relationtypetable_id_seq', (SELECT max(id) FROM RelationTypeTable))</raw-sql>
</update> </update>
<update version="35" abortOnFailure="true">
<raw-sql backends="mysql,psql,sqlite">UPDATE PartTable SET storage = external;</raw-sql>
<raw-sql backends="mysql,psql,sqlite">ALTER TABLE PartTable DROP COLUMN external;</raw-sql>
</update>
</updates> </updates>
...@@ -398,7 +398,7 @@ void ItemRetriever::verifyCache() ...@@ -398,7 +398,7 @@ void ItemRetriever::verifyCache()
SelectQueryBuilder<Part> qb; SelectQueryBuilder<Part> qb;
qb.addJoin(QueryBuilder::InnerJoin, PimItem::tableName(), Part::pimItemIdFullColumnName(), PimItem::idFullColumnName()); qb.addJoin(QueryBuilder::InnerJoin, PimItem::tableName(), Part::pimItemIdFullColumnName(), PimItem::idFullColumnName());
qb.addValueCondition(Part::externalFullColumnName(), Query::Equals, true); qb.addValueCondition(Part::storageFullColumnName(), Query::Equals, Part::External);
qb.addValueCondition(Part::dataFullColumnName(), Query::IsNot, QVariant()); qb.addValueCondition(Part::dataFullColumnName(), Query::IsNot, QVariant());
if (mScope.scope() != Scope::Invalid) { if (mScope.scope() != Scope::Invalid) {
ItemQueryHelper::scopeToQuery(mScope, mConnection->context(), qb); ItemQueryHelper::scopeToQuery(mScope, mConnection->context(), qb);
......
...@@ -42,24 +42,24 @@ void PartHelper::update(Part *part, const QByteArray &data, qint64 dataSize) ...@@ -42,24 +42,24 @@ void PartHelper::update(Part *part, const QByteArray &data, qint64 dataSize)
const bool storeExternal = dataSize > DbConfig::configuredDatabase()->sizeThreshold(); const bool storeExternal = dataSize > DbConfig::configuredDatabase()->sizeThreshold();
QByteArray newFile; QByteArray newFile;
if (part->external() && storeExternal) { if (part->storage() == Part::External && storeExternal) {
if (!ExternalPartStorage::self()->updatePartFile(data, part->data(), newFile)) { if (!ExternalPartStorage::self()->updatePartFile(data, part->data(), newFile)) {
throw PartHelperException(QStringLiteral("Failed to update external payload part")); throw PartHelperException(QStringLiteral("Failed to update external payload part"));
} }
part->setData(newFile); part->setData(newFile);