diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-06-12 22:02:08 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-06-15 15:41:40 +0300 |
commit | 299f9682a4a2df434d0e61e73780fd2555afa1b8 (patch) | |
tree | e78e7ef6deaa16fe6ce35a77a3d3afdf1a35bcf2 /bpkg | |
parent | 02ada52a38576331f58744ffa83d9cbba6b53827 (diff) |
Default version epoch to one
Diffstat (limited to 'bpkg')
-rw-r--r-- | bpkg/database.cxx | 46 | ||||
-rw-r--r-- | bpkg/package.hxx | 6 | ||||
-rw-r--r-- | bpkg/package.xml | 2 |
3 files changed, 53 insertions, 1 deletions
diff --git a/bpkg/database.cxx b/bpkg/database.cxx index 3c55237..7d0e2ac 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -44,6 +44,52 @@ namespace bpkg } }; + // Register the data migration functions. + // + template <odb::schema_version v> + using migration_entry = odb::data_migration_entry<v, DB_SCHEMA_VERSION_BASE>; + + // Migrate tables that contain package version columns converting the + // default zero version epoch to one, unless the version is a stub. + // + // Note that we can't really distinguish the default zero epoch from an + // explicitly specified one, so will just update all of them, assuming that + // it is currently unlikely that the epoch was specified explicitly for any + // package version. + // + static const migration_entry<5> + migrate_epoch_entry ([] (odb::database& db) + { + // Delay the foreign key constraint checks until we are done with all the + // tables. + // + assert (transaction::has_current ()); + db.execute ("PRAGMA defer_foreign_keys = ON"); + + auto update = [&db] (const string& table, + const string& version_prefix = "version") + { + string ec (version_prefix + "_epoch"); + + db.execute ("UPDATE " + table + " SET " + ec + " = 1 " + + "WHERE " + ec + " = 0 AND NOT (" + + version_prefix + "_canonical_upstream = '' AND " + + version_prefix + "_canonical_release = '~')"); + }; + + update ("available_package"); + update ("available_package_locations"); + update ("available_package_dependencies"); + update ("available_package_dependency_alternatives"); + update ("available_package_dependency_alternatives", "dep_min_version"); + update ("available_package_dependency_alternatives", "dep_max_version"); + update ("selected_package"); + update ("selected_package_prerequisites", "min_version"); + update ("selected_package_prerequisites", "max_version"); + + db.execute ("PRAGMA defer_foreign_keys = OFF"); + }); + database open (const dir_path& d, tracer& tr, bool create) { diff --git a/bpkg/package.hxx b/bpkg/package.hxx index 185059f..ab0d144 100644 --- a/bpkg/package.hxx +++ b/bpkg/package.hxx @@ -24,7 +24,11 @@ #include <bpkg/diagnostics.hxx> -#pragma db model version(4, 4, closed) +// Used by the data migration entries. +// +#define DB_SCHEMA_VERSION_BASE 4 + +#pragma db model version(DB_SCHEMA_VERSION_BASE, 5, open) namespace bpkg { diff --git a/bpkg/package.xml b/bpkg/package.xml index 2b7ac59..0cb00c1 100644 --- a/bpkg/package.xml +++ b/bpkg/package.xml @@ -1,4 +1,6 @@ <changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="sqlite" version="1"> + <changeset version="5"/> + <model version="4"> <table name="repository_fragment" kind="object"> <column name="name" type="TEXT" null="true"/> |