forked from zacharyvoase/django-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified create_functions to mirror create_views zacharyvoase#4
- Loading branch information
Scott Walton
committed
May 10, 2013
1 parent
b2c911d
commit 552645e
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from optparse import make_option | ||
import logging | ||
|
||
from django.core.management.base import NoArgsCommand | ||
from django.db import models | ||
|
||
from django_postgres.function import create_functions | ||
|
||
|
||
log = logging.getLogger('django_postgres.sync_pgfunctions') | ||
|
||
|
||
class Command(NoArgsCommand): | ||
help = """Create/update Postgres functions for all installed apps.""" | ||
option_list = NoArgsCommand.option_list + ( | ||
make_option( | ||
'--no-update', | ||
action='store_false', | ||
dest='update', | ||
default=True, | ||
help="""Don't update existing functions, only create new ones."""), | ||
) | ||
|
||
def handle_noargs(self, force, update, **options): | ||
for module in models.get_apps(): | ||
log.info("Creating functions for %s", module.__name__) | ||
try: | ||
create_result = create_functions(module, update=update) | ||
|
||
for status, function_cls, python_name in create_result: | ||
if status == 'CREATED': | ||
msg = "created" | ||
elif status == 'UPDATED': | ||
msg = "updated" | ||
elif status == 'EXISTS': | ||
msg = "already exists, skipping" | ||
elif status == 'FORCE_REQUIRED': | ||
msg = ( | ||
"exists with incompatible schema, which must be " | ||
"manually removed") | ||
log.info("%(python_name)s (%(function_name)s): %(msg)s" % { | ||
'python_name': python_name, | ||
'function_name': function_cls._meta.db_table, | ||
'msg': msg}) | ||
except Exception, exc: | ||
if not hasattr(exc, 'function_cls'): | ||
raise | ||
log.exception("Error creating function %s (%r)", | ||
exc.python_name, | ||
exc.function_cls._meta.db_table) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters