diff options
Diffstat (limited to 'bpkg/database.cxx')
-rw-r--r-- | bpkg/database.cxx | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bpkg/database.cxx b/bpkg/database.cxx index 18bb5af..01488c6 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -7,6 +7,7 @@ #include <memory> // unique_ptr #include <utility> // move() +#include <odb/schema-catalog.hxx> #include <odb/sqlite/exceptions.hxx> #include <bpkg/types> @@ -17,6 +18,7 @@ using namespace std; namespace bpkg { using namespace odb::sqlite; + using odb::schema_catalog; database open (const dir_path& d, bool create) @@ -49,6 +51,26 @@ namespace bpkg t.commit (); } + if (create) + { + // Create the new schema. + // + if (db.schema_version () != 0) + fail << f << ": already has database schema"; + + transaction t (db.begin ()); + schema_catalog::create_schema (db); + t.commit (); + } + else + { + // Migrate the database if necessary. + // + transaction t (db.begin ()); + schema_catalog::migrate (db); + t.commit (); + } + return db; } catch (const database_exception& e) |