Created
June 1, 2014 06:01
-
-
Save hillscottc/8310f5c112c4118bd535 to your computer and use it in GitHub Desktop.
Sample Fabric file to rebuild db.
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
from __future__ import with_statement | |
import os | |
from fabric.api import local, settings, abort, sudo, env | |
from fabric.contrib.console import confirm | |
env.hosts = [ | |
# 'me@my-imac', | |
'me@my-desk', | |
] | |
def db_exists(db='testdb'): | |
if (sudo("psql -l | grep {} | wc -l".format(db), user='postgres')) != '0': | |
return True | |
else: | |
return False | |
def db_rebuild(db='testdb'): | |
"""Drop, create, and sync the db.""" | |
## Warning. | |
if not confirm("Running on {} with database {}. Proceed?".format(env.host, db)): | |
print("Ok, no changes.") | |
return | |
## Drop the database. | |
if db_exists(db): | |
sudo("dropdb {}".format(db), user='postgres') | |
## Create the database. | |
sudo("createdb -E UTF8 -e {}".format(db), user='postgres') | |
## Run django's syncdb. | |
local('python ./manage.py syncdb') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment