|
1 from south.management.commands.migrate import Command |
|
2 from south.db import DEFAULT_DB_ALIAS |
|
3 from south import migration |
|
4 import sys |
|
5 |
|
6 ### RBA+GIB: prevent uno custom __import__ from messing with south import machinery (to discover south enabled dj apps) |
|
7 def new_handle(self, app=None, target=None, skip=False, merge=False, backwards=False, fake=False, db_dry_run=False, show_list=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False, ignore_ghosts=False, **options): |
|
8 |
|
9 # NOTE: THIS IS DUPLICATED FROM django.core.management.commands.syncdb |
|
10 # This code imports any module named 'management' in INSTALLED_APPS. |
|
11 # The 'management' module is the preferred way of listening to post_syncdb |
|
12 # signals, and since we're sending those out with create_table migrations, |
|
13 # we need apps to behave correctly. |
|
14 from django.conf import settings |
|
15 for app_name in settings.INSTALLED_APPS: |
|
16 try: |
|
17 __import__(app_name + '.management', {}, {}, ['']) |
|
18 except ImportError, exc: |
|
19 msg = exc.args[0] |
|
20 if (not msg.startswith('No module named') and not msg.endswith(' is unknown') ) or 'management' not in msg: |
|
21 raise |
|
22 |
|
23 # END DJANGO DUPE CODE |
|
24 |
|
25 # if all_apps flag is set, shift app over to target |
|
26 if options.get('all_apps', False): |
|
27 target = app |
|
28 app = None |
|
29 |
|
30 # Migrate each app |
|
31 if app: |
|
32 try: |
|
33 apps = [Migrations(app)] |
|
34 except NoMigrations: |
|
35 print "The app '%s' does not appear to use migrations." % app |
|
36 print "./manage.py migrate " + self.args |
|
37 return |
|
38 else: |
|
39 apps = list(migration.all_migrations()) |
|
40 |
|
41 # Do we need to show the list of migrations? |
|
42 if show_list and apps: |
|
43 list_migrations(apps, database) |
|
44 |
|
45 if not show_list: |
|
46 |
|
47 for app in apps: |
|
48 result = migration.migrate_app( |
|
49 app, |
|
50 target_name = target, |
|
51 fake = fake, |
|
52 db_dry_run = db_dry_run, |
|
53 verbosity = int(options.get('verbosity', 0)), |
|
54 interactive = options.get('interactive', True), |
|
55 load_initial_data = not options.get('no_initial_data', False), |
|
56 merge = merge, |
|
57 skip = skip, |
|
58 database = database, |
|
59 delete_ghosts = delete_ghosts, |
|
60 ignore_ghosts = ignore_ghosts, |
|
61 ) |
|
62 if result is False: |
|
63 sys.exit(1) # Migration failed, so the command fails. |
|
64 |
|
65 Command.handle = new_handle |