1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SQLITE_RELATIONAL_DATABASE_UPGRADER_H
17 #define SQLITE_RELATIONAL_DATABASE_UPGRADER_H
18 
19 #include "database_upgrader.h"
20 #include "sqlite_utils.h"
21 #include "types_export.h"
22 
23 namespace DistributedDB {
24 class SqliteRelationalDatabaseUpgrader : public DatabaseUpgrader {
25 public:
26     explicit SqliteRelationalDatabaseUpgrader(sqlite3 *db);
27     ~SqliteRelationalDatabaseUpgrader() override;
28     int Upgrade() override;
29 
30 private:
31     int BeginUpgrade();
32     int ExecuteUpgrade();
33     int EndUpgrade(bool isSuccess);
34 
35     bool IsNewestVersion(const std::string &logTableVersion);
36     int UpgradeTrigger(const std::string &logTableVersion, const RelationalSchemaObject &schemaObj,
37         const RelationalSchemaObject &trackerSchemaObj);
38     int UpgradeLogTable(const std::string &logTableVersion, const RelationalSchemaObject &schemaObj,
39         const RelationalSchemaObject &trackerSchemaObj);
40     int UpgradeLogBaseOnVersion(const std::string &oldVersion, const std::string &tableName);
41     int GetParseSchema(RelationalSchemaObject &schemaObj, RelationalSchemaObject &trackerSchemaObj);
42     sqlite3 *db_;
43 };
44 } // namespace DistributedDB
45 #endif // SQLITE_RELATIONAL_DATABASE_UPGRADER_H