# # # patch "README.encapsulation" # from [dc81088d6bf35555821f076556a68dbdce3b15be] # to [58b2ac83ce87c1af2d19bb5becfd8fd29a869f00] # # patch "database.cc" # from [42b9871aa028701eced7a80ba678c4d96db992ec] # to [7b8fe9e102befb5254ab47915f4201e0c61b13c5] # # patch "schema_migration.cc" # from [4d94671c50a1e8412ab1982167317aac5c9bd581] # to [54c4a069756b8609e44b7e374dc9d04dbc3f91b1] # # patch "schema_migration.hh" # from [28378b9f52084c15026e2cd9cba011256cdec0ab] # to [c02720141fbd073e228691f9aa049a5a8309ded6] # ============================================================ --- README.encapsulation dc81088d6bf35555821f076556a68dbdce3b15be +++ README.encapsulation 58b2ac83ce87c1af2d19bb5becfd8fd29a869f00 @@ -1,24 +1,45 @@ database.cc: database.cc: - __app is a member variable of class database, it's needed for the - following functions: + __app is a member variable of class database, used by: - migrate_sql_schema() - test_migration_step() + normal member functions: + database::complete() + __app->require_workspace() + __app->opts.branchname + __app->get_project() - database::complete() - needs: __app->require_workspace() - needs: __app->opts.branchname + database::test_migration_step() + __app->keys + database::migrate() + __app->keys -schema_migration.cc: + accessor hacks: + __app->keys + get_key_store() - migrate_to_external_privkeys(): - needs the key_store + __app->lua ... + hook_exists() + hook_expand_selector() + hook_expand_date() + hook_get_manifest_cert_trust() + hook_get_revision_cert_trust() + hook_get_author() + hook_accept_testresult_change() - the migrator func (migrator_cb) also needs the app_state. + __app->get_project() + get_project() + __app->opts + must_drop_attr() + get_opt_author() + get_opt_ignore_suspend_certs() + get_opt_date_or_cur_date() + has_opt_branch() + get_opt_branchname() + set_opt_branchname() + netsync.cc: struct session: ============================================================ --- database.cc 42b9871aa028701eced7a80ba678c4d96db992ec +++ database.cc 7b8fe9e102befb5254ab47915f4201e0c61b13c5 @@ -679,14 +679,14 @@ database::migrate() database::migrate() { ensure_open_for_maintenance(); - migrate_sql_schema(__sql, *__app); + migrate_sql_schema(__sql, get_filename(), __app->keys); } void database::test_migration_step(string const & schema) { ensure_open_for_maintenance(); - ::test_migration_step(__sql, *__app, schema); + ::test_migration_step(__sql, get_filename(), __app->keys, schema); } void ============================================================ --- schema_migration.cc 4d94671c50a1e8412ab1982167317aac5c9bd581 +++ schema_migration.cc 54c4a069756b8609e44b7e374dc9d04dbc3f91b1 @@ -11,11 +11,11 @@ #include #include "lexical_cast.hh" #include "sqlite/sqlite3.h" -#include +#include #include "sanity.hh" #include "schema_migration.hh" -#include "app_state.hh" +#include "key_store.hh" #include "keys.hh" #include "transforms.hh" #include "ui.hh" @@ -304,7 +304,7 @@ sqlite3_unbase64_fn(sqlite3_context *f, // Here are all of the migration steps. Almost all of them can be expressed // entirely as a series of SQL statements; those statements are packaged -// into a long, continued string constant for the step. One step requires a +// into a long, continued string constant for the step. A few require a // function instead. char const migrate_merge_url_and_group[] = @@ -339,7 +339,6 @@ char const migrate_merge_url_and_group[] " SELECT (url || '/' || groupname), major, minor FROM tmp;" "DROP TABLE tmp;" - // migrate the netserver_manifests table "ALTER TABLE netserver_manifests RENAME TO tmp;" "CREATE TABLE netserver_manifests" @@ -484,13 +483,11 @@ char const migrate_add_indexes[] = ; // There is, perhaps, an argument for turning the logic inside the -// while-loop into a callback function like unbase64(). We would then not -// need a special case for this step in the master migration loop. However, -// we'd have to get the app_state in there somehow, we might in the future -// need to do other things that can't be easily expressed in pure SQL, and -// besides I think it's clearer this way. +// while-loop into a callback function like unbase64(). However, we'd have +// to get the key_store in there somehow, and besides I think it's clearer +// this way. static void -migrate_to_external_privkeys(sqlite3 * db, app_state &app) +migrate_to_external_privkeys(sqlite3 * db, key_store & keys) { { sql stmt(db, 3, @@ -504,7 +501,7 @@ migrate_to_external_privkeys(sqlite3 * d base64< arc4 > old_priv(stmt.column_string(1)); keypair kp; - migrate_private_key(app.keys, ident, old_priv, kp); + migrate_private_key(keys, ident, old_priv, kp); MM(kp.pub); if (stmt.column_nonnull(2)) @@ -515,8 +512,8 @@ migrate_to_external_privkeys(sqlite3 * d F("public and private keys for %s don't match") % ident); } P(F("moving key '%s' from database to %s") - % ident % app.keys.get_key_dir()); - app.keys.put_key_pair(ident, kp); + % ident % keys.get_key_dir()); + keys.put_key_pair(ident, kp); } } @@ -618,7 +615,7 @@ static void // this is a function because it has to refer to the numeric constant // defined in schema_migration.hh. static void -migrate_add_ccode(sqlite3 * db, app_state &) +migrate_add_ccode(sqlite3 * db, key_store &) { string cmd = "PRAGMA user_version = "; cmd += boost::lexical_cast(mtn_creator_code); @@ -648,7 +645,7 @@ dump(enum upgrade_regime const & regime, } } -typedef void (*migrator_cb)(sqlite3 *, app_state &); +typedef void (*migrator_cb)(sqlite3 *, key_store &); // Exactly one of migrator_sql and migrator_func should be non-null in // all entries in migration_events, except the very last. @@ -924,7 +921,8 @@ void } void -migrate_sql_schema(sqlite3 * db, app_state & app) +migrate_sql_schema(sqlite3 * db, system_path const & filename, + key_store & keys) { I(db != NULL); @@ -946,7 +944,7 @@ migrate_sql_schema(sqlite3 * db, app_sta m = find_migration(db); cat = classify_schema(db, m); - diagnose_unrecognized_schema(cat, app.db.get_filename()); + diagnose_unrecognized_schema(cat, filename); // We really want 'db migrate' on an up-to-date schema to be a no-op // (no vacuum or anything, even), so that automated scripts can fire @@ -975,7 +973,7 @@ migrate_sql_schema(sqlite3 * db, app_sta if (m->migrator_sql) sql::exec(db, m->migrator_sql); else if (m->migrator_func) - m->migrator_func(db, app); + m->migrator_func(db, keys); else break; @@ -1023,7 +1021,8 @@ void // conformance check will reject them). void -test_migration_step(sqlite3 * db, app_state & app, string const & schema) +test_migration_step(sqlite3 * db, system_path const & filename, + key_store & keys, string const & schema) { I(db != NULL); sql::create_function(db, "sha1", sqlite_sha1_fn); @@ -1044,12 +1043,12 @@ test_migration_step(sqlite3 * db, app_st F("schema %s is up to date") % schema); L(FL("testing migration from %s to %s\n in database %s") - % schema % m[1].id % app.db.get_filename()); + % schema % m[1].id % filename); if (m->migrator_sql) sql::exec(db, m->migrator_sql); else - m->migrator_func(db, app); + m->migrator_func(db, keys); // in the unlikely event that we get here ... P(F("successful migration to schema %s") % m[1].id); ============================================================ --- schema_migration.hh 28378b9f52084c15026e2cd9cba011256cdec0ab +++ schema_migration.hh c02720141fbd073e228691f9aa049a5a8309ded6 @@ -19,19 +19,20 @@ struct sqlite3; // of the migration. struct sqlite3; -class app_state; +class key_store; class system_path; -void migrate_sql_schema(sqlite3 * db, app_state & app); +std::string describe_sql_schema(sqlite3 * db); void check_sql_schema(sqlite3 * db, system_path const & filename); -std::string describe_sql_schema(sqlite3 * db); +void migrate_sql_schema(sqlite3 * db, system_path const & filename, + key_store & keys); // utility routine shared with database.cc void assert_sqlite3_ok(sqlite3 * db); // debugging -void test_migration_step(sqlite3 * db, app_state & app, - std::string const & schema); +void test_migration_step(sqlite3 * db, system_path const & filename, + key_store & keys, std::string const & schema); // this constant is part of the database schema, but it is not in schema.sql // because sqlite expressions can't do arithmetic on character values. it