# # # rename "tests/db_migrate_on_bad_schema" # to "tests/schema_migration_bad_schema" # # rename "tests/migrate_with_rosterify" # to "tests/schema_migration_with_rosterify" # # add_file "tests/schema_migration_bad_schema/bogus.dump" # content [43562c9df27f2728127fe973e3600d25f6a5b891] # # add_file "tests/schema_migration_bad_schema/empty.dump" # content [3dd764e9a24d150803b5bd517255c98e4a662d2e] # # add_file "tests/schema_migration_bad_schema/possible.dump" # content [99f9120eef90c5600b0afd4f85653b815b0ea4cb] # # patch "ChangeLog" # from [e661d96285a0c54c6dd981314e3728edb0687cf3] # to [a790280148e322a9c40687fc51664cbb4914d87f] # # patch "tests/schema_migration_bad_schema/__driver__.lua" # from [77d715318de6a775f5debf2bf394db959fa260e7] # to [b826f20824c4267fa9dcdcc18ecc8dd9d6ec2f34] # # patch "testsuite.lua" # from [6318f3eb4391d1121db27facd4821cf6c686d2bc] # to [5360e416548d4328291c3c6a19f86feffc6cdd0e] # ============================================================ --- tests/schema_migration_bad_schema/bogus.dump 43562c9df27f2728127fe973e3600d25f6a5b891 +++ tests/schema_migration_bad_schema/bogus.dump 43562c9df27f2728127fe973e3600d25f6a5b891 @@ -0,0 +1,3 @@ +BEGIN EXCLUSIVE; +CREATE TABLE foo (bar primary key, baz not null); +COMMIT; ============================================================ --- tests/schema_migration_bad_schema/empty.dump 3dd764e9a24d150803b5bd517255c98e4a662d2e +++ tests/schema_migration_bad_schema/empty.dump 3dd764e9a24d150803b5bd517255c98e4a662d2e @@ -0,0 +1,2 @@ +BEGIN EXCLUSIVE; +COMMIT; ============================================================ --- tests/schema_migration_bad_schema/possible.dump 99f9120eef90c5600b0afd4f85653b815b0ea4cb +++ tests/schema_migration_bad_schema/possible.dump 99f9120eef90c5600b0afd4f85653b815b0ea4cb @@ -0,0 +1,113 @@ +-- empty monotone database, with a vaguely plausible future table added +-- (skip_deltas). +BEGIN EXCLUSIVE; +CREATE TABLE branch_epochs + ( + hash not null unique, -- hash of remaining fields separated by ":" + branch not null unique, -- joins with revision_certs.value + epoch not null -- random hex-encoded id + ); +CREATE TABLE db_vars + ( + domain not null, -- scope of application of a var + name not null, -- var key + value not null, -- var value + unique(domain, name) + ); +CREATE TABLE file_deltas + ( + id not null, -- strong hash of file contents + base not null, -- joins with files.id or file_deltas.id + delta not null, -- compressed rdiff to construct current from base + unique(id, base) + ); +CREATE TABLE files + ( + id primary key, -- strong hash of file contents + data not null -- compressed contents of a file + ); +CREATE TABLE heights + ( + revision not null, -- joins with revisions.id + height not null, -- complex height, array of big endian u32 integers + unique(revision, height) + ); +CREATE TABLE manifest_certs + ( + hash not null unique, -- hash of remaining fields separated by ":" + id not null, -- joins with manifests.id or manifest_deltas.id + name not null, -- opaque string chosen by user + value not null, -- opaque blob + keypair not null, -- joins with public_keys.id + signature not null, -- RSA/SHA1 signature of "address@hidden:val]" + unique(name, id, value, keypair, signature) + ); +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 + unique(id, base) + ); +CREATE TABLE manifests + ( + id primary key, -- strong hash of all the entries in a manifest + data not null -- compressed, encoded contents of a manifest + ); +CREATE TABLE next_roster_node_number + ( + node primary key -- only one entry in this table, ever + ); +CREATE TABLE public_keys + ( + hash not null unique, -- hash of remaining fields separated by ":" + id primary key, -- key identifier chosen by user + keydata not null -- RSA public params + ); +CREATE TABLE revision_ancestry + ( + parent not null, -- joins with revisions.id + child not null, -- joins with revisions.id + unique(parent, child) + ); +CREATE TABLE revision_certs + ( + hash not null unique, -- hash of remaining fields separated by ":" + id not null, -- joins with revisions.id + name not null, -- opaque string chosen by user + value not null, -- opaque blob + keypair not null, -- joins with public_keys.id + signature not null, -- RSA/SHA1 signature of "address@hidden:val]" + unique(name, id, value, keypair, signature) + ); +CREATE TABLE revisions + ( + id primary key, -- SHA1(text of revision) + data not null -- compressed, encoded contents of a revision + ); +CREATE TABLE roster_deltas + ( + id primary key, -- a revision id + checksum not null, -- checksum of 'delta', to protect against disk corruption + base not null, -- joins with either rosters.id or roster_deltas.id + delta not null -- rdiff to construct current from base + ); +CREATE TABLE rosters + ( + id primary key, -- a revision id + checksum not null, -- checksum of 'data', to protect against disk corruption + data not null -- compressed, encoded contents of the roster + ); +CREATE TABLE skip_deltas + ( + id not null, -- strong hash of target file contents + base not null, -- joins with files.id + base_manifest not null, -- joins with manifests.id + target_manifest not null, -- joins with manifests.id + delta not null, -- rdiff to construct current from base + unique(id, base, base_manifest, target_manifest) + ); +CREATE INDEX revision_ancestry__child ON revision_ancestry (child); +CREATE INDEX revision_certs__id ON revision_certs (id); +CREATE INDEX revision_certs__name_value ON revision_certs (name, value); +COMMIT; ============================================================ --- ChangeLog e661d96285a0c54c6dd981314e3728edb0687cf3 +++ ChangeLog a790280148e322a9c40687fc51664cbb4914d87f @@ -1,5 +1,12 @@ 2007-01-09 Zack Weinberg + * tests/db_migrate_on_bad_schema: Rename to schema_migration_bad_schema. + Rewrite to test for specific error messages corresponding to the + five-way distinction made by check_sql_schema. + * tests/migrate_with_rosterify: Rename to + schema_migration_with_rosterify. + * testsuite.lua: Update. + * schema_migration.cc: Prune headers and using-declarations. Make various things static and/or wrapped in the anonymous namespace. (struct migrator): Delete. ============================================================ --- tests/schema_migration_bad_schema/__driver__.lua 77d715318de6a775f5debf2bf394db959fa260e7 +++ tests/schema_migration_bad_schema/__driver__.lua b826f20824c4267fa9dcdcc18ecc8dd9d6ec2f34 @@ -1,8 +1,20 @@ +-- This test exercises monotone's ability to identify random SQLite +-- databases which are not suitable for use by monotone. +-- check_sql_schema() makes a five-way distinction: usable, usable +-- with migration, possibly usable by some newer version but not this +-- one, not a monotone database at all, and utterly empty. Cases 1 and 2 +-- are tested elsewhere, so we just do 3-5. -mtn_setup() +function test_one(tag, expected_setup) + dump = tag .. ".dump" + db = tag .. ".mtn" + check(get(dump)) + check(raw_mtn("db", "load", "-d", db), 0, nil, nil, {dump}) -check(mtn("db", "migrate"), 0, false, false) + check(raw_mtn("setup", "-d", db, "-b", "foo", "subdir"), 1, nil, true) + check(qgrep(expected_setup, "stderr")) +end +test_one("possible", "monotone does not recognize its schema") +test_one("bogus", "does not appear to be a monotone database") +test_one("empty", "empty sqlite database") -check(mtn("db", "execute", 'CREATE TABLE foo (bar primary key, baz not null)'), 0, false, false) - -check(mtn("db", "migrate"), 1, false, false) ============================================================ --- testsuite.lua 6318f3eb4391d1121db27facd4821cf6c686d2bc +++ testsuite.lua 5360e416548d4328291c3c6a19f86feffc6cdd0e @@ -384,6 +384,8 @@ table.insert(tests, "schema_migration") table.insert(tests, "first_extent_normalization_pass") table.insert(tests, "(imp)_deleting_directories") table.insert(tests, "schema_migration") +table.insert(tests, "schema_migration_bad_schema") +table.insert(tests, "schema_migration_with_rosterify") table.insert(tests, "database_dump_load") table.insert(tests, "no-change_deltas_disappear") table.insert(tests, "merge((),_(drop_a,_rename_b_a,_patch_a))") @@ -565,7 +567,6 @@ table.insert(tests, "diff_--external") table.insert(tests, "diff_-rREV1_-rREV2_UNCHANGED-FILE") table.insert(tests, "b_t_and_a_selector_globbing") table.insert(tests, "diff_--external") -table.insert(tests, "db_migrate_on_bad_schema") table.insert(tests, "list_branches") table.insert(tests, "unnormalized_paths_in_database") table.insert(tests, "annotate_with_no_revs") @@ -597,7 +598,6 @@ table.insert(tests, "update_-b_switches_ table.insert(tests, "_--confdir_option_and_get_confdir_lua_function_work") table.insert(tests, "database_is_closed_on_signal_exit") table.insert(tests, "update_-b_switches_branches_even_when_noop") -table.insert(tests, "migrate_with_rosterify") table.insert(tests, "rosterify_migrates_file_dir_attrs") table.insert(tests, "db_rosterify_preserves_renames") table.insert(tests, "restrictions_when_pwd_is_mixed_case")