Browse files

Merge remote-tracking branch 'origin/develop'

  • Loading branch information...
2 parents d6bfbe1 + fdc7361 commit 14b132ff5d37eddf1a2df12c6ad76a5ad02eb92f Sridhar Ratnakumar committed Jun 1, 2012
Showing with 29 additions and 35 deletions.
  1. +2 −6 README.md
  2. +26 −28 settings.py
  3. +1 −1 stackato.yml
View
8 README.md
@@ -24,9 +24,5 @@ Visit http://gtd.stackato.local/ to see the list of tasks. Visit http://gtd.stac
To use mysql instead of postgresql on production, you need to make only a few
changes before pushing (or updating) your app:
- * In requirements.txt, replace `psycopg2` with `mysql-python`
- * In settings.py, replace `django.db.backends.postgresql_psycopg2` with
- `django.db.backends.mysql`
- * In settings.py, replace `vcap_services['postgresql-8.4'][0]` with
- `vcap_services['mysql-5.1'][0]`
- * In stackato.yml, replace `postgresql` with `mysql.
+ * In stackato.yml, replace `postgresql` with `mysql` under *services*.
+ * In stackato.yml, replace `psycopg2` with `mysql-python` under *requirements*.
View
54 settings.py
@@ -1,5 +1,7 @@
# Django settings for djangogtd project.
-import sys, os
+import os
+import sys
+import urlparse
DEBUG = False
TEMPLATE_DEBUG = DEBUG
@@ -12,35 +14,31 @@
MANAGERS = ADMINS
-STACKATO = 'VCAP_SERVICES' in os.environ
-
-## Pull in CloudFoundry's production settings
-if STACKATO:
- import json
- vcap_services = json.loads(os.environ['VCAP_SERVICES'])
- # XXX: avoid hardcoding here
- srv = vcap_services['postgresql-8.4'][0]
- cred = srv['credentials']
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': cred['name'], # Or path to database file if using sqlite3.
- 'USER': cred['user'], # Not used with sqlite3.
- 'PASSWORD': cred['password'], # Not used with sqlite3.
- 'HOST': cred['hostname'], # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': cred['port'], # Set to empty string for default. Not used with sqlite3.
- }
+# running on stckato?
+STACKATO = 'VCAP_APPLICATION' in os.environ
+
+DATABASES = {}
+if 'DATABASE_URL' in os.environ:
+ url = urlparse.urlparse(os.environ['DATABASE_URL'])
+ DATABASES['default'] = {
+ 'NAME': url.path[1:],
+ 'USER': url.username,
+ 'PASSWORD': url.password,
+ 'HOST': url.hostname,
+ 'PORT': url.port,
}
+ if url.scheme == 'postgres':
+ DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
+ elif url.scheme == 'mysql':
+ DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
else:
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': 'dev.db', # Or path to database file if using sqlite3.
- 'USER': '', # Not used with sqlite3.
- 'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
- }
+ DATABASES['default'] = {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'dev.db', # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
# Local time zone for this installation. Choices can be found here:
View
2 stackato.yml
@@ -10,7 +10,7 @@ requirements:
- south
services:
- postgresql: postgresql-gtd
+ postgresql-gtd: postgresql
hooks:
post-staging:

0 comments on commit 14b132f

Please sign in to comment.