1 # Copyright (C) 2015 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Test database schema migrations with Alembic"""
26 import alembic
.command
27 import sqlalchemy
as sa
29 from mailman
.config
import config
30 from mailman
.database
.alembic
import alembic_cfg
31 from mailman
.database
.model
import Model
32 from mailman
.testing
.layers
import ConfigLayer
36 class TestMigrations(unittest
.TestCase
):
40 alembic
.command
.stamp(alembic_cfg
, 'head')
43 # Drop and restore a virgin database.
44 md
= sa
.MetaData(bind
=config
.db
.engine
)
47 Model
.metadata
.create_all(config
.db
.engine
)
49 def test_all_migrations(self
):
50 script_dir
= alembic
.script
.ScriptDirectory
.from_config(alembic_cfg
)
51 revisions
= [sc
.revision
for sc
in
52 script_dir
.walk_revisions('base', 'heads')]
53 for revision
in revisions
:
54 alembic
.command
.downgrade(alembic_cfg
, revision
)
56 for revision
in revisions
:
57 alembic
.command
.upgrade(alembic_cfg
, revision
)