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
124
|
from tests import clear_staging_env, staging_env, eq_, ne_, \
assert_raises_message
from alembic import util
def setup():
global env
env = staging_env()
global a, b, c, d, e
a = env.generate_revision(util.rev_id(), None, refresh=True)
b = env.generate_revision(util.rev_id(), None, refresh=True)
c = env.generate_revision(util.rev_id(), None, refresh=True)
d = env.generate_revision(util.rev_id(), None, refresh=True)
e = env.generate_revision(util.rev_id(), None, refresh=True)
def teardown():
clear_staging_env()
def test_upgrade_path():
eq_(
env._upgrade_revs(e.revision, c.revision),
[
(d.module.upgrade, c.revision, d.revision),
(e.module.upgrade, d.revision, e.revision),
]
)
eq_(
env._upgrade_revs(c.revision, None),
[
(a.module.upgrade, None, a.revision),
(b.module.upgrade, a.revision, b.revision),
(c.module.upgrade, b.revision, c.revision),
]
)
def test_relative_upgrade_path():
eq_(
env._upgrade_revs("+2", a.revision),
[
(b.module.upgrade, a.revision, b.revision),
(c.module.upgrade, b.revision, c.revision),
]
)
eq_(
env._upgrade_revs("+1", a.revision),
[
(b.module.upgrade, a.revision, b.revision),
]
)
eq_(
env._upgrade_revs("+3", b.revision),
[
(c.module.upgrade, b.revision, c.revision),
(d.module.upgrade, c.revision, d.revision),
(e.module.upgrade, d.revision, e.revision),
]
)
def test_invalid_relative_upgrade_path():
assert_raises_message(
util.CommandError,
"Relative revision -2 didn't produce 2 migrations",
env._upgrade_revs, "-2", b.revision
)
assert_raises_message(
util.CommandError,
r"Relative revision \+5 didn't produce 5 migrations",
env._upgrade_revs, "+5", b.revision
)
def test_downgrade_path():
eq_(
env._downgrade_revs(c.revision, e.revision),
[
(e.module.downgrade, e.revision, e.down_revision),
(d.module.downgrade, d.revision, d.down_revision),
]
)
eq_(
env._downgrade_revs(None, c.revision),
[
(c.module.downgrade, c.revision, c.down_revision),
(b.module.downgrade, b.revision, b.down_revision),
(a.module.downgrade, a.revision, a.down_revision),
]
)
def test_relative_downgrade_path():
eq_(
env._downgrade_revs("-1", c.revision),
[
(c.module.downgrade, c.revision, c.down_revision),
]
)
eq_(
env._downgrade_revs("-3", e.revision),
[
(e.module.downgrade, e.revision, e.down_revision),
(d.module.downgrade, d.revision, d.down_revision),
(c.module.downgrade, c.revision, c.down_revision),
]
)
def test_invalid_relative_downgrade_path():
assert_raises_message(
util.CommandError,
"Relative revision -5 didn't produce 5 migrations",
env._downgrade_revs, "-5", b.revision
)
assert_raises_message(
util.CommandError,
r"Relative revision \+2 didn't produce 2 migrations",
env._downgrade_revs, "+2", b.revision
)
|