aboutsummaryrefslogtreecommitdiff
path: root/odb/schema-catalog.hxx
blob: 07e625b13aeba0727d84feb2e8451bfe187d202a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// file      : odb/schema-catalog.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef ODB_SCHEMA_CATALOG_HXX
#define ODB_SCHEMA_CATALOG_HXX

#include <odb/pre.hxx>

#include <string>

#include <odb/forward.hxx> // schema_version, odb::core

#include <odb/details/export.hxx>

namespace odb
{
  class LIBODB_EXPORT schema_catalog
  {
  public:
    // Schema creation.
    //
    static void
    create_schema (database&, const std::string& name = "", bool drop = true);

    static void
    drop_schema (database&, const std::string& name = "");

    // Schema migration.
    //
    static void
    migrate_schema_pre (database& db,
                        schema_version v,
                        const std::string& name = "")
    {
      migrate_schema_impl (db, v, name, migrate_pre);
    }

    static void
    migrate_schema_post (database& db,
                         schema_version v,
                         const std::string& name = "")
    {
      migrate_schema_impl (db, v, name, migrate_post);
    }

    static void
    migrate_schema (database& db,
                    schema_version v,
                    const std::string& name = "")
    {
      migrate_schema_impl (db, v, name, migrate_both);
    }

    // Migrate both schema and data to the specified version. If version
    // is not specified, then migrate to the latest version.
    //
    static void
    migrate (database& db, schema_version v = 0, const std::string& name = "");

    // Return 0 if current is greater or equal to the latest version.
    // If current is not specified, get the current version from the
    // database.
    //
    static schema_version
    next_version (const database& db,
                  schema_version current = 0,
                  const std::string& name = "")
    {
      return next_version (db.id (),
                           current == 0 ? db.schema_version () : current,
                           name);
    }

    static schema_version
    next_version (database_id,
                  schema_version current,
                  const std::string& name = "");

    static schema_version
    latest_version (const database& db, const std::string& name = "")
    {
      return latest_version (db.id (), name);
    }

    static schema_version
    latest_version (database_id, const std::string& name = "");

    // Test for presence of a schema with a specific name.
    //
    static bool
    exists (const database& db, const std::string& name = "")
    {
      return exists (db.id (), name);
    }

    static bool
    exists (database_id, const std::string& name = "");

  private:
    enum migrate_mode
    {
      migrate_pre,
      migrate_post,
      migrate_both
    };

    static void
    migrate_schema_impl (database&,
                         schema_version,
                         const std::string& name,
                         migrate_mode);
  };

  namespace common
  {
    using odb::schema_catalog;
  }
}

#include <odb/post.hxx>

#endif // ODB_SCHEMA_CATALOG_HXX