add combined method for creating databases with users

- implement userdbs.models.UserDatabaseManager.create_userdatabase_with_user to
  setup a new database with a new database user in one step
This commit is contained in:
Jan Dittberner 2015-01-26 12:01:48 +01:00
parent f3168ffdb7
commit 2447f558e4

View file

@ -202,6 +202,26 @@ class UserDatabaseManager(models.Manager):
break break
return nextname return nextname
@transaction.atomic
def create_userdatabase_with_user(
self, db_type, osuser, password=None, commit=True):
"""
Creates a new user database with a new user.
:param db_type: database type from :py:data:`DB_TYPES`
:param osuser: :py:class:`osusers.models.OsUser` instance
:param str password: the password of the new database user
:param boolean commit: whether the user and the database should be
persisted
:return: database instance
:rtype: :py:class:`UserDatabase`
"""
dbuser = DatabaseUser.objects.create_database_user(
osuser, db_type, password=password, commit=commit)
database = self.create_userdatabase(dbuser, commit=commit)
return database
@transaction.atomic @transaction.atomic
def create_userdatabase(self, db_user, db_name=None, commit=True): def create_userdatabase(self, db_user, db_name=None, commit=True):
""" """