From d05f9f046565f2d0d4135912103f96f0e66b454f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Sep 2015 15:12:32 +0200 Subject: Add initial database model --- bpkg/database.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'bpkg/database.cxx') 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 // unique_ptr #include // move() +#include #include #include @@ -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) -- cgit v1.1