Esempio n. 1
0
def load_db(filename=None):
    """Loads a dump into the database"""
    env.box_dump_filename = filename

    if not filename:
        abort(red('Dump missing. "fab server.load_db:filename"', bold=True))

    if not os.path.exists(filename):
        abort(red('"%(box_dump_filename)s" does not exist.' % env, bold=True))

    if not confirm(
        "Completely replace the remote database" ' "%(box_database)s" (if it exists)?',
        default=False,
    ):
        return

    env.box_remote_db = remote_env("DATABASE_URL")
    if not env.box_remote_db:
        abort(red("Unable to determine the remote DATABASE_URL", bold=True))

    run('psql -c "DROP DATABASE IF EXISTS %(box_database)s"')
    run(
        "createdb %(box_database)s --encoding=UTF8 --template=template0"
        " --owner=%(box_database)s"
    )
    run_local(
        "cat %(box_dump_filename)s |" " ssh %(host_string)s psql %(box_remote_db)s"
    )
    run('psql %(box_database)s -c "REASSIGN OWNED BY admin ' ' TO %(box_database)s"')
Esempio n. 2
0
def dump_db():
    """Dumps the database into the tmp/ folder"""
    env.box_datetime = datetime.now().strftime('%Y-%m-%d-%s')
    env.box_dump_filename = os.path.join(
        os.getcwd(),
        'tmp',
        '%(box_database)s-%(box_environment)s-%(box_datetime)s.sql' % env,
    )

    env.box_remote_db = remote_env('DATABASE_URL')
    if not env.box_remote_db:
        abort(red('Unable to determine the remote DATABASE_URL', bold=True))

    run_local('ssh %(host_string)s pg_dump -Ox %(box_remote_db)s'
              ' > %(box_dump_filename)s')
    puts(green('\nWrote a dump to %(box_dump_filename)s' % env))
Esempio n. 3
0
def pull_database():
    """Pulls the database contents from the server, dropping the local
    database first (if it exists)"""

    if not confirm('Completely replace the local database'
                   ' "%(box_database_local)s" (if it exists)?'):
        return

    env.box_remote_db = remote_env('DATABASE_URL')
    if not env.box_remote_db:
        abort(red('Unable to determine the remote DATABASE_URL', bold=True))

    run_local('dropdb --if-exists %(box_database_local)s')
    run_local('createdb %(box_database_local)s'
              ' --encoding=UTF8 --template=template0')
    run_local('ssh %(host_string)s pg_dump -Ox "%(box_remote_db)s"'
              ' | psql %(box_database_local)s')
Esempio n. 4
0
def dump_db():
    """Dumps the database into the tmp/ folder"""
    env.box_datetime = datetime.now().strftime("%Y-%m-%d-%s")
    env.box_dump_filename = os.path.join(
        os.getcwd(),
        "tmp",
        "%(box_database)s-%(box_environment)s-%(box_datetime)s.sql" % env,
    )

    env.box_remote_db = remote_env("DATABASE_URL")
    if not env.box_remote_db:
        abort(red("Unable to determine the remote DATABASE_URL", bold=True))

    run_local(
        "ssh %(host_string)s pg_dump -Ox %(box_remote_db)s" " > %(box_dump_filename)s"
    )
    puts(green("\nWrote a dump to %(box_dump_filename)s" % env))