aboutsummaryrefslogtreecommitdiff
path: root/bpkg/database.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-14 15:12:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-14 15:12:32 +0200
commitd05f9f046565f2d0d4135912103f96f0e66b454f (patch)
tree750c05a010e886de83edc30282476cc36cc1c127 /bpkg/database.cxx
parentf9b9844eabe29250298f8120fa32a3b98c718454 (diff)
Add initial database model
Diffstat (limited to 'bpkg/database.cxx')
-rw-r--r--bpkg/database.cxx22
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)