Package wsatools :: Package DbConnect :: Module DbSession :: Class Database
[hide private]

Class Database

source code


Defines a database object, and provides method to create and modify databases through administrative database connections. First, define with Database.__init__(), then create the database with Database.create().

Nested Classes [hide private]
    Nested Error Exceptions
  ExistsError
Exception thrown when a database being created already exists.
Instance Methods [hide private]
 
__init__(self, name, volumes=['G:\\', 'H:\\', 'I:\\', 'J:\\'], dbDir=None, primarySize='4 GB', logSize='1 GB', filegroups=[], filegrowth='10%')
Defines a database object.
source code
str
__str__(self)
Returns: Database name.
source code
 
attach(self, adminDb, asName=None)
Re-attach the offline database that was previously detached.
source code
 
create(self, adminDb, overWrite=False)
Creates this database on a specified server.
source code
 
delete(self, adminDb)
Delete this database on a specified server.
source code
 
detach(self, adminDb)
Detach (take offline) the database.
source code
str
getMirrorServer(self, server)
Returns the corresponding mirror server for the given server.
source code
str
mirror(self, adminDb)
Copy the database to the mirror server on the cluster.
source code
 
release(self, adminDb, pubServer)
Copy the database to the given public server on the cluster.
source code
 
setBulkLoadOptions(self, adminDb)
Set MS SQL Server database options appropriate for bulk loading, over the load database default options.
source code
 
setDefaultOptions(self, adminDb)
Set the MS SQL Server database options that are appropriate for a load database over the MS SQL server default options.
source code
 
setReleaseOptions(self, adminDb)
Set MS SQL Server database options appropriate for a release db over the default load database options.
source code
 
_makeFolders(self, adminDb)
Creates the folders for the database files.
source code
str
_splitSize(self, size, divisions)
Splits a size into a number of divisions, converting between GB and MB when necessary.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]
  files = None
List of file path names for this database.
  name = ''
Database name.
  _folders = []
Set of directories this database spans.
  _sqlLine = ''
SQL to create this database.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, volumes=['G:\\', 'H:\\', 'I:\\', 'J:\\'], dbDir=None, primarySize='4 GB', logSize='1 GB', filegroups=[], filegrowth='10%')
(Constructor)

source code 

Defines a database object.

Parameters:
  • name (str) - Name of database to create.
  • volumes (str) - List of volumes to spread database files over.
  • dbDir (str) - Directory name on catalogue server to store database. This value is overriden for multi-file databases, which have the directory name as the database name, otherwise assumes non-survey folder.
  • primarySize (str) - Total initial size of files in the primary file group, as a string, e.g. "4 GB".
  • logSize (str) - Total initial size of files in the log file group, as a string, e.g. "4 GB".
  • filegroups (list(tuple(str, str))) - List of additional file group names and sizes, e.g. ("Detection", "4 GB").
  • filegrowth (str) - File growth, e.g. "10%".
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns: str
Database name.
Overrides: object.__str__

attach(self, adminDb, asName=None)

source code 

Re-attach the offline database that was previously detached. The current implementation is tied to MS SQL Server via T-SQL.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be attached.
  • asName (str) - Optional alternative name to attach the database as, instead of its real name (used in the file names).

create(self, adminDb, overWrite=False)

source code 

Creates this database on a specified server.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be created.
  • overWrite (bool) - If True, overwrite any pre-existing database of this name.

delete(self, adminDb)

source code 

Delete this database on a specified server.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be deleted.

detach(self, adminDb)

source code 

Detach (take offline) the database. The current implementation is tied to MS SQL Server via T-SQL.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be detached.

getMirrorServer(self, server)

source code 

Returns the corresponding mirror server for the given server.

Parameters:
  • server (str) - Name of server to find mirror of.
Returns: str
Name of mirror server.

mirror(self, adminDb)

source code 

Copy the database to the mirror server on the cluster.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server which has the database to be copied.
Returns: str
Mirror server name.

release(self, adminDb, pubServer)

source code 

Copy the database to the given public server on the cluster.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server which has the database to be copied.
  • pubServer (str) - Name of server to copy to.

To Do: Merge with mirror somehow.

setBulkLoadOptions(self, adminDb)

source code 

Set MS SQL Server database options appropriate for bulk loading, over the load database default options.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be altered.

setDefaultOptions(self, adminDb)

source code 

Set the MS SQL Server database options that are appropriate for a load database over the MS SQL server default options.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be altered.

setReleaseOptions(self, adminDb)

source code 

Set MS SQL Server database options appropriate for a release db over the default load database options.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be altered.

_makeFolders(self, adminDb)

source code 

Creates the folders for the database files.

Parameters:
  • adminDb (DbSession) - An autocommiting admin (i.e. master) database connection to the server where the database will be created.

_splitSize(self, size, divisions)

source code 

Splits a size into a number of divisions, converting between GB and MB when necessary.

Parameters:
  • size (str) - Initial size in GB or MB, e.g. 10 GB.
  • divisions (int) - Number of divisions size must be divide between.
Returns: str
Divided integer size in either GB or MB.