Exemplo n.º 1
0
def run():
    db_name = settings.DATABASES['default']['NAME']
    if "postgres" in settings.DATABASES['default']['ENGINE']:
        import psycopg2
        try:
            psycopg2.connect("dbname=%s" % db_name)
            print("Deleting DB ...", end="")
            sh.dropdb(db_name)
            print("Done")
        except psycopg2.OperationalError:
            pass
    else:
        if os.path.isfile(db_name):
            os.unlink(db_name)
    print("Done")
    print("Creating DB ...", end="")
    if "postgres" in settings.DATABASES['default']['ENGINE']:
        sh.createdb(db_name)
    print("Done")
    call_command("migrate")

    print("Create superuser")
    admin = User.objects.create_superuser(username="******",
                                          password="******",
                                          email="*****@*****.**")
Exemplo n.º 2
0
def deletedb():
    environ['PGUSER'] = "******"

    click.echo("Dropping databases")
    dropdb(DB_NAME)
    dropdb("maps")

    click.echo("Dropping user")
    dropuser(DB_USER)
Exemplo n.º 3
0
    def reset_db(self):
        common_args = ['-h', settings.PG_HOST, '-U', settings.PG_USERNAME]
        print('Dropping postgres', self.settings['PG_DATABASE'])
        sh.dropdb(self.settings['PG_DATABASE'], *common_args, _ok_code=[0, 1])
        print('Creating postgres', self.settings['PG_DATABASE'])
        sh.createdb(self.settings['PG_DATABASE'], *common_args)

        # verify DB is accessible
        self.psql(c="SELECT 1")
Exemplo n.º 4
0
def resetdb():
    """Create the tables."""
    import annotator.models  # noqa

    click.echo('Resetting database...')

    query = '''
        SELECT pg_terminate_backend(pid)
        FROM pg_stat_activity
        WHERE datname = '{}'
    '''.format(db.engine.url.database)
    psql('--command', query)
    dropdb('--if-exists', db.engine.url.database)
    createdb(db.engine.url.database)
    _createtables()
Exemplo n.º 5
0
def drop_database(dbname: str) -> None:
    from sh import dropdb

    dropdb(*_maint_conn_args(), dbname)