aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-05-03 11:03:54 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-05-03 23:02:22 +0300
commit804e2976f8f7e94d9174640ec125f819cef6e7aa (patch)
treea12fda594275fece2905fd408731a46721a5f418
parentda39700745c4cd5f6dede3c3a522c0068ce094d8 (diff)
-rw-r--r--bpkg/database.cxx15
-rw-r--r--bpkg/package.hxx40
-rw-r--r--bpkg/package.xml6
3 files changed, 58 insertions, 3 deletions
diff --git a/bpkg/database.cxx b/bpkg/database.cxx
index e50c63e..5374b92 100644
--- a/bpkg/database.cxx
+++ b/bpkg/database.cxx
@@ -46,12 +46,23 @@ namespace bpkg
{
// Add the unnamed self configuration of the target type.
//
- shared_ptr<configuration> sc (
- make_shared<configuration> (optional<string> (), "target"));
+ shared_ptr<configuration8> sc (
+ make_shared<configuration8> (optional<string> (), "target"));
db.persist (sc);
});
+ static const migration_entry<10>
+ migrate_v10 ([] (odb::database& db)
+ {
+ for (shared_ptr<configuration> c:
+ pointer_result (db.query<configuration> ()))
+ {
+ c->nam = c->name;
+ db.update (c);
+ }
+ });
+
static inline path
cfg_path (const dir_path& d, bool create)
{
diff --git a/bpkg/package.hxx b/bpkg/package.hxx
index 48c684e..6ca162f 100644
--- a/bpkg/package.hxx
+++ b/bpkg/package.hxx
@@ -27,7 +27,7 @@
//
#define DB_SCHEMA_VERSION_BASE 6
-#pragma db model version(DB_SCHEMA_VERSION_BASE, 9, open)
+#pragma db model version(DB_SCHEMA_VERSION_BASE, 10, open)
namespace bpkg
{
@@ -155,6 +155,8 @@ namespace bpkg
//
dir_path path;
+ optional<string> nam;
+
// Database mapping.
//
#pragma db member(id) id auto
@@ -182,6 +184,42 @@ namespace bpkg
configuration () = default;
};
+ // @@ TMP Is only required for migration from the schema version 8.
+ //
+ #pragma db object table("configuration") pointer(shared_ptr) session
+ class configuration8
+ {
+ public:
+ // Zero for the self configuration and is auto-assigned for associated
+ // configurations when the object is persisted.
+ //
+ optional<uint64_t> id;
+
+ optional<string> name;
+ string type;
+
+ // Is empty only for the self configuration.
+ //
+ dir_path path;
+
+ // Database mapping.
+ //
+ #pragma db member(id) id auto
+ #pragma db member(path) unique
+
+ public:
+ // Create the self configuration.
+ //
+ configuration8 (optional<string> n, string t)
+ : id (0),
+ name (move (n)),
+ type (move (t)) {}
+
+ private:
+ friend class odb::access;
+ configuration8 () = default;
+ };
+
// Verify that a string is a valid configuration name, that is non-empty,
// containing only alpha-numeric characters, '_', '-' (except for the first
// character which can only be alphabetic or '_'). Issue diagnostics and
diff --git a/bpkg/package.xml b/bpkg/package.xml
index 42d91e2..f008dd7 100644
--- a/bpkg/package.xml
+++ b/bpkg/package.xml
@@ -1,4 +1,10 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="sqlite" version="1">
+ <changeset version="10">
+ <alter-table name="main.configuration">
+ <add-column name="nam" type="TEXT" null="true"/>
+ </alter-table>
+ </changeset>
+
<changeset version="9">
<add-table name="main.configuration" kind="object">
<column name="id" type="INTEGER" null="true"/>