1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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.
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.
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/>.
18 from mediagoblin
.db
import migrations
19 from mediagoblin
.db
import util
as db_util
20 from mediagoblin
.gmg_commands
import util
as commands_util
23 def migrate_parser_setup(subparser
):
24 subparser
.add_argument(
25 '-cf', '--conf_file', default
='mediagoblin.ini',
26 help="Config file used to set up environment")
30 mgoblin_app
= commands_util
.setup_app(args
)
33 print "== Clearing old indexes... =="
34 removed_indexes
= db_util
.remove_deprecated_indexes(mgoblin_app
.db
)
36 for collection
, index_name
in removed_indexes
:
37 print "Removed index '%s' in collection '%s'" % (
38 index_name
, collection
)
41 print "== Applying migrations... =="
42 for model_name
in migrations
.MIGRATE_CLASSES
:
43 model
= getattr(mgoblin_app
.db
, model_name
)
45 if not hasattr(model
, 'migration_handler') or not model
.collection
:
48 migration
= model
.migration_handler(model
)
49 migration
.migrate_all(collection
=model
.collection
)
52 print "== Adding new indexes... =="
53 new_indexes
= db_util
.add_new_indexes(mgoblin_app
.db
)
55 for collection
, index_name
in new_indexes
:
56 print "Added index '%s' to collection '%s'" % (
57 index_name
, collection
)