From 3ee16754eb6c6d998faf5472627bc9e54cbc82cb Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Sun, 12 Dec 2021 14:00:35 -0800 Subject: [PATCH] Remove superfluous auto_key from ArchiveDef. --- engine/src/flutter/impeller/archivist/archivable.h | 1 - engine/src/flutter/impeller/archivist/archive.cc | 13 ++++--------- .../archivist/archive_class_registration.cc | 8 +------- .../impeller/archivist/archivist_unittests.cc | 1 - 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/impeller/archivist/archivable.h b/engine/src/flutter/impeller/archivist/archivable.h index 5018d5a16e..41c296301d 100644 --- a/engine/src/flutter/impeller/archivist/archivable.h +++ b/engine/src/flutter/impeller/archivist/archivable.h @@ -13,7 +13,6 @@ namespace impeller { struct ArchiveDef { const std::string table_name; - const bool auto_key = true; const std::vector members; }; diff --git a/engine/src/flutter/impeller/archivist/archive.cc b/engine/src/flutter/impeller/archivist/archive.cc index c10646e081..8cf81ddb65 100644 --- a/engine/src/flutter/impeller/archivist/archive.cc +++ b/engine/src/flutter/impeller/archivist/archive.cc @@ -53,12 +53,6 @@ std::optional Archive::ArchiveInstance( auto primary_key = archivable.GetPrimaryKey(); - if (!definition.auto_key && !primary_key.has_value()) { - VALIDATION_LOG << "Archive definition specified that primary keys will be " - "explicitly specified but none was provided when asked."; - return std::nullopt; - } - /* * The lifecycle of the archive item is tied to this scope and there is no * way for the user to create an instance of an archive item. So its safe @@ -68,9 +62,10 @@ std::optional Archive::ArchiveInstance( ArchiveLocation item(*this, statement, *registration, primary_key); /* - * We need to bind the primary key only if the item does not provide its own + * If the item provides its own primary key, we need to bind it now. + * Otherwise, one will be automatically assigned to it. */ - if (!definition.auto_key && + if (primary_key.has_value() && !statement.WriteValue(ArchiveClassRegistration::kPrimaryKeyIndex, primary_key.value())) { return std::nullopt; @@ -86,7 +81,7 @@ std::optional Archive::ArchiveInstance( int64_t lastInsert = database_->GetLastInsertRowID(); - if (!definition.auto_key && + if (primary_key.has_value() && lastInsert != static_cast(primary_key.value())) { return std::nullopt; } diff --git a/engine/src/flutter/impeller/archivist/archive_class_registration.cc b/engine/src/flutter/impeller/archivist/archive_class_registration.cc index 335f3acd0e..33b3695c61 100644 --- a/engine/src/flutter/impeller/archivist/archive_class_registration.cc +++ b/engine/src/flutter/impeller/archivist/archive_class_registration.cc @@ -60,13 +60,7 @@ bool ArchiveClassRegistration::CreateTable() { * a statement and check its validity before running. */ stream << "CREATE TABLE IF NOT EXISTS " << definition_.table_name << " (" - << kArchivePrimaryKeyColumnName; - - if (definition_.auto_key) { - stream << " INTEGER PRIMARY KEY AUTOINCREMENT, "; - } else { - stream << " INTEGER PRIMARY KEY, "; - } + << kArchivePrimaryKeyColumnName << " INTEGER PRIMARY KEY, "; for (size_t i = 0, columns = definition_.members.size(); i < columns; i++) { stream << definition_.members[i]; diff --git a/engine/src/flutter/impeller/archivist/archivist_unittests.cc b/engine/src/flutter/impeller/archivist/archivist_unittests.cc index fdf9608e45..d789034c3f 100644 --- a/engine/src/flutter/impeller/archivist/archivist_unittests.cc +++ b/engine/src/flutter/impeller/archivist/archivist_unittests.cc @@ -49,7 +49,6 @@ class Sample : public Archivable { const ArchiveDef Sample::kArchiveDefinition = { .table_name = "Sample", - .auto_key = false, .members = {"some_data"}, };