def run(self) -> Model: self.validate() try: database = DatabaseDAO.create(self._properties, commit=False) database.set_sqlalchemy_uri(database.sqlalchemy_uri) try: TestConnectionDatabaseCommand(self._actor, self._properties).run() except Exception as ex: # pylint: disable=broad-except db.session.rollback() event_logger.log_with_context( action=f"db_creation_failed.{ex.__class__.__name__}", engine=database.db_engine_spec.__name__, ) raise DatabaseConnectionFailedError() # adding a new database we always want to force refresh schema list schemas = database.get_all_schema_names(cache=False) for schema in schemas: security_manager.add_permission_view_menu( "schema_access", security_manager.get_schema_perm(database, schema)) security_manager.add_permission_view_menu("database_access", database.perm) db.session.commit() except DAOCreateFailedError as ex: event_logger.log_with_context( action=f"db_creation_failed.{ex.__class__.__name__}", engine=database.db_engine_spec.__name__, ) raise DatabaseCreateFailedError() return database
def run(self) -> Model: self.validate() try: # Test connection before starting create transaction TestConnectionDatabaseCommand(self._properties).run() except Exception as ex: event_logger.log_with_context( action=f"db_creation_failed.{ex.__class__.__name__}", engine=self._properties.get("sqlalchemy_uri", "").split(":")[0], ) raise DatabaseConnectionFailedError() from ex try: database = DatabaseDAO.create(self._properties, commit=False) database.set_sqlalchemy_uri(database.sqlalchemy_uri) # adding a new database we always want to force refresh schema list schemas = database.get_all_schema_names(cache=False) for schema in schemas: security_manager.add_permission_view_menu( "schema_access", security_manager.get_schema_perm(database, schema) ) db.session.commit() except DAOCreateFailedError as ex: db.session.rollback() event_logger.log_with_context( action=f"db_creation_failed.{ex.__class__.__name__}", engine=database.db_engine_spec.__name__, ) raise DatabaseCreateFailedError() from ex return database
def run(self) -> Model: self.validate() try: database = DatabaseDAO.update(self._model, self._properties, commit=False) database.set_sqlalchemy_uri(database.sqlalchemy_uri) security_manager.add_permission_view_menu("database_access", database.perm) # adding a new database we always want to force refresh schema list # TODO Improve this simplistic implementation for catching DB conn fails try: schemas = database.get_all_schema_names() except Exception as ex: db.session.rollback() raise DatabaseConnectionFailedError() from ex for schema in schemas: security_manager.add_permission_view_menu( "schema_access", security_manager.get_schema_perm(database, schema)) db.session.commit() except DAOUpdateFailedError as ex: logger.exception(ex.exception) raise DatabaseUpdateFailedError() from ex return database
def run(self) -> Model: self.validate() if not self._model: raise DatabaseNotFoundError() old_database_name = self._model.database_name try: database = DatabaseDAO.update(self._model, self._properties, commit=False) database.set_sqlalchemy_uri(database.sqlalchemy_uri) # adding a new database we always want to force refresh schema list # TODO Improve this simplistic implementation for catching DB conn fails try: schemas = database.get_all_schema_names() except Exception as ex: db.session.rollback() raise DatabaseConnectionFailedError() from ex # Update database schema permissions new_schemas: List[str] = [] for schema in schemas: old_view_menu_name = security_manager.get_schema_perm( old_database_name, schema) new_view_menu_name = security_manager.get_schema_perm( database.database_name, schema) schema_pvm = security_manager.find_permission_view_menu( "schema_access", old_view_menu_name) # Update the schema permission if the database name changed if schema_pvm and old_database_name != database.database_name: schema_pvm.view_menu.name = new_view_menu_name else: new_schemas.append(schema) for schema in new_schemas: security_manager.add_permission_view_menu( "schema_access", security_manager.get_schema_perm(database, schema)) db.session.commit() except DAOUpdateFailedError as ex: logger.exception(ex.exception) raise DatabaseUpdateFailedError() from ex return database
def run(self) -> Model: self.validate() try: database = DatabaseDAO.create(self._properties, commit=False) database.set_sqlalchemy_uri(database.sqlalchemy_uri) try: TestConnectionDatabaseCommand(self._actor, self._properties).run() except Exception: db.session.rollback() raise DatabaseConnectionFailedError() # adding a new database we always want to force refresh schema list schemas = database.get_all_schema_names(cache=False) for schema in schemas: security_manager.add_permission_view_menu( "schema_access", security_manager.get_schema_perm(database, schema) ) security_manager.add_permission_view_menu("database_access", database.perm) db.session.commit() except DAOCreateFailedError as ex: logger.exception(ex.exception) raise DatabaseCreateFailedError() return database