PackageUpdateTrackingTable.h (2173B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "Microsoft/Schema/ISQLiteIndex.h" 5 #include <winget/SQLiteWrapper.h> 6 7 8 namespace AppInstaller::Repository::Microsoft::Schema::V2_0 9 { 10 // Table for tracking the updates to the internal table so that prepare can output 11 // only the necessary package manifests. 12 struct PackageUpdateTrackingTable 13 { 14 // Get the table name. 15 static std::string_view TableName(); 16 17 // Creates the table. 18 static void Create(SQLite::Connection& connection); 19 20 // Creates the table if it does not exist. 21 static void EnsureExists(SQLite::Connection& connection); 22 23 // Drops the table. 24 static void Drop(SQLite::Connection& connection); 25 26 // Determine if the table currently exists in the database. 27 static bool Exists(const SQLite::Connection& connection); 28 29 // Updates the tracking table for the given package identifier in the internal index. 30 static void Update(SQLite::Connection& connection, const ISQLiteIndex* internalIndex, const std::string& packageIdentifier, bool ensureTable = true); 31 32 // Checks the consistency of the index to ensure that every referenced row exists. 33 // Returns true if index is consistent; false if it is not. 34 static bool CheckConsistency(const SQLite::Connection& connection, ISQLiteIndex* internalIndex, bool log); 35 36 // Data on a single row in the table. 37 struct PackageData 38 { 39 SQLite::rowid_t RowID = 0; 40 std::string PackageIdentifier; 41 int64_t WriteTime = 0; 42 SQLite::blob_t Manifest; 43 SQLite::blob_t Hash; 44 }; 45 46 // Gets the data on updates that have been written since the given base time. 47 static std::vector<PackageData> GetUpdatesSince(const SQLite::Connection& connection, int64_t updateBaseTime); 48 49 // Gets the data hash for the given package identifier. 50 static SQLite::blob_t GetDataHash(const SQLite::Connection& connection, const std::string& packageIdentifier); 51 }; 52 }