# # # patch "database.cc" # from [46f9560d1d3de02eb2e7dfa0275b7b0e256721a6] # to [b3e5c5859ebb6dd165ce8bf52d98908b6d737ede] # # patch "schema.sql" # from [2ce5689c47a0528abceb3813f431fb94b89e62ca] # to [83bbd8274486f892916f6b82b665c1b28fb670b5] # # patch "schema_migration.cc" # from [b09bce5e9684764dc58c0897b82ae416531472f2] # to [a15f0fb822c1ec4c500e1f12d279bf62931e2a16] # ============================================================ --- database.cc 46f9560d1d3de02eb2e7dfa0275b7b0e256721a6 +++ database.cc b3e5c5859ebb6dd165ce8bf52d98908b6d737ede @@ -72,7 +72,7 @@ // non-alphabetic ordering of tables in sql source files. we could create // a temporary db, write our intended schema into it, and read it back, // but this seems like it would be too rude. possibly revisit this issue. - schema("acf96bb0bd230523fe5fa7621864fa252c3cf11c"), + schema("d19b106aaabbf31c89420a27224766eab10b6783"), __sql(NULL), transaction_level(0) {} @@ -847,16 +847,8 @@ // consistency check data rdata_unpacked; - if (table=="files") - { gzip rdata(res[0][0]); - decode_gzip(rdata,rdata_unpacked); - } - else - { - base64 > rdata(res[0][0]); - unpack(rdata, rdata_unpacked); - } - + gzip rdata(res[0][0]); + decode_gzip(rdata,rdata_unpacked); hexenc tid; calculate_ident(rdata_unpacked, tid); I(tid == ident); @@ -877,15 +869,8 @@ fetch(res, one_col, one_row, query.c_str(), ident().c_str(), base().c_str()); - if (table=="file_deltas") - { gzip del_packed(res[0][0]); - decode_gzip(del_packed, del); - } - else - { - base64 > del_packed = res[0][0]; - unpack(del_packed, del); - } + gzip del_packed(res[0][0]); + decode_gzip(del_packed, del); } void @@ -901,25 +886,14 @@ MM(tid); I(tid == ident); - if (table=="files") - { - gzip dat_packed; - encode_gzip(dat, dat_packed); - - string insert = "INSERT INTO " + table + " VALUES(?, ?)"; - std::vector args; - args.push_back(ident()); - args.push_back(dat_packed()); - execute(insert,args); - } - else - { - base64 > dat_packed; - pack(dat, dat_packed); + gzip dat_packed; + encode_gzip(dat, dat_packed); string insert = "INSERT INTO " + table + " VALUES(?, ?)"; - execute(insert.c_str(),ident().c_str(), dat_packed().c_str()); - } + std::vector args; + args.push_back(ident()); + args.push_back(dat_packed()); + execute(insert,args); } void database::put_delta(hexenc const & ident, @@ -931,26 +905,15 @@ I(ident() != ""); I(base() != ""); - if (table=="file_deltas") - { - gzip del_packed; - encode_gzip(del, del_packed); + gzip del_packed; + encode_gzip(del, del_packed); - std::vector args; - args.push_back(ident()); - args.push_back(base()); - args.push_back(del_packed()); - string insert = "INSERT INTO "+table+" VALUES(?, ?, ?)"; - execute(insert, args); - } - else - { - base64 > del_packed; - pack(del, del_packed); - + std::vector args; + args.push_back(ident()); + args.push_back(base()); + args.push_back(del_packed()); string insert = "INSERT INTO "+table+" VALUES(?, ?, ?)"; - execute(insert.c_str(), ident().c_str(), base().c_str(), del_packed().c_str()); - } + execute(insert, args); } // static ticker cache_hits("vcache hits", "h", 1); ============================================================ --- schema.sql 2ce5689c47a0528abceb3813f431fb94b89e62ca +++ schema.sql 83bbd8274486f892916f6b82b665c1b28fb670b5 @@ -36,14 +36,14 @@ CREATE TABLE manifests ( id primary key, -- strong hash of all the entries in a manifest - data not null -- compressed, encoded contents of a manifest + data not null -- compressed 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 manifest.id or manifest_deltas.id - delta not null, -- rdiff to construct current from base + delta not null, -- compressed rdiff to construct current from base unique(id, base) ); ============================================================ --- schema_migration.cc b09bce5e9684764dc58c0897b82ae416531472f2 +++ schema_migration.cc a15f0fb822c1ec4c500e1f12d279bf62931e2a16 @@ -944,6 +944,82 @@ 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) +{ + int res; +// app->db.install_functions(app); + I(sqlite3_create_function(sql, "unbase64", -1, + SQLITE_UTF8, NULL, + &sqlite3_unbase64_fn, + NULL, NULL) == 0); + + // 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 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) { @@ -975,9 +1051,12 @@ m.add("bd86f9a90b5d552f0be1fa9aee847ea0f317778b", &migrate_files_BLOB); + m.add("acf96bb0bd230523fe5fa7621864fa252c3cf11c", + &migrate_manifests_BLOB); + // IMPORTANT: whenever you modify this to add a new schema version, you must // also add a new migration test for the new schema version. See // tests/t_migrate_schema.at for details. - m.migrate(sql, "acf96bb0bd230523fe5fa7621864fa252c3cf11c"); + m.migrate(sql, "d19b106aaabbf31c89420a27224766eab10b6783"); }