| 100 | } |
| 101 | |
| 102 | static void loadDatabase( |
| 103 | ContextMutablePtr context, |
| 104 | const String & database, |
| 105 | const fs::path & metadata_file_path, |
| 106 | bool force_restore_data) |
| 107 | { |
| 108 | /// If it is already loaded. |
| 109 | if (DatabaseCatalog::instance().isDatabaseExist(database)) |
| 110 | return; |
| 111 | |
| 112 | String database_attach_query; |
| 113 | |
| 114 | auto default_db_disk = Context::getGlobalContextInstance()->getDatabaseDisk(); |
| 115 | if (default_db_disk->existsFile(metadata_file_path)) |
| 116 | { |
| 117 | /// There is .sql file with database creation statement. |
| 118 | database_attach_query = readMetadataFile(default_db_disk, metadata_file_path); |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | /// It's first server run and we need create default and system databases. |
| 123 | /// .sql file with database engine will be written for CREATE query. |
| 124 | database_attach_query = "CREATE DATABASE " + backQuoteIfNeed(database); |
| 125 | } |
| 126 | |
| 127 | try |
| 128 | { |
| 129 | executeCreateQuery(database_attach_query, context, database, metadata_file_path, /* create */ true, force_restore_data); |
| 130 | } |
| 131 | catch (Exception & e) |
| 132 | { |
| 133 | e.addMessage(fmt::format("while loading database {} from file {}", backQuote(database), metadata_file_path)); |
| 134 | throw; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | static void checkUnsupportedVersion(ContextMutablePtr, const String & database_name) |
| 139 | { |
no test coverage detected