Ejemplo n.º 1
0
 def __init__(self, resource_module, apply_out_of_order_changes=False):
     self.resource_module = resource_module
     self.connection = None
     self.cursor = None
     self.connect_options = ConnectionParameters.from_config()
     self.apply_out_of_order_changes = apply_out_of_order_changes
     self.finder = ChangeScriptFinder(self.resource_module)
Ejemplo n.º 2
0
 def __init__(self, sql_dir, apply_out_of_order_changes=False):
     self.sql_dir = sql_dir
     self.connection = None
     self.cursor = None
     self.connect_options = ConnectionParameters.from_config()
     self.apply_out_of_order_changes = apply_out_of_order_changes
     self.finder = ChangeScriptFinder(self.sql_dir)
Ejemplo n.º 3
0
 def __init__(self, sql_dir, apply_out_of_order_changes=False):
     self.sql_dir = sql_dir
     self.connection = None
     self.cursor = None
     self.connect_options = ConnectionParameters.from_config()
     self.apply_out_of_order_changes = apply_out_of_order_changes
     self.finder = ChangeScriptFinder(self.sql_dir)
Ejemplo n.º 4
0
def drop_database():
    """Drops an existing database using PostgreSQL command line clients"""
    nav_opts = ConnectionParameters.from_config()
    postgres_opts = ConnectionParameters.for_postgres_user()
    postgres_opts.export(os.environ)

    print("Dropping database %s" % nav_opts.dbname)
    trap_and_die(subprocess.CalledProcessError,
                 "Failed to drop database %s" % nav_opts.dbname, check_call,
                 ["dropdb", nav_opts.dbname])
Ejemplo n.º 5
0
def drop_database():
    """Drops an existing database using PostgreSQL command line clients"""
    nav_opts = ConnectionParameters.from_config()
    postgres_opts = ConnectionParameters.for_postgres_user()
    postgres_opts.export(os.environ)

    print "Dropping database %s" % nav_opts.dbname
    trap_and_die(subprocess.CalledProcessError,
                 "Failed to drop database %s" % nav_opts.dbname,
                 check_call, ["dropdb", nav_opts.dbname])
Ejemplo n.º 6
0
def restore_from_dump(filename):
    """Restores a NAV database from an SQL dump produced by pg_dump"""
    postgres_opts = ConnectionParameters.for_postgres_user()
    postgres_opts.export(os.environ)
    nav_opts = ConnectionParameters.from_config()

    print("Restoring database %s from file %s" % (nav_opts.dbname, filename))
    trap_and_die(
        subprocess.CalledProcessError,
        "Failed to restore database %s from file %s" %
        (nav_opts.dbname, filename), check_call,
        ["psql", "--quiet", "-f", filename, nav_opts.dbname])
Ejemplo n.º 7
0
def restore_from_dump(filename):
    """Restores a NAV database from an SQL dump produced by pg_dump"""
    postgres_opts = ConnectionParameters.for_postgres_user()
    postgres_opts.export(os.environ)
    nav_opts = ConnectionParameters.from_config()

    print "Restoring database %s from file %s" % (nav_opts.dbname, filename)
    trap_and_die(
        subprocess.CalledProcessError,
        "Failed to restore database %s from file %s" % (nav_opts.dbname,
                                                        filename),
        check_call, ["psql", "--quiet", "-f", filename, nav_opts.dbname])
Ejemplo n.º 8
0
def create_database():
    """Create a database using PostgreSQL command line clients"""
    nav_opts = ConnectionParameters.from_config()
    postgres_opts = ConnectionParameters.for_postgres_user()
    postgres_opts.export(os.environ)

    if not user_exists(nav_opts.user):
        create_user(nav_opts.user, nav_opts.password)

    print "Creating database %s owned by %s" % (nav_opts.dbname, nav_opts.user)
    trap_and_die(subprocess.CalledProcessError,
                 "Failed creating database %s" % nav_opts.dbname,
                 check_call, ["createdb",
                              "--owner=%s" % nav_opts.user,
                              "--encoding=utf-8", nav_opts.dbname])
    install_pl_pgsql(nav_opts.dbname)
Ejemplo n.º 9
0
def export_pgvars():
    """Exports NAV's db config as PG* environment variables"""
    params = ConnectionParameters.from_config()
    params.export(os.environ)
Ejemplo n.º 10
0
def verify_password_is_configured():
    """Verifies that a password has been configured in db.conf"""
    opts = ConnectionParameters.from_config()
    if not opts.password:
        die("No password configured for %s user in db.conf" % opts.user)
Ejemplo n.º 11
0
def export_pgvars():
    """Exports NAV's db config as PG* environment variables"""
    params = ConnectionParameters.from_config()
    params.export(os.environ)
Ejemplo n.º 12
0
def verify_password_is_configured():
    """Verifies that a password has been configured in db.conf"""
    opts = ConnectionParameters.from_config()
    if not opts.password:
        die("No password configured for %s user in db.conf" % opts.user)