Source

fabulator / src / fabulator / core / db / pgsql.py

"""
    psql management functions
"""
import datetime
import time

from fabric.api import run

from base import BaseDB

class PgSQL(BaseDB):
    """Base class for database"""

    def create_database(self, database_name=None):
        """create database"""
        run("echo 'CREATE DATABASE IF NOT EXISTS %(db)s' | psql --user=%(user)s --password=%(pw)s" % self.conf)

    def backup(self, filename="plop"):
        """Backups your psql database"""
        date = datetime.datetime.now()

        conf['backup_fname'] = "%s/backup-%s-%d-%d-%d-%s.sql" % \
            (self.conf.get('backup'), self.conf.get('db'), date.day, date.month,
             date.year, time.time())
        run("mkdir -p %(backup)s" % self.conf)
        run("""psqldump --host=%(host)s --user=%(user)s --password=%(pw)s %(db)s > %(backup_fname)s""" % self.conf)

    def migrate(self, revision):
        """migrate the database"""
        raise NotImplementedError

    def fallback(self, revision):
        """fallback to an old revision"""
        raise NotImplementedError

    def drop_table(self, table_name):
        """Drop a table"""
        raise NotImplementedError

    def drop_database(self, database_name):
        run("echo 'DROP DATABASE %(db)s' | psql --user=%(user)s --password=%(pw)s" % self.conf)

    def list_revision(self):
        """Return a list of available database revision"""
        run("ls -l %(backup)s" % self.conf)
        raise NotImplementedError
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.