1 /* 2 * Copyright (c) 2021 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 SINGLE_VER_SCHEMA_DATABASE_UPGRADER_H 17 #define SINGLE_VER_SCHEMA_DATABASE_UPGRADER_H 18 19 #include "schema_object.h" 20 #include "single_ver_database_upgrader.h" 21 22 namespace DistributedDB { 23 class SingleVerSchemaDatabaseUpgrader : virtual public SingleVerDatabaseUpgrader { 24 public: 25 // An invalid SchemaObject indicate no schema 26 explicit SingleVerSchemaDatabaseUpgrader(const SchemaObject &newSchema); ~SingleVerSchemaDatabaseUpgrader()27 ~SingleVerSchemaDatabaseUpgrader() override {}; 28 protected: 29 int ExecuteUpgrade() override; 30 31 // Database content related upgrade 32 int ExecuteUpgradeSchema(); 33 34 // Get an empty string with return_code E_OK indicate no schema but everything normally 35 virtual int GetDatabaseSchema(std::string &dbSchema) const = 0; 36 37 // Set or update schema into database file 38 virtual int SetDatabaseSchema(const std::string &dbSchema) = 0; 39 40 virtual int UpgradeValues() = 0; 41 virtual int UpgradeIndexes(const IndexDifference &indexDiffer) = 0; 42 43 SchemaObject newSchema_; 44 private: 45 int RestoreSchemaObjectFromDatabase(SchemaObject &outOriSchema) const; 46 }; 47 } // namespace DistributedDB 48 #endif // SINGLE_VER_SCHEMA_DATABASE_UPGRADER_H 49