diff --git a/src/rgw/driver/sfs/sqlite/dbconn.cc b/src/rgw/driver/sfs/sqlite/dbconn.cc index 1b43023cba9d7..4c8fe0d05fc11 100644 --- a/src/rgw/driver/sfs/sqlite/dbconn.cc +++ b/src/rgw/driver/sfs/sqlite/dbconn.cc @@ -355,6 +355,30 @@ static int upgrade_metadata_from_v2(sqlite3* db, std::string* errmsg) { return 0; } +static int upgrade_metadata_from_v4(sqlite3* db, std::string* errmsg) { + auto rc = sqlite3_exec( + db, + fmt::format( + "ALTER TABLE {} ADD COLUMN mtime INTEGER NOT NULL DEFAULT 0", + BUCKETS_TABLE + ) + .c_str(), + nullptr, nullptr, nullptr + ); + + if (rc != SQLITE_OK) { + if (errmsg != nullptr) { + *errmsg = fmt::format( + "Error creating column 'mtime' in table '{}': {}", BUCKETS_TABLE, + sqlite3_errmsg(db) + ); + } + return -1; + } + + return 0; +} + static void upgrade_metadata( CephContext* cct, StorageRef storage, sqlite3* db ) { @@ -372,6 +396,8 @@ static void upgrade_metadata( rc = upgrade_metadata_from_v1(db, &errmsg); } else if (cur_version == 2) { rc = upgrade_metadata_from_v2(db, &errmsg); + } else if (cur_version == 4) { + rc = upgrade_metadata_from_v4(db, &errmsg); } if (rc < 0) { diff --git a/src/rgw/driver/sfs/sqlite/dbconn.h b/src/rgw/driver/sfs/sqlite/dbconn.h index 715b11bb70e3b..75fcfba8cf592 100644 --- a/src/rgw/driver/sfs/sqlite/dbconn.h +++ b/src/rgw/driver/sfs/sqlite/dbconn.h @@ -37,7 +37,7 @@ namespace rgw::sal::sfs::sqlite { /// current db version. -constexpr int SFS_METADATA_VERSION = 4; +constexpr int SFS_METADATA_VERSION = 5; /// minimum required version to upgrade db. constexpr int SFS_METADATA_MIN_VERSION = 4; @@ -139,7 +139,9 @@ inline auto _make_storage(const std::string& path) { sqlite_orm::make_column("deleted", &DBBucket::deleted), sqlite_orm::make_column("bucket_attrs", &DBBucket::bucket_attrs), sqlite_orm::make_column("object_lock", &DBBucket::object_lock), - sqlite_orm::make_column("mtime", &DBBucket::mtime), + sqlite_orm::make_column( + "mtime", &DBBucket::mtime, sqlite_orm::default_value(0) + ), sqlite_orm::foreign_key(&DBBucket::owner_id) .references(&DBUser::user_id) ),