diff options
Diffstat (limited to 'server/src/database.cppm')
| -rw-r--r-- | server/src/database.cppm | 27 |
1 files changed, 1 insertions, 26 deletions
diff --git a/server/src/database.cppm b/server/src/database.cppm index 86ed0d7..ff5cae4 100644 --- a/server/src/database.cppm +++ b/server/src/database.cppm | |||
| @@ -5,8 +5,6 @@ import :sqlite3; | |||
| 5 | 5 | ||
| 6 | namespace routemon::database { | 6 | namespace routemon::database { |
| 7 | 7 | ||
| 8 | static constexpr std::int64_t expected_database_version = 1; | ||
| 9 | |||
| 10 | export class connection | 8 | export class connection |
| 11 | { | 9 | { |
| 12 | sqlite3::connection dbc_; | 10 | sqlite3::connection dbc_; |
| @@ -19,29 +17,6 @@ public: | |||
| 19 | // Nothing here yet | 17 | // Nothing here yet |
| 20 | }; | 18 | }; |
| 21 | 19 | ||
| 22 | export auto open(std::string const& filename) -> std::shared_ptr<connection> | 20 | export auto open(std::string const& filename) -> std::shared_ptr<connection>; |
| 23 | { | ||
| 24 | auto dbc = sqlite3::open(filename); | ||
| 25 | try | ||
| 26 | { | ||
| 27 | auto version = std::optional<std::int64_t>{}; | ||
| 28 | dbc.query("SELECT version FROM migration;").scan_single(version); | ||
| 29 | if (!version) | ||
| 30 | throw std::runtime_error{"failed to fetch database migration version"}; | ||
| 31 | if (version != expected_database_version) | ||
| 32 | { | ||
| 33 | throw std::runtime_error{std::format( | ||
| 34 | "database migration version ({}) does not match expected " | ||
| 35 | "version ({}), consider running migrations", | ||
| 36 | *version, expected_database_version)}; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | catch (std::exception const& e) | ||
| 40 | { | ||
| 41 | throw std::runtime_error{std::format( | ||
| 42 | "failed to query database version: {}", e.what())}; | ||
| 43 | } | ||
| 44 | return std::shared_ptr<connection>{new connection{std::move(dbc)}}; | ||
| 45 | } | ||
| 46 | 21 | ||
| 47 | } // namespace routemon::database | 22 | } // namespace routemon::database |