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 db_delete(args): thesite = Site.get(args.shortname) if not thesite: logger.error("No site named {0} exists".format(thesite.shortname)) sys.exit(1) try: Database.delete(args.database_name, thesite) except Exception as e: logger.exception("Database deletion failed")
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()
def db_create(args): thesite = Site.get(args.shortname) if not thesite: logger.error("No site named {0} exists".format(thesite.shortname)) sys.exit(1) if args.dbms.lower() == "mysql": dbms = Database.MYSQL elif args.dbms.lower() == "postgresql": dbms = Database.POSTGRESQL else: logger.error("Invalid DBMS!") sys.exit(1) try: Database.create(args.database_name, thesite, dbms, fake_create=args.fake_create) except Database.Exists as e: logger.exception("A database with the name {0} already exists".format(args.database_name)) except Exception as e: logger.exception("Database creation failed")