monotone

monotone Mtn Source Tree

Root/src/migration.hh

1// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __MIGRATION_HH__
11#define __MIGRATION_HH__
12
13// this file knows how to migrate schema databases. the general strategy is
14// to hash each schema we ever use, and make a list of the SQL commands
15// required to get from one hash value to the next. when you do a
16// migration, the migrator locates your current db's state on the list and
17// then runs all the migration functions between that point and the target
18// of the migration.
19
20#include <set>
21
22struct sqlite3;
23class key_store;
24class database;
25class project_t;
26class system_path;
27
28std::string describe_sql_schema(sqlite3 * db);
29void check_sql_schema(sqlite3 * db, system_path const & filename);
30
31// if you add a new item here, don't forget to raise the
32// value of the "catch all" item "regen_all"
33enum regen_cache_type { regen_none = 0, regen_rosters = 1,
34 regen_heights = 2, regen_branches = 4,
35 regen_file_sizes = 8, regen_all = 15 };
36
37class migration_status {
38 regen_cache_type _regen_type;
39 std::string _flag_day_name;
40public:
41 migration_status() : _regen_type(regen_none), _flag_day_name("") {}
42 explicit migration_status(regen_cache_type type, std::string flag_day_name = "")
43 : _regen_type(type),
44 _flag_day_name(flag_day_name)
45 {}
46 bool need_regen() const { return _regen_type != regen_none; }
47 bool need_flag_day() const { return !_flag_day_name.empty(); }
48 std::string flag_day_name() const { return _flag_day_name; }
49 regen_cache_type regen_type() const { return _regen_type; }
50};
51migration_status migrate_sql_schema(sqlite3 * db, key_store & keys,
52 system_path const & filename);
53
54// utility routine shared with database.cc
55void assert_sqlite3_ok(sqlite3 * db);
56
57// debugging
58void test_migration_step(sqlite3 * db, key_store & keys,
59 system_path const & filename,
60 std::string const & schema);
61
62// this constant is part of the database schema, but it is not in schema.sql
63// because sqlite expressions can't do arithmetic on character values. it
64// is stored in the "user version" field of the database header. when we
65// encounter a database whose schema hash we don't recognize, we look for
66// this code in the header to decide whether it's a monotone database or
67// some other sqlite3 database. the expectation is that it will never need
68// to change. we call it a creator code because it has the same format and
69// function as file creator codes in old-sk00l Mac OS.
70
71const unsigned int mtn_creator_code = ((('_'*256 + 'M')*256 + 'T')*256 + 'N');
72
73
74
75// migrations of ancestry format and so on
76
77void
78build_changesets_from_manifest_ancestry(database & db, key_store & keys,
79 project_t & project,
80 std::set<std::string> const & attrs_to_drop);
81
82void
83build_roster_style_revs_from_manifest_style_revs(database & db, key_store & keys,
84 project_t & project,
85 std::set<std::string> const & attrs_to_drop);
86
87
88void
89regenerate_caches(database & db, regen_cache_type type);
90
91
92#endif // __MIGRATION__
93
94// Local Variables:
95// mode: C++
96// fill-column: 76
97// c-file-style: "gnu"
98// indent-tabs-mode: nil
99// End:
100// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status