django_evolution.db.state
Database state tracking for in-progress evolutions.
Classes
|
Tracks some useful state in the database. |
|
An index recorded in the database state. |
- class django_evolution.db.state.IndexState(name, columns=[], unique=False)
Bases:
object
An index recorded in the database state.
- __init__(name, columns=[], unique=False)
Initialize the index state.
- __eq__(other_state)
Return whether two index states are equal.
- Parameters:
other_state (
IndexState
) – The other index state to compare to.- Returns:
True
if the two index states are equal.False
if they are not.- Return type:
- __hash__()
Return a hash representation of the index.
- Returns:
The hash representation.
- Return type:
- class django_evolution.db.state.DatabaseState(db_name, scan=True)
Bases:
object
Tracks some useful state in the database.
This primarily tracks indexes associated with tables, allowing them to be scanned from the database, explicitly added, removed, or cleared.
- __init__(db_name, scan=True)
Initialize the state.
- clone()
Clone the database state.
- Returns:
The cloned copy of the state.
- Return type:
- add_table(table_name)
Add a table to track.
This will add an empty entry for the table to the state.
- Parameters:
table_name (
unicode
) – The name of the table.
- has_table(table_name)
Return whether a table is being tracked.
This does not necessarily mean that the table exists in the database. Rather, state for the table is being tracked.
- has_model(model)
Return whether a database model is installed in the database.
- add_index(table_name, index_name, columns, unique=False)
Add a table’s index to the database state.
This index can be used for later lookup during the evolution process. It won’t otherwise be preserved, though the resulting indexes are expected to match the result in the database.
This requires the table to be tracked first.
- Parameters:
- Raises:
django_evolution.errors.DatabaseStateError – There was an issue adding this index. Details are in the exception’s message.
- remove_index(table_name, index_name, unique=False)
Remove an index from the database state.
This index will no longer be found during lookups when generating evolution SQL, even if it exists in the database.
This requires the table to be tracked first and for the index to both exist and match the
unique
flag.- Parameters:
- Raises:
django_evolution.errors.DatabaseStateError – There was an issue removing this index. Details are in the exception’s message.
- get_index(table_name, index_name, unique=False)
Return the index state for a given name.
- Parameters:
- Returns:
The state for the index, if found.
None
if the index could not be found.- Return type:
- find_index(table_name, columns, unique=False)
Find and return an index matching the given columns and flags.
- Parameters:
- Returns:
The state for the index, if found.
None
if an index matching the criteria could not be found.- Return type:
- clear_indexes(table_name)
Clear all recorded indexes for a table.
- Parameters:
table_name (
unicode
) – The name of the table.
- iter_indexes(table_name)
Iterate through all indexes for a table.
- Parameters:
table_name (
unicode
) – The name of the table.- Yields:
IndexState
– An index in the table.
- rescan_tables()
Rescan the list of tables from the database.
This will look up all tables found in the database, along with information (such as indexes) on those tables.
Existing information on the tables will be flushed.