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 #include "sqlite_single_ver_database_upgrader.h"
17 #include "db_errno.h"
18 #include "log_print.h"
19 #include "version.h"
20 #include "db_constant.h"
21 #include "platform_specific.h"
22 #include "param_check_utils.h"
23 #include "res_finalizer.h"
24 #include "runtime_context.h"
25 #include "sqlite_single_ver_storage_executor_sql.h"
26 
27 namespace DistributedDB {
28 namespace {
29     const constexpr char *CREATE_LOCAL_TABLE_SQL =
30         "CREATE TABLE IF NOT EXISTS local_data(" \
31             "key BLOB PRIMARY KEY," \
32             "value BLOB," \
33             "timestamp INT," \
34             "hash_key BLOB);";
35 
36     const constexpr char *CREATE_SYNC_TABLE_SQL =
37         "CREATE TABLE IF NOT EXISTS sync_data(" \
38             "key         BLOB NOT NULL," \
39             "value       BLOB," \
40             "timestamp   INT  NOT NULL," \
41             "flag        INT  NOT NULL," \
42             "device      BLOB," \
43             "ori_device  BLOB," \
44             "hash_key    BLOB PRIMARY KEY NOT NULL," \
45             "w_timestamp INT," \
46             "modify_time INT DEFAULT 0," \
47             "create_time INT DEFAULT 0" \
48             ");";
49 
50     const constexpr char *CREATE_META_TABLE_SQL =
51         "CREATE TABLE IF NOT EXISTS meta_data("  \
52             "key    BLOB PRIMARY KEY  NOT NULL," \
53             "value  BLOB);";
54 
55     const constexpr char *CREATE_SINGLE_META_TABLE_SQL =
56         "CREATE TABLE IF NOT EXISTS meta.meta_data("  \
57             "key    BLOB PRIMARY KEY  NOT NULL," \
58             "value  BLOB);";
59 
60     const constexpr char *CREATE_SYNC_TABLE_INDEX_SQL_KEY_INDEX =
61         "CREATE INDEX IF NOT EXISTS key_index ON sync_data (key, flag);";
62 
63     const constexpr char *CREATE_SYNC_TABLE_INDEX_SQL_TIME_INDEX =
64         "CREATE INDEX IF NOT EXISTS time_index ON sync_data (timestamp);";
65 
66     const constexpr char *CREATE_SYNC_TABLE_INDEX_SQL_DEV_INDEX =
67         "CREATE INDEX IF NOT EXISTS dev_index ON sync_data (device);";
68 
69     const constexpr char *CREATE_SYNC_TABLE_INDEX_SQL_LOCAL_HASHKEY_INDEX =
70         "CREATE INDEX IF NOT EXISTS local_hashkey_index ON local_data (hash_key);";
71 
72     const constexpr char *DROP_META_TABLE_SQL = "DROP TABLE IF EXISTS main.meta_data;";
73     const constexpr char *COPY_META_TABLE_SQL = "INSERT OR REPLACE INTO meta.meta_data SELECT * FROM meta_data "
74         "where (SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='main.meta_data') > 0;";
75 
76     const constexpr char *DROP_META_DB_TABLE_SQL = "DROP TABLE IF EXISTS meta.meta_data;";
77     const constexpr char *COPY_META_DB_TABLE_SQL = "INSERT OR REPLACE INTO meta_data SELECT * FROM meta.meta_data "
78         "where (SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='meta.meta_data') > 0;";
79 }
80 
SQLiteSingleVerDatabaseUpgrader(sqlite3 * db,const SecurityOption & secopt,bool isMemDb)81 SQLiteSingleVerDatabaseUpgrader::SQLiteSingleVerDatabaseUpgrader(sqlite3 *db,
82     const SecurityOption &secopt, bool isMemDb)
83     : db_(db),
84       secOpt_(secopt),
85       isMemDB_(isMemDb),
86       isMetaUpgrade_(false),
87       isMigrateMetaDb_(false)
88 {
89 }
90 
~SQLiteSingleVerDatabaseUpgrader()91 SQLiteSingleVerDatabaseUpgrader::~SQLiteSingleVerDatabaseUpgrader()
92 {
93     db_ = nullptr;
94 }
95 
TransferDatabasePath(const std::string & parentDir,const OpenDbProperties & option)96 int SQLiteSingleVerDatabaseUpgrader::TransferDatabasePath(const std::string &parentDir,
97     const OpenDbProperties &option)
98 {
99     std::string dbFilePath = parentDir + "/" + DBConstant::SINGLE_VER_DATA_STORE + DBConstant::DB_EXTENSION;
100     std::string upgradeLockFile = parentDir + "/" + DBConstant::UPGRADE_POSTFIX;
101 
102     if (OS::CheckPathExistence(upgradeLockFile)) {
103         return MoveDatabaseToNewDir(parentDir, upgradeLockFile);
104     }
105     if (OS::CheckPathExistence(dbFilePath)) {
106         int currentVersion = 0;
107         int errCode = GetDbVersion(dbFilePath, option, currentVersion);
108         if (errCode != E_OK) {
109             LOGE("[SQLiteSinVerUp] Get version of old database failed");
110             return errCode;
111         }
112         if (currentVersion == 0) {
113             LOGI("The database file has not been initialized, maybe invalid database");
114             if (OS::RemoveFile(dbFilePath) != E_OK) {
115                 LOGE("[SQLiteSinVerUp] Remove the uninitialized database failed, errno[%d]", errno);
116                 return -E_SYSTEM_API_FAIL;
117             }
118         }
119         if (currentVersion >= SINGLE_VER_STORE_VERSION_V1 && currentVersion <= SINGLE_VER_STORE_VERSION_V2) {
120             LOGI("[SQLiteSinVerUp] Old version[%d] database exists.", currentVersion);
121             if (OS::CreateFileByFileName(upgradeLockFile) != E_OK) {
122                 return -E_SYSTEM_API_FAIL;
123             }
124             return MoveDatabaseToNewDir(parentDir, upgradeLockFile);
125         }
126     }
127     return E_OK;
128 }
129 
BeginUpgrade()130 int SQLiteSingleVerDatabaseUpgrader::BeginUpgrade()
131 {
132     return SQLiteUtils::BeginTransaction(db_, TransactType::IMMEDIATE);
133 }
134 
EndUpgrade(bool isSuccess)135 int SQLiteSingleVerDatabaseUpgrader::EndUpgrade(bool isSuccess)
136 {
137     if (isSuccess) {
138         return SQLiteUtils::CommitTransaction(db_);
139     } else {
140         int errCode = SQLiteUtils::RollbackTransaction(db_);
141         std::string secOptUpgradeFile = subDir_ + "/" + DBConstant::SET_SECOPT_POSTFIX;
142         if (errCode == E_OK && OS::CheckPathExistence(secOptUpgradeFile) &&
143             (OS::RemoveFile(secOptUpgradeFile) != E_OK)) {
144             LOGW("[EndUpgrade] Delete secure upgrade file failed");
145             return -E_SYSTEM_API_FAIL;
146         }
147         return errCode;
148     }
149 }
150 
GetDatabaseVersion(int & version) const151 int SQLiteSingleVerDatabaseUpgrader::GetDatabaseVersion(int &version) const
152 {
153     return SQLiteUtils::GetVersion(db_, version);
154 }
155 
SetDatabaseVersion(int version)156 int SQLiteSingleVerDatabaseUpgrader::SetDatabaseVersion(int version)
157 {
158     return SQLiteUtils::SetUserVer(db_, version);
159 }
160 
SetUpgradeSqls(int version,std::vector<std::string> & sqls,bool & isCreateUpgradeFile) const161 void SQLiteSingleVerDatabaseUpgrader::SetUpgradeSqls(int version, std::vector<std::string> &sqls,
162     bool &isCreateUpgradeFile) const
163 {
164     if (version == 0) { // no write version.
165         SetCreateSql(sqls);
166     } else {
167         if (version <= SINGLE_VER_STORE_VERSION_V1) {
168             sqls = {
169                 "DROP INDEX key_index;",
170                 "CREATE INDEX IF NOT EXISTS key_index ON sync_data (key, flag);",
171                 "ALTER TABLE sync_data ADD w_timestamp INT;",
172                 "UPDATE sync_data SET w_timestamp=timestamp;",
173                 "ALTER TABLE local_data ADD timestamp INT;",
174                 "ALTER TABLE local_data ADD hash_key BLOB;",
175                 "UPDATE local_data SET hash_key=calc_hash_key(key), timestamp=0;",
176                 "CREATE INDEX IF NOT EXISTS local_hashkey_index ON local_data (hash_key);"
177             };
178         }
179         if ((version <= SINGLE_VER_STORE_VERSION_V2 && ParamCheckUtils::IsS3SECEOpt(secOpt_)) ||
180             (version >= SINGLE_VER_STORE_VERSION_V3 && isMetaUpgrade_)) {
181             sqls.emplace_back(CREATE_SINGLE_META_TABLE_SQL);
182             sqls.emplace_back(COPY_META_TABLE_SQL);
183             sqls.emplace_back(DROP_META_TABLE_SQL);
184             isCreateUpgradeFile = true;
185         }
186         if (version < SINGLE_VER_STORE_VERSION_V4) {
187             sqls.emplace_back("ALTER TABLE sync_data ADD modify_time INT DEFAULT 0");
188             sqls.emplace_back("ALTER TABLE sync_data ADD create_time INT DEFAULT 0");
189         }
190         if (isMigrateMetaDb_) {
191             sqls.emplace_back(CREATE_META_TABLE_SQL);
192         }
193     }
194 }
195 
UpgradeFromDatabaseVersion(int version)196 int SQLiteSingleVerDatabaseUpgrader::UpgradeFromDatabaseVersion(int version)
197 {
198     std::vector<std::string> sqls;
199     bool isCreateUpgradeFile = false;
200     LOGI("[SqlSingleUp] metaSplit[%d], secLabel[%d], secFlag[%d], version[%d]",
201         isMetaUpgrade_, secOpt_.securityLabel, secOpt_.securityFlag, version);
202     SetUpgradeSqls(version, sqls, isCreateUpgradeFile);
203     for (const auto &item : sqls) {
204         int errCode = SQLiteUtils::ExecuteRawSQL(db_, item);
205         if (errCode != E_OK) {
206             LOGE("[SqlSingleUp][UpFrom] Execute upgrade sql failed:%d", errCode);
207             return errCode;
208         }
209     }
210     InitTimeForUpgrade(version);
211     if (isMigrateMetaDb_) {
212         MigrateMetaFromMetaDB();
213     }
214     if (isCreateUpgradeFile) {
215         std::string secOptUpgradeFile = subDir_ + "/" + DBConstant::SET_SECOPT_POSTFIX;
216         if (!OS::CheckPathExistence(secOptUpgradeFile) && (OS::CreateFileByFileName(secOptUpgradeFile) != E_OK)) {
217             LOGE("[SqlSingleUp][UpFrom] Create s3sece flag file failed");
218             return -E_SYSTEM_API_FAIL;
219         }
220         LOGD("[SqlSingleUp][UpFrom] Create s3sece mark file success");
221     }
222     return E_OK;
223 }
224 
GetDbVersion(const std::string & dbPath,const OpenDbProperties & option,int & version)225 int SQLiteSingleVerDatabaseUpgrader::GetDbVersion(const std::string &dbPath, const OpenDbProperties &option,
226     int &version)
227 {
228     OpenDbProperties optionTmp(option);
229     optionTmp.uri = dbPath;
230     sqlite3 *db = nullptr;
231     int errCode = SQLiteUtils::OpenDatabase(optionTmp, db);
232     if (errCode != E_OK) {
233         return errCode;
234     }
235     errCode = SQLiteUtils::GetVersion(db, version);
236     (void)sqlite3_close_v2(db);
237     db = nullptr;
238     return errCode;
239 }
240 
SetMetaUpgrade(const SecurityOption & currentOpt,const SecurityOption & expectOpt,const std::string & subDir)241 void SQLiteSingleVerDatabaseUpgrader::SetMetaUpgrade(const SecurityOption &currentOpt,
242     const SecurityOption &expectOpt, const std::string &subDir)
243 {
244     std::string secOptUpgradeFile = subDir + "/" + DBConstant::SET_SECOPT_POSTFIX;
245     // the same version should upgrade while user open db with s3sece.
246     bool isCurrentS3SECE = ParamCheckUtils::IsS3SECEOpt(currentOpt);
247     bool isOpenS3SECE = ParamCheckUtils::IsS3SECEOpt(expectOpt);
248     if ((!OS::CheckPathExistence(secOptUpgradeFile)) && isOpenS3SECE) {
249         isMetaUpgrade_ = true;
250         bool isMetaExist = false;
251         int errCode = SQLiteUtils::CheckTableExists(db_, "meta_data", isMetaExist, true);
252         if (errCode != E_OK) {
253             LOGW("[SqlSingleUp] Check meta.meta_data failed %d", errCode);
254         }
255         // only create meta.meta_data if not exist
256         isMetaUpgrade_ = !isMetaExist;
257     } else {
258         isMetaUpgrade_ = false;
259     }
260     if (isCurrentS3SECE && !isOpenS3SECE) {
261         isMigrateMetaDb_ = true;
262     } else {
263         isMigrateMetaDb_ = false;
264     }
265 }
266 
SetSubdir(const std::string & subDir)267 void SQLiteSingleVerDatabaseUpgrader::SetSubdir(const std::string &subDir)
268 {
269     subDir_ = subDir;
270 }
271 
SetPathSecOptWithCheck(const std::string & path,const SecurityOption & secOption,const std::string & dbStore,bool isWithChecked)272 int SQLiteSingleVerDatabaseUpgrader::SetPathSecOptWithCheck(const std::string &path, const SecurityOption &secOption,
273     const std::string &dbStore, bool isWithChecked)
274 {
275     SecurityOption dbOpt;
276     std::vector<std::string> dbFilePathVec {DBConstant::DB_EXTENSION};
277     std::string dbFilePath = path + "/" + dbStore + DBConstant::DB_EXTENSION;
278     if (OS::CheckPathExistence(dbFilePath) && isWithChecked) {
279         int errCode = RuntimeContext::GetInstance()->GetSecurityOption(dbFilePath, dbOpt);
280         if (errCode != E_OK) {
281             LOGE("[SetPathSecOptWithCheck] GetSecurityOption failed:%d", errCode);
282             if (errCode == -E_NOT_SUPPORT) {
283                 dbOpt = SecurityOption();
284             } else {
285                 return errCode;
286             }
287         }
288     }
289 
290     for (const auto &item : dbFilePathVec) {
291         std::string dbItemFilePath = path + "/" + dbStore + item;
292         if (!OS::CheckPathExistence(dbItemFilePath)) {
293             continue;
294         }
295         int errCode = RuntimeContext::GetInstance()->SetSecurityOption(dbItemFilePath, secOption);
296         if (errCode != E_OK) {
297             LOGE("[SetPathSecOptWithCheck] SetSecurityOption failed.");
298             return errCode;
299         }
300     }
301     return E_OK;
302 }
303 
SetSecOption(const std::string & path,const SecurityOption & secOption,bool isWithChecked)304 int SQLiteSingleVerDatabaseUpgrader::SetSecOption(const std::string &path, const SecurityOption &secOption,
305     bool isWithChecked)
306 {
307     if (!ParamCheckUtils::CheckSecOption(secOption)) {
308         return -E_INVALID_ARGS;
309     }
310     if (secOption.securityLabel == NOT_SET) {
311         return E_OK;
312     }
313     std::string secOptUpgradeFile = path + "/" + DBConstant::SET_SECOPT_POSTFIX;
314     if (OS::CheckPathExistence(secOptUpgradeFile) && !ParamCheckUtils::IsS3SECEOpt(secOption)) {
315         LOGE("[SingleVerUp][SetSec] Security option is invalid");
316         return -E_INVALID_ARGS;
317     }
318     int errCode = E_OK;
319     if (secOption.securityLabel != NOT_SET) {
320         std::string mainDbPath = path + "/" + DBConstant::MAINDB_DIR;
321         std::string cacheDbPath = path + "/" + DBConstant::CACHEDB_DIR;
322         std::string metaDbPath = path + "/" + DBConstant::METADB_DIR;
323         errCode = SetPathSecOptWithCheck(mainDbPath, secOption, DBConstant::SINGLE_VER_DATA_STORE, isWithChecked);
324         if (errCode != E_OK) {
325             return errCode;
326         }
327         errCode = SetPathSecOptWithCheck(cacheDbPath, secOption, DBConstant::SINGLE_VER_CACHE_STORE, isWithChecked);
328         if (errCode != E_OK) {
329             LOGE("[SQLiteSingleVerDatabaseUpgrader] cacheDb SetSecurityOption failed.");
330             return errCode;
331         }
332         SecurityOption metaSecOpt;
333         metaSecOpt.securityLabel = ((secOption.securityLabel >= SecurityLabel::S2) ?
334             SecurityLabel::S2 : secOption.securityLabel);
335         errCode = SetPathSecOptWithCheck(metaDbPath, metaSecOpt, DBConstant::SINGLE_VER_META_STORE, false);
336         if (errCode != E_OK) {
337             LOGE("[SQLiteSingleVerDatabaseUpgrader] metaDb SetSecurityOption failed.");
338             return errCode;
339         }
340     }
341     if (OS::CheckPathExistence(secOptUpgradeFile) && (OS::RemoveFile(secOptUpgradeFile) != E_OK)) {
342         return -E_SYSTEM_API_FAIL;
343     }
344 
345     return errCode;
346 }
347 
MoveDatabaseToNewDir(const std::string & parentDir,const std::string & upgradeLockFile)348 int SQLiteSingleVerDatabaseUpgrader::MoveDatabaseToNewDir(const std::string &parentDir,
349     const std::string &upgradeLockFile)
350 {
351     std::vector<std::string> dbFilePathVec {DBConstant::DB_EXTENSION, ".db-wal", ".db-shm"};
352     for (const auto &item : dbFilePathVec) {
353         std::string oldDbPath = parentDir + "/" + DBConstant::SINGLE_VER_DATA_STORE + item;
354         std::string currentDbPath = parentDir + "/" + DBConstant::MAINDB_DIR + "/" +
355             DBConstant::SINGLE_VER_DATA_STORE + item;
356         if (OS::CheckPathExistence(oldDbPath)) {
357             if (OS::RenameFilePath(oldDbPath, currentDbPath) != E_OK) {
358                 LOGE("[SQLiteSinVerUp] Move database file to the new directory failed, errno:%d", errno);
359                 return -E_SYSTEM_API_FAIL;
360             }
361         }
362     }
363     int errCode = OS::RemoveFile(upgradeLockFile);
364     if (errCode != E_OK) {
365         LOGE("[SQLiteSinVerUp] Remove upgrade flag file failed, errno:%d", errno);
366     }
367     return errCode;
368 }
369 
IsValueNeedUpgrade() const370 bool SQLiteSingleVerDatabaseUpgrader::IsValueNeedUpgrade() const
371 {
372     return valueNeedUpgrade_;
373 }
374 
InitTimeForUpgrade(int version)375 void SQLiteSingleVerDatabaseUpgrader::InitTimeForUpgrade(int version)
376 {
377     if (version >= SINGLE_VER_STORE_VERSION_V4) {
378         return;
379     }
380     auto [errCode, offset] = GetLocalTimeOffset();
381     if (errCode != E_OK) {
382         // init time failed should not block upgrade
383         return;
384     }
385     UpgradeTime(offset);
386 }
387 
GetLocalTimeOffset()388 std::pair<int, TimeOffset> SQLiteSingleVerDatabaseUpgrader::GetLocalTimeOffset()
389 {
390     std::pair<int, TimeOffset> res;
391     auto &[errCode, offset] = res;
392     sqlite3_stmt *stmt = nullptr;
393     errCode = SQLiteUtils::GetStatement(db_, SELECT_META_VALUE_SQL, stmt);
394     if (errCode != E_OK) {
395         LOGW("[SQLiteSinVerUp] Prepare get meta data failed %d", errCode);
396         return res;
397     }
398     ResFinalizer finalizer([stmt]() {
399         int ret = E_OK;
400         sqlite3_stmt *sqlite3Stmt = stmt;
401         SQLiteUtils::ResetStatement(sqlite3Stmt, true, ret);
402         if (ret != E_OK) {
403             LOGW("[SQLiteSinVerUp] Finalize select stmt failed %d", ret);
404         }
405     });
406     const std::string_view localTimeOffset = DBConstant::LOCALTIME_OFFSET_KEY;
407     Key key(localTimeOffset.begin(), localTimeOffset.end());
408     errCode = SQLiteUtils::BindBlobToStatement(stmt, 1, key); // 1 is time offset
409     if (errCode != E_OK) {
410         LOGW("[SQLiteSinVerUp] Bind localTimeOffset failed %d", errCode);
411         return res;
412     }
413     errCode = SQLiteUtils::StepWithRetry(stmt, isMemDB_);
414     if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) {
415         errCode = -E_NOT_FOUND;
416     } else if (errCode != SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) {
417         LOGW("[SQLiteSinVerUp] Get meta data failed %d", errCode);
418         return res;
419     }
420     Value value;
421     errCode = SQLiteUtils::GetColumnBlobValue(stmt, 0, value);
422     if (errCode != E_OK) {
423         LOGW("[SQLiteSinVerUp] Get blob local offset failed %d", errCode);
424         return res;
425     }
426     offset = std::strtoll(std::string(value.begin(), value.end()).c_str(), nullptr, DBConstant::STR_TO_LL_BY_DEVALUE);
427     return res;
428 }
429 
UpgradeTime(TimeOffset offset)430 void SQLiteSingleVerDatabaseUpgrader::UpgradeTime(TimeOffset offset)
431 {
432     std::string addOffset;
433     if (offset < 0) {
434         addOffset = "+";
435     } else {
436         addOffset = "-";
437     }
438     addOffset += std::to_string(std::abs(offset));
439     std::string updateSQL = "UPDATE sync_data SET modify_time=timestamp" + addOffset + ", create_time=w_timestamp" +
440         addOffset + " WHERE modify_time = 0";
441     int errCode = SQLiteUtils::ExecuteRawSQL(db_, updateSQL);
442     if (errCode != E_OK) {
443         LOGE("[SQLiteSinVerUp] Upgrade time failed %d", errCode);
444     }
445 }
446 
MigrateMetaFromMetaDB()447 void SQLiteSingleVerDatabaseUpgrader::MigrateMetaFromMetaDB()
448 {
449     bool isCreate = false;
450     int errCode = SQLiteUtils::CheckTableExists(db_, "meta_data", isCreate, true);
451     if (errCode != E_OK || !isCreate) {
452         LOGW("[SQLiteSinVerUp] Check table in meta db errCode %d isCreate %d", errCode, static_cast<int>(isCreate));
453         return;
454     }
455     errCode = SQLiteUtils::ExecuteRawSQL(db_, COPY_META_DB_TABLE_SQL);
456     if (errCode != E_OK) {
457         LOGW("[SQLiteSinVerUp] Copy meta from meta db failed %d", errCode);
458         return;
459     }
460     errCode = SQLiteUtils::ExecuteRawSQL(db_, DROP_META_DB_TABLE_SQL);
461     if (errCode != E_OK) {
462         LOGW("[SQLiteSinVerUp] Drop meta in meta db failed %d", errCode);
463     } else {
464         LOGI("[SQLiteSinVerUp] Migrate meta from meta db success");
465     }
466 }
467 
SetCreateSql(std::vector<std::string> & sql) const468 void SQLiteSingleVerDatabaseUpgrader::SetCreateSql(std::vector<std::string> &sql) const
469 {
470     if ((!isMemDB_) && ParamCheckUtils::IsS3SECEOpt(secOpt_)) {
471         sql = {
472             CREATE_LOCAL_TABLE_SQL,
473             CREATE_SINGLE_META_TABLE_SQL,
474             CREATE_SYNC_TABLE_SQL,
475             CREATE_SYNC_TABLE_INDEX_SQL_KEY_INDEX,
476             CREATE_SYNC_TABLE_INDEX_SQL_TIME_INDEX,
477             CREATE_SYNC_TABLE_INDEX_SQL_DEV_INDEX,
478             CREATE_SYNC_TABLE_INDEX_SQL_LOCAL_HASHKEY_INDEX
479         };
480     } else {
481         sql = {
482             CREATE_LOCAL_TABLE_SQL,
483             CREATE_META_TABLE_SQL,
484             CREATE_SYNC_TABLE_SQL,
485             CREATE_SYNC_TABLE_INDEX_SQL_KEY_INDEX,
486             CREATE_SYNC_TABLE_INDEX_SQL_TIME_INDEX,
487             CREATE_SYNC_TABLE_INDEX_SQL_DEV_INDEX,
488             CREATE_SYNC_TABLE_INDEX_SQL_LOCAL_HASHKEY_INDEX
489         };
490     }
491 }
492 } // namespace DistributedDB
493