Package trac :: Package db :: Module api :: Class DatabaseManager

Class DatabaseManager

source code

    object --+    
             |    
core.Component --+
                 |
                DatabaseManager

Component used to manage the IDatabaseConnector implementations.
Nested Classes

Inherited from core.Component: __metaclass__

Instance Methods
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
init_db(self) source code
 
destroy_db(self) source code
 
db_exists(self) source code
 
create_tables(self, schema)
Create the specified tables.
source code
 
drop_columns(self, table, columns)
Drops the specified columns from table.
source code
 
drop_tables(self, schema)
Drop the specified tables.
source code
 
insert_into_tables(self, data_or_callable)
Insert data into existing tables.
source code
 
reset_tables(self)
Deletes all data from the tables and resets autoincrement indexes.
source code
 
upgrade_tables(self, new_schema)
Upgrade table schema to new_schema, preserving data in columns that exist in the current schema and new_schema.
source code
 
get_connection(self, readonly=False)
Get a database connection from the pool.
source code
 
get_database_version(self, name='database_version')
Returns the database version from the SYSTEM table as an int, or False if the entry is not found.
source code
 
get_exceptions(self) source code
 
get_sequence_names(self)
Returns a list of the sequence names.
source code
 
get_table_names(self)
Returns a list of the table names.
source code
 
get_column_names(self, table)
Returns a list of the column names for table.
source code
 
has_table(self, table)
Returns whether the table exists.
source code
 
set_database_version(self, version, name='database_version')
Sets the database version in the SYSTEM table.
source code
 
needs_upgrade(self, version, name='database_version')
Checks the database version to determine if an upgrade is needed.
source code
 
upgrade(self, version, name='database_version', pkg='trac.upgrades')
Invokes do_upgrade(env, version, cursor) in module "%s/db%i.py" % (pkg, version), for each required version upgrade.
source code
 
shutdown(self, tid=None) source code
 
backup(self, dest=None)
Save a backup of the database.
source code
 
get_connector(self) source code
 
environment_created(self)
Insert default data into the database.
source code
 
environment_needs_upgrade(self) source code
 
upgrade_environment(self) source code
 
get_system_info(self) source code

Inherited from core.Component: __repr__

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

Static Methods

Inherited from core.Component: implements

Class Variables
  connection_uri = <Option [trac] 'database'>
  backup_dir = <Option [trac] 'backup_dir'>
  timeout = <IntOption [trac] 'timeout'>
  debug_sql = <BoolOption [trac] 'debug_sql'>
Properties
  connectors
List of components that implement ~trac.db.api.IDatabaseConnector

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

source code 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__
(inherited documentation)

create_tables(self, schema)

source code 
Create the specified tables.
Parameters:
  • schema - an iterable of table objects.

Since: version 1.0.2

drop_columns(self, table, columns)

source code 
Drops the specified columns from table.

Since: version 1.2

drop_tables(self, schema)

source code 
Drop the specified tables.
Parameters:
  • schema - an iterable of Table objects or table names.

Since: version 1.0.2

insert_into_tables(self, data_or_callable)

source code 
Insert data into existing tables.
Parameters:
  • data_or_callable - Nested tuples of table names, column names and row data:

    (table1,
     (column1, column2),
     ((row1col1, row1col2),
      (row2col1, row2col2)),
     table2, ...)
    

    or a callable that takes a single parameter db and returns the aforementioned nested tuple.

Since: version 1.1.3

reset_tables(self)

source code 
Deletes all data from the tables and resets autoincrement indexes.
Returns:
list of names of the tables that were reset.

Since: version 1.1.3

upgrade_tables(self, new_schema)

source code 
Upgrade table schema to new_schema, preserving data in columns that exist in the current schema and new_schema.
Parameters:
  • new_schema - tuple or list of Table objects

Since: version 1.2

get_connection(self, readonly=False)

source code 

Get a database connection from the pool.

If readonly is True, the returned connection will purposely lack the rollback and commit methods.

get_database_version(self, name='database_version')

source code 
Returns the database version from the SYSTEM table as an int, or False if the entry is not found.
Parameters:
  • name - The name of the entry that contains the database version in the SYSTEM table. Defaults to database_version, which contains the database version for Trac.

get_sequence_names(self)

source code 
Returns a list of the sequence names.

Since: 1.3.2

get_table_names(self)

source code 
Returns a list of the table names.

Since: 1.1.6

get_column_names(self, table)

source code 
Returns a list of the column names for table.
Parameters:
  • table - a Table object or table name.

Since: 1.2

set_database_version(self, version, name='database_version')

source code 
Sets the database version in the SYSTEM table.
Parameters:
  • version - an integer database version.
  • name - The name of the entry that contains the database version in the SYSTEM table. Defaults to database_version, which contains the database version for Trac.

needs_upgrade(self, version, name='database_version')

source code 
Checks the database version to determine if an upgrade is needed.
Parameters:
  • version - the expected integer database version.
  • name - the name of the entry in the SYSTEM table that contains the database version. Defaults to database_version, which contains the database version for Trac.
Returns:
True if the stored version is less than the expected version, False if it is equal to the expected version.
Raises:
  • TracError - if the stored version is greater than the expected version.

upgrade(self, version, name='database_version', pkg='trac.upgrades')

source code 
Invokes do_upgrade(env, version, cursor) in module "%s/db%i.py" % (pkg, version), for each required version upgrade.
Parameters:
  • version - the expected integer database version.
  • name - the name of the entry in the SYSTEM table that contains the database version. Defaults to database_version, which contains the database version for Trac.
  • pkg - the package containing the upgrade modules.
Raises:
  • TracError - if the package or module doesn't exist.

backup(self, dest=None)

source code 

Save a backup of the database.

Returns the file actually written.

Parameters:
  • dest - base filename to write to.

Property Details

connectors

List of components that implement ~trac.db.api.IDatabaseConnector
Get Method:
unreachable.extensions(component) - Return a list of components that declare to implement the extension point interface.