django_evolution.db.sqlite3
Evolution operations backend for SQLite.
Classes
|
Evolution operations backend for SQLite. |
|
Represents SQL statements used to rebuild a table on SQLite. |
- class django_evolution.db.sqlite3.SQLiteAlterTableSQLResult(evolver, model, alter_table=None, *args, **kwargs)
Bases:
AlterTableSQLResult
Represents SQL statements used to rebuild a table on SQLite.
Unlike most databases, SQLite doesn’t offer typical ALTER TABLE support, instead requiring a full table rebuild and data transfer. This class handles that process, allowing operations for the rebuild (adding, deleting, or changing columns) to be batched together.
The rebuild uses the step-by-step instructions recommended by SQLite. It creates a new table with the desired schema, copies all data from the old table, drops the old table, and then renames the new table over.
It can also update the newly-populated rows in the new table with new initial data, if needed by a new column.
- class django_evolution.db.sqlite3.EvolutionOperations(database_state, connection=<django.db.DefaultConnectionProxy object>)
Bases:
BaseEvolutionOperations
Evolution operations backend for SQLite.
- name = 'SQLite'
The name of the database type.
New in version 2.3.
- supported_change_meta = {'constraints': True, 'db_table_comment': False, 'index_together': True, 'indexes': True, 'unique_together': True}
- alter_table_sql_result_cls
alias of
SQLiteAlterTableSQLResult
- get_deferrable_sql()
Return the SQL for marking a reference as deferrable.
Despite SQLite3 supporting this, the Django SQLite3 backend does not implement the standard function (
BaseDatabaseOperations.deferrable_sql()
) for this.This provides a value used internally for building references.
New in version 2.2.
- Returns:
The SQL for marking a reference as deferrable.
- Return type:
- rename_table(model, old_db_table, new_db_table)
Rename a table.
- Parameters:
model (
django_evolution.mock_models.MockModel
) – The model representing the table to rename.old_db_table (
unicode
) – The old table name.new_db_table (
unicode
) – The new table name.
- Returns:
The resulting SQL for renaming the table.
- Return type:
- delete_column(model, field)
Delete a column from the table.
- Parameters:
model (
type
) – TheModel
class representing the table to delete the column from.field (
django.db.models.Field
) – The field representing the column to delete.
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- rename_column(model, old_field, new_field)
Rename a column on a table.
- Parameters:
model (
type
) – TheModel
class representing the table to rename the column on.old_field (
django.db.models.Field
) – The field representing the old column.new_field (
django.db.models.Field
) – The field representing the new column.
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- add_column(model, field, initial)
Add a column to the table.
- Parameters:
model (
type
) – TheModel
class representing the table to add the column to.field (
django.db.models.Field
) – The field representing the column to add.initial (
object
) –The initial data to set for the column. If
None
, the data will not be set.This will be required for
NOT NULL
columns.
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- change_column_attr_null(model, mutation, field, old_value, new_value)
Change a column’s NULL flag.
- Parameters:
model (
type
) – TheModel
class representing the table to change the column on.mutation (
django_evolution.mutations.BaseModelMutation
) – The mutation making this change.field (
django.db.models.Field
) – The field representing the column to change.old_value (
bool
, unused) – The old null flag.new_value (
bool
) – The new null flag.
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- change_column_attr_decimal_type(model, mutation, field, new_max_digits, new_decimal_places)
Return SQL for changing a column’s decimal_places attribute.
This is used for
DecimalField
and subclasses to change the maximum number of digits or decimal places. As these are used together as a column type, they must be considered together as one attribute change.- Parameters:
model (
type
) – The model class that owns the field.mutation (
django_evolution.mutations.BaseModelMutation
) – The mutation applying this change.field (
django.db.models.DecimalField
) – The field being modified.new_max_digits (
int
) – The new value formax_digits
. IfNone
, it wasn’t provided in the attribute change.new_decimal_places (
int
) – The new value fordecimal_places
. IfNone
, it wasn’t provided in the attribute change.
- Returns:
The SQL for modifying the value.
- Return type:
- change_column_attr_max_length(model, mutation, field, old_value, new_value)
Change a column’s max length.
- Parameters:
model (
type
) – TheModel
class representing the table to change the column on.mutation (
django_evolution.mutations.BaseModelMutation
) – The mutation making this change.field (
django.db.models.Field
) – The field representing the column to change.old_value (
int
, unused) – The old max length.new_value (
int
, unused) – The new max length.
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- change_column_type(model, old_field, new_field, new_attrs)
Return SQL to change the type of a column.
New in version 2.2.
- Parameters:
model (
type
) – The type of model owning the field.old_field (
django.db.models.Field
) – The old field.new_field (
django.db.models.Field
) – The new field.new_attrs (
dict
) – New attributes set in theChangeField
.
- Returns:
The SQL statements for changing the column type.
- Return type:
- get_change_unique_sql(model, field, new_unique_value, constraint_name, initial)
Change a column’s unique flag.
- Parameters:
model (
type
) – TheModel
class representing the table to change the column on.mutation (
django_evolution.mutations.BaseModelMutation
) – The mutation making this change.field (
django.db.models.Field
) – The field representing the column to change.old_value (
bool
, unused) – The old unique flag.new_value (
bool
, unused) – The new unique flag.
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- get_update_table_constraints_sql(model, old_constraints, new_constraints, to_add, to_remove)
Return SQL for updating the constraints on a table.
This will perform a table rebuild, including only any new constraints in the new schema.
- Parameters:
model (
django.db.models.Model
) – The model being changed.old_constraints (
list
of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``django.db.models.constraints.BaseConstraint
) – The old constraints pre-evolution.new_constraints (
list
of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``django.db.models.constraints.BaseConstraint
) – The new constraints post-evolution.to_add (
list
ofdjango.db.models.constraints.BaseConstraint
) – A list of new constraints to add to the database that weren’t set before.to_remove (
list
ofdjango.db.models.constraints.BaseConstraint
) – A list of old constraints to remove from the database that aren’t set now.
- Returns:
The SQL statements for changing the constraints.
- Return type:
django_evolution.sql_result.SQLResult
- change_column_attr_db_index(model, mutation, field, old_value, new_value)
Return the SQL for creating/dropping indexes for a column.
If setting
db_index=True
, SQL for generating the index will be returned immediately.If setting
db_index=False
, the dropping of the index will be scheduled as an Alter Table operation, ensuring it’s dropped immediately (and cached/queued database index state updated) before the table is rebuilt, never later.New in version 2.3.
- Parameters:
model (
django.db.models.Model
) – The model being changed.mutation (
django_evolution.mutations.BaseModelMutation
) – The mutation applying this change.field (
django.db.models.DecimalField
) – The field being modified.old_value (
bool
) – The old value fordb_index
.new_value (
bool
) – The new value fordb_index
.
- Returns:
The resulting SQL for creating the index or scheduling a drop.
- Return type:
- get_drop_unique_constraint_sql(model, index_name)
Return SQL for dropping unique constraints.
- Parameters:
- Returns:
The resulting SQL for rebuilding the table.
- Return type:
- get_indexes_for_table(table_name)
Return all known indexes on a table.
This is a fallback used only on Django 1.6, due to lack of proper introspection on that release.
- is_column_referenced(reffed_table_name, reffed_col_name)
Return whether a column on a table is referenced by another table.