def _drop_db_accounts(self): logger.info("Dropping databases associated with {0}".format(self.shortname)) for provisioned_db in self.databases: try: provisioned_db._drop() except: if not shell.is_forced(): raise try: logger.info("Dropping PostgreSQL user account {0}".format(self.db_username)) if not shell.is_pretend(): conn, cur = Database._postgres() cur.execute("DROP OWNED BY {0};".format(self.db_username)) cur.execute("DROP ROLE {0};".format(self.db_username)) cur.execute('SELECT pg_reload_conf();') cur.close() conn.close() except: if not shell.is_forced(): raise try: logger.info("Dropping MySQL user account {0}".format(self.db_username_mysql)) if not shell.is_pretend(): conn, cur = Database._mysql() cur.execute("DROP USER '{0}'@'localhost';".format(self.db_username_mysql)) cur.close() conn.close() except: if not shell.is_forced(): raise
def _create_db_accounts(self): logger.info("Creating PostgreSQL user account {0}".format(self.db_username)) if not shell.is_pretend(): conn, cur = Database._postgres() cur.execute("CREATE ROLE {0} PASSWORD '{1}' LOGIN;".format(self.db_username, self.db_password)) cur.execute('SELECT pg_reload_conf();') cur.close() conn.close() logger.info("Creating MySQL user account {0}".format(self.db_username_mysql)) if not shell.is_pretend(): conn, cur = Database._mysql() cur.execute("CREATE USER '{0}'@'localhost' IDENTIFIED BY '{1}';".format(self.db_username_mysql, self.db_password)) cur.close() conn.close()