# # # patch "database.hh" # from [68384cf0f0833e964f6393158c27efee4091a5a2] # to [975f832260dea3305889570be3a89e602f7cec46] # # patch "schema.sql" # from [219e58ea3064650384b40af09be54c8cc2f8f5ec] # to [d811d7503305093359874d46f1142861657642c0] # # patch "schema_migration.cc" # from [7d23ee792e0a1d4fee826458f95159b710806519] # to [1354bd78efb75e321287e7f73b2a1b90805325e1] # ============================================================ --- database.hh 68384cf0f0833e964f6393158c27efee4091a5a2 +++ database.hh 975f832260dea3305889570be3a89e602f7cec46 @@ -97,7 +97,7 @@ typedef std::vector< std::vector > results; void execute(char const * query, ...); - + // structure to distinguish between blob and string arguments // in sqlite3 a blob never equals a string even when binary identical // so we need to remember which type to pass to the query ============================================================ --- schema.sql 219e58ea3064650384b40af09be54c8cc2f8f5ec +++ schema.sql d811d7503305093359874d46f1142861657642c0 @@ -36,14 +36,14 @@ CREATE TABLE manifests ( id primary key, -- strong hash of all the entries in a manifest - data not null -- compressed contents of a manifest + data not null -- compressed, encoded contents of a manifest ); CREATE TABLE manifest_deltas ( id not null, -- strong hash of all the entries in a manifest - base not null, -- joins with either manifests.id or manifest_deltas.id - delta not null, -- compressed rdiff to construct current from base + base not null, -- joins with either manifest.id or manifest_deltas.id + delta not null, -- rdiff to construct current from base unique(id, base) ); ============================================================ --- schema_migration.cc 7d23ee792e0a1d4fee826458f95159b710806519 +++ schema_migration.cc 1354bd78efb75e321287e7f73b2a1b90805325e1 @@ -857,23 +857,6 @@ return true; } -// I hate to duplicate this from database.cc but install_functions is private -// and gets called too late -#include - -static void -sqlite3_unbase64_fn(sqlite3_context *f, int nargs, sqlite3_value ** args) -{ - if (nargs != 1) - { - sqlite3_result_error(f, "need exactly 1 arg to unbase64()", -1); - return; - } - data decoded; - decode_base64(base64(string(sqlite3_value_text_s(args[0]))), decoded); - sqlite3_result_blob(f, decoded().c_str(), decoded().size(), SQLITE_TRANSIENT); -} - static bool migrate_client_to_add_rosters(sqlite3 * sql, char ** errmsg, @@ -925,6 +908,25 @@ return true; } +// I hate to duplicate this from database.cc but install_functions is private +// and gets called too late +#include + +static void +sqlite3_unbase64_fn(sqlite3_context *f, int nargs, sqlite3_value ** args) +{ + if (nargs != 1) + { + sqlite3_result_error(f, "need exactly 1 arg to unbase64()", -1); + return; + } + data decoded; + decode_base64(base64(string(sqlite3_value_text_s(args[0]))), decoded); + sqlite3_result_blob(f, decoded().c_str(), decoded().size(), SQLITE_TRANSIENT); +} + +// we could as well use the fact that uuencoded gzip starts with H4sI +// but we can not change comments on fields static bool migrate_files_BLOB(sqlite3 * sql, char ** errmsg, @@ -998,80 +1000,6 @@ return true; } -// we could as well use the fact that uuencoded gzip starts with H4sI -// but we can not change comments on fields -static bool -migrate_manifests_BLOB(sqlite3 * sql, - char ** errmsg, - app_state *app) -{ - if (!migrate_files_BLOB(sql,errmsg,app)) - return false; - - int res; - - // change the encoding of manifest(_delta)s - if (!move_table(sql, errmsg, - "manifests", - "tmp", - "(" - "id primary key," - "data not null" - ")")) - return false; - - res = logged_sqlite3_exec(sql, "CREATE TABLE manifests\n" - "(\n" - "id primary key, -- strong hash of all the entries in a manifest\n" - "data not null -- compressed contents of a manifest\n" - ")", NULL, NULL, errmsg); - if (res != SQLITE_OK) - return false; - - res = logged_sqlite3_exec(sql, "INSERT INTO manifests " - "SELECT id, unbase64(data) " - "FROM tmp", NULL, NULL, errmsg); - if (res != SQLITE_OK) - return false; - - res = logged_sqlite3_exec(sql, "DROP TABLE tmp", NULL, NULL, errmsg); - if (res != SQLITE_OK) - return false; - - if (!move_table(sql, errmsg, - "manifest_deltas", - "tmp", - "(" - "id not null," - "base not null," - "delta not null" - ")")) - return false; - - res = logged_sqlite3_exec(sql, "CREATE TABLE manifest_deltas\n" - "(\n" - "id not null, -- strong hash of all the entries in a manifest\n" - "base not null, -- joins with either manifests.id or manifest_deltas.id\n" - "delta not null, -- compressed rdiff to construct current from base\n" - "unique(id, base)\n" - ")", NULL, NULL, errmsg); - if (res != SQLITE_OK) - return false; - - res = logged_sqlite3_exec(sql, "INSERT INTO manifest_deltas " - "SELECT id, base, unbase64(delta) " - "FROM tmp", NULL, NULL, errmsg); - if (res != SQLITE_OK) - return false; - - res = logged_sqlite3_exec(sql, "DROP TABLE tmp", NULL, NULL, errmsg); - if (res != SQLITE_OK) - return false; - - // change comment - return true; -} - void migrate_monotone_schema(sqlite3 *sql, app_state *app) { @@ -1099,7 +1027,7 @@ m.add("1509fd75019aebef5ac3da3a5edf1312393b70e9", &migrate_client_to_external_privkeys); - + m.add("bd86f9a90b5d552f0be1fa9aee847ea0f317778b", &migrate_client_to_add_rosters);