|
12 | 12 | #include <Parsers/ASTSelectWithUnionQuery.h> |
13 | 13 | #include <Parsers/ParserCreateQuery.h> |
14 | 14 | #include <Parsers/parseQuery.h> |
| 15 | +#include <Storages/AlterCommands.h> |
15 | 16 | #include <Storages/ColumnsDescription.h> |
16 | 17 | #include <Storages/KeyDescription.h> |
17 | 18 | #include <Storages/StorageDictionary.h> |
@@ -42,6 +43,7 @@ namespace ErrorCodes |
42 | 43 | extern const int NOT_IMPLEMENTED; |
43 | 44 | extern const int LOGICAL_ERROR; |
44 | 45 | extern const int CANNOT_GET_CREATE_TABLE_QUERY; |
| 46 | + extern const int BAD_ARGUMENTS; |
45 | 47 | } |
46 | 48 | namespace |
47 | 49 | { |
@@ -324,6 +326,24 @@ void writeMetadataFile(std::shared_ptr<IDisk> db_disk, const String & file_path, |
324 | 326 | out.reset(); |
325 | 327 | } |
326 | 328 |
|
| 329 | +void updateDatabaseCommentWithMetadataFile(DatabasePtr db, const AlterCommand & command) |
| 330 | +{ |
| 331 | + if (!command.comment) |
| 332 | + throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unable to obtain database comment from query"); |
| 333 | + |
| 334 | + String old_database_comment = db->getDatabaseComment(); |
| 335 | + db->setDatabaseComment(command.comment.value()); |
| 336 | + |
| 337 | + try |
| 338 | + { |
| 339 | + DatabaseCatalog::instance().updateMetadataFile(db); |
| 340 | + } |
| 341 | + catch (...) |
| 342 | + { |
| 343 | + db->setDatabaseComment(old_database_comment); |
| 344 | + throw; |
| 345 | + } |
| 346 | +} |
327 | 347 |
|
328 | 348 | DatabaseWithOwnTablesBase::DatabaseWithOwnTablesBase(const String & name_, const String & logger, ContextPtr context_) |
329 | 349 | : IDatabase(name_), WithContext(context_->getGlobalContext()), db_disk(context_->getDatabaseDisk()), log(getLogger(logger)) |
|
0 commit comments