From 5527311ed36d1f51c610f3ea53ffc1fc3fc1bea2 Mon Sep 17 00:00:00 2001 From: Fred Wenzel Date: Thu, 6 Jan 2011 16:06:31 -0800 Subject: [PATCH] Added schematic. --- docs/libs.rst | 2 +- manage.py | 5 +++++ migrations/01-noop.sql | 1 + migrations/__init__.py | 0 migrations/schematic_settings.py | 30 ++++++++++++++++++++++++++++++ vendor | 2 +- 6 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 migrations/01-noop.sql create mode 100644 migrations/__init__.py create mode 100644 migrations/schematic_settings.py diff --git a/docs/libs.rst b/docs/libs.rst index 869d925..3f6bfaf 100644 --- a/docs/libs.rst +++ b/docs/libs.rst @@ -16,7 +16,7 @@ Database * `django-multidb-router `_: Round-robin master/slave db router for Django 1.2. -* `schematic `_: +* `schematic `_\*: Simple database migration tool. Deferred Execution (cron, message queues) diff --git a/manage.py b/manage.py index 0e88a15..807fa42 100755 --- a/manage.py +++ b/manage.py @@ -38,6 +38,11 @@ " Please come back and try again later.") raise +# If we want to use django settings anywhere, we need to set up the required +# environment variables. +setup_environ(settings) + +# Configure Celery import djcelery djcelery.setup_loader() diff --git a/migrations/01-noop.sql b/migrations/01-noop.sql new file mode 100644 index 0000000..7aad5af --- /dev/null +++ b/migrations/01-noop.sql @@ -0,0 +1 @@ +-- Example database migration for schematic. Remove this, if you like. diff --git a/migrations/__init__.py b/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/migrations/schematic_settings.py b/migrations/schematic_settings.py new file mode 100644 index 0000000..f5455ff --- /dev/null +++ b/migrations/schematic_settings.py @@ -0,0 +1,30 @@ +import sys +import os + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +# Set up playdoh. +import manage +from django.conf import settings + +config = settings.DATABASES['default'] +config['HOST'] = config.get('HOST', 'localhost') +config['PORT'] = config.get('PORT', '3306') + +if not config['HOST'] or config['HOST'].endswith('.sock'): + """Oh, you meant 'localhost'!""" + config['HOST'] = 'localhost' + +s = 'mysql --silent {NAME} -h{HOST} -u{USER}' + +if config['PASSWORD']: + s += ' -p{PASSWORD}' +else: + del config['PASSWORD'] +if config['PORT']: + s += ' -P{PORT}' +else: + del config['PORT'] + +db = s.format(**config) +table = 'schema_version' diff --git a/vendor b/vendor index 50f7ed7..8b719f7 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit 50f7ed7ae3a1980d03ee04f8bb9004e3e69cb8a9 +Subproject commit 8b719f776a3280a9cad439f9def6e238b9843dc3