1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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/>.
19 from mediagoblin
.init
import setup_global_and_app_config
22 def migrate_parser_setup(subparser
):
26 def _print_started_migration(migration_number
, migration_func
):
28 "Running migration %s, '%s'... " % (
29 migration_number
, migration_func
.func_name
))
33 def _print_finished_migration(migration_number
, migration_func
):
34 sys
.stdout
.write("done.\n")
39 run_migrate(args
.conf_file
)
42 def run_migrate(conf_file
):
43 # This MUST be imported so as to set up the appropriate migrations!
44 from mediagoblin
.db
.mongo
import migrations
46 from mediagoblin
.db
.mongo
import util
as db_util
47 from mediagoblin
.db
.mongo
.open import setup_connection_and_db_from_config
49 global_config
, app_config
= setup_global_and_app_config(conf_file
)
51 connection
, db
= setup_connection_and_db_from_config(
52 app_config
, use_pymongo
=True)
53 migration_manager
= db_util
.MigrationManager(db
)
56 print "== Clearing old indexes... =="
57 removed_indexes
= db_util
.remove_deprecated_indexes(db
)
59 for collection
, index_name
in removed_indexes
:
60 print "Removed index '%s' in collection '%s'" % (
61 index_name
, collection
)
64 print "\n== Applying migrations... =="
65 migration_manager
.migrate_new(
66 pre_callback
=_print_started_migration
,
67 post_callback
=_print_finished_migration
)
70 print "\n== Adding new indexes... =="
71 new_indexes
= db_util
.add_new_indexes(db
)
73 for collection
, index_name
in new_indexes
:
74 print "Added index '%s' to collection '%s'" % (
75 index_name
, collection
)