SQLiteVersion.h (2341B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winget/SQLiteWrapper.h> 5 #include <memory> 6 7 namespace AppInstaller::SQLite 8 { 9 // Represents the schema version of the database. 10 struct Version 11 { 12 // The major version of the schema. 13 // All minor changes to this major version must be backward compatible. 14 uint32_t MajorVersion{}; 15 // The minor version of the schema. 16 // All changes to the schema warrant a change to the minor version. 17 uint32_t MinorVersion{}; 18 19 bool operator==(const Version& other) const 20 { 21 return (MajorVersion == other.MajorVersion && MinorVersion == other.MinorVersion); 22 } 23 24 bool operator!=(const Version& other) const 25 { 26 return !operator==(other); 27 } 28 29 bool operator>=(const Version& other) const 30 { 31 if (MajorVersion > other.MajorVersion) return true; 32 if (MajorVersion < other.MajorVersion) return false; 33 return MinorVersion >= other.MinorVersion; 34 } 35 36 bool operator<(const Version& other) const 37 { 38 if (MajorVersion < other.MajorVersion) return true; 39 if (MajorVersion > other.MajorVersion) return false; 40 return MinorVersion < other.MinorVersion; 41 } 42 43 // Gets a version that represents the latest schema known to the implementation. 44 static Version Latest(); 45 46 // Gets a version that represents the latest schema known to the implementation for the given major version. 47 static Version LatestForMajor(uint32_t majorVersion); 48 49 // Determines if this version represents the latest schema. 50 bool IsLatest() const; 51 52 // Determines if this version represents the latest schema of the given major version. 53 bool IsLatestForMajor(uint32_t majorVersion) const; 54 55 // Determines the schema version of the opened database. 56 static Version GetSchemaVersion(Connection& connection); 57 58 // Writes the current version to the given database. 59 void SetSchemaVersion(Connection& connection) const; 60 }; 61 62 // Output the version 63 std::ostream& operator<<(std::ostream& out, const Version& version); 64 }