Commits

and...@69d324d9-c39d-4fdc-8679-7745eae9e2c8  committed 4974d39

Various changes, which will form the 0.2 release.

  • Participants
  • Parent commits 313896d

Comments (0)

Files changed (5)

 """
 South - Useable migrations for Django apps
-"""
+"""
+
+__version__ = "0.2"
+__authors__ = ["Andrew Godwin <andrew@aeracode.org>"]

File db/sqlite3.py

+
+from django.db import connection
+from south.db import generic
+
+class DatabaseOperations(generic.DatabaseOperations):
+
+    """
+    SQLite3 implementation of database operations.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("Support for SQLite3 is not yet complete.")

File docs/CHANGELOG

+
+0.2
+===
+
+The oh-i'm-sorry-mysql-users release.
+
+New features:
+
+ - MySQL support up to the same level as PostgreSQL
+ - New --all option to ./manage.py startmigration, which creates a migration
+   for every model in the given app. For project starts.
+ - Project status upgraded to 'beta'. Next up, a colour-coded
+   release level system.
+
+Fixed bugs:
+
+ - A few typos in various column methods
+ - ManyToMany tables weren't created by startmigration migrations.
+
+Known bugs:
+
+ - None
+
+
+0.1
+===
+
+Initial release.
 of a whole load of applied ones, and will let you apply it straight off,
 or let you roll back to it, and apply from there forward.
 
+Contact
+-------
+
+If you have any problems with South not addressed in this documentation, or
+would like to request a feature, please get in touch with me at
+andrew at aeracode dot org.
+
+
 Installation
 ------------
 

File management/commands/startmigration.py

 from django.core.management.base import BaseCommand
 from django.core.management.color import no_style
 from django.db import models
+from django.db.models.loading import get_models
 from optparse import make_option
 from south import migration
 import sys
 import random
 
 class Command(BaseCommand):
-    option_list = BaseCommand.option_list
+    option_list = BaseCommand.option_list + (
+        make_option('--all', action='store_true', dest='all_models', default=False,
+            help='Tells South to create migrations for all models in the given app.'),
+    )
     help = "Creates a new template migration for the given app"
 
-    def handle(self, app=None, name="", model=None, **options):
+    def handle(self, app=None, name="", model=None, all_models=False, **options):
         if not app:
             print "Please provide an app in which to create the migration."
             return
         except ImportError:
             print "App '%s' doesn't seem to exist." % app
             return
+        # If they asked for all models, they better not have given a name
+        if all_models:
+            if name:
+                print "You cannot ask for all models to be autogenerated, and give a migration name."
+                return
+            else:
+                # OK, go ahead and scan the models then
+                models = get_models(app_module.models)
+                for model in models:
+                    self.handle(app, model.__name__.lower(), model.__name__, **options)
+                return
         # If there's a model, open it and have a poke
         if model:
             try:
         if model:
             table_name = model._meta.db_table
             fields = []
+            m2ms = []
             for f in model._meta.local_fields:
                 # We use a list of tuples to get nice ordering
                 type, type_param = genericify_type(f.db_type())
                 ]),
             )
             backwards = '''db.delete_table("%s")''' % table_name
+            # Now go through local M2Ms and add extra stuff for them
+            for m in model._meta.local_many_to_many:
+                forwards += '''\n        # M2M field '%s'
+        db.create_table("%s", [
+            {"name": "id", "type": "serial", "null": False, "unique": True},
+            {"name": "%s", "type": "integer", "null": False, "related_to": ("%s", "%s")},
+            {"name": "%s", "type": "integer", "null": False, "related_to": ("%s", "%s")},
+        ) ''' % (
+                    m.name,
+                    m.m2m_db_table(),
+                    m.m2m_column_name(),
+                    table_name,
+                    "id",
+                    m.m2m_reverse_name(),
+                    m.rel.to._meta.db_table,
+                    "id",
+                )
+                backwards += '''
+        db.delete_table("%s")''' % m.m2m_db_table()
         else:
             forwards = '"Write your forwards migration here"'
             backwards = '"Write your backwards migration here"'