~raj-abhilash1/mailman/sqlalchemy

« back to all changes in this revision

Viewing changes to src/mailman/commands/cli_migrate.py

  • Committer: Abhilash Raj
  • Date: 2014-10-02 14:46:00 UTC
  • mfrom: (7251.1.16 abhilash)
  • Revision ID: raj.abhilash1@gmail.com-20141002144600-szesk2tnsq4tbxce
Merge barry\'s branch with test fixes and clean code

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
__metaclass__ = type
23
23
__all__ = [
24
24
    'Migrate',
25
 
]
 
25
    ]
 
26
 
26
27
 
27
28
from alembic import command
28
29
from alembic.config import Config
31
32
from mailman.config import config
32
33
from mailman.core.i18n import _
33
34
from mailman.interfaces.command import ICLISubCommand
 
35
from mailman.utilities.modules import expand_path
 
36
 
34
37
 
35
38
 
36
39
@implementer(ICLISubCommand)
37
40
class Migrate:
38
 
    """Migrate the mailman database to the schema."""
 
41
    """Migrate the Mailman database to the latest schema."""
39
42
 
40
43
    name = 'migrate'
41
44
 
43
46
        """See `ICLISubCommand`."""
44
47
        command_parser.add_argument(
45
48
            '-a', '--autogenerate',
46
 
            action="store_true", help=_("""\
47
 
            Autogenerate the migration script using alembic"""))
48
 
        pass
 
49
            action='store_true', help=_("""\
 
50
            Autogenerate the migration script using Alembic."""))
 
51
        command_parser.add_argument(
 
52
            '-q', '--quiet',
 
53
            action='store_true', default=False,
 
54
            help=('Produce less output.'))
49
55
 
50
56
    def process(self, args):
51
 
        alembic_cfg= Config()
 
57
        alembic_cfg = Config()
52
58
        alembic_cfg.set_main_option(
53
 
            "script_location", config.alembic['script_location'])
 
59
            'script_location', expand_path(config.database['alembic_scripts']))
54
60
        if args.autogenerate:
55
61
            command.revision(alembic_cfg, autogenerate=True)
56
62
        else:
57
 
            command.upgrade(alembic_cfg, "head")
58
 
            print("Updated the database schema.")
 
63
            command.upgrade(alembic_cfg, 'head')
 
64
            if not args.quiet:
 
65
                print('Updated the database schema.')