Debian Codegraph @

oslo_db/sqlalchemy/migration_cli/ext_base.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import abc
14
15
16 class MigrationExtensionBase(metaclass=abc.ABCMeta):
17
18 # used to sort migration in logical order
19 order = 0
20
21 @property
22 def enabled(self):
23 """Used for availability verification of a plugin.
24
25 :rtype: bool
26 """
27 return False
28
29 @abc.abstractmethod
30 def upgrade(self, version):
31 """Used for upgrading database.
32
33 :param version: Desired database version
34 :type version: string
35 """
36
37 @abc.abstractmethod
38 def downgrade(self, version):
39 """Used for downgrading database.
40
41 :param version: Desired database version
42 :type version: string
43 """
44
45 @abc.abstractmethod
46 def version(self):
47 """Current database version.
48
49 :returns: Databse version
50 :rtype: string
51 """
52
53 def revision(self, *args, **kwargs):
54 """Used to generate migration script.
55
56 In migration engines that support this feature, it should generate
57 new migration script.
58
59 Accept arbitrary set of arguments.
60 """
61 raise NotImplementedError()
62
63 def stamp(self, *args, **kwargs):
64 """Stamps database based on plugin features.
65
66 Accept arbitrary set of arguments.
67 """
68 raise NotImplementedError()
69
70 def has_revision(self, rev_id):
71 """Checks whether the repo contains a revision
72
73 :param rev_id: Revision to check
74 :returns: Whether the revision is in the repo
75 :rtype: bool
76 """
77 raise NotImplementedError()
78
79 def __cmp__(self, other):
80 """Used for definition of plugin order.
81
82 :param other: MigrationExtensionBase instance
83 :rtype: bool
84 """
85 return self.order > other.order