Merge remote branch 'refs/remotes/gullydwarf-cfdv/is315'
[mediagoblin.git] / mediagoblin / gmg_commands / migrate.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18 from mediagoblin.db import migrations
19 from mediagoblin.gmg_commands import util as commands_util
20
21
22 def migrate_parser_setup(subparser):
23 subparser.add_argument(
24 '-cf', '--conf_file', default='mediagoblin.ini',
25 help="Config file used to set up environment")
26
27
28 def migrate(args):
29 mgoblin_app = commands_util.setup_app(args)
30 print "Applying migrations..."
31
32 for model_name in migrations.MIGRATE_CLASSES:
33 model = getattr(mgoblin_app.db, model_name)
34
35 if not hasattr(model, 'migration_handler') or not model.collection:
36 continue
37
38 migration = model.migration_handler(model)
39 migration.migrate_all(collection=model.collection)
40
41 print "... done."