This module extends SQLAlchemy and provides additional DDL [1] support.
[1] | SQL Data Definition Language |
Extensions to SQLAlchemy for altering existing tables.
At the moment, this isn’t so much based off of ANSI as much as things that just happen to work with multiple databases.
Extends ANSI SQL dropper for column dropping (ALTER TABLE DROP COLUMN).
Drop a column from its table.
Parameters: | column (sqlalchemy.Column) – the column object |
---|
Extends ansisql generator for column creation (alter table add col)
Create a column (table already exists).
Parameters: | column (sqlalchemy.Column instance) – column object |
---|
Migrate’s constraints require a separate creation function from SA’s: Migrate’s constraints are created independently of a table; SA’s are created at the same time as the table.
Gets a name for the given constraint.
If the name is already set it will be used otherwise the constraint’s autoname method is used.
Parameters: | cons – constraint object |
---|
Manages changes to existing schema elements.
Note that columns are schema elements; ALTER TABLE ADD COLUMN is in SchemaGenerator.
All items may be renamed. Columns can also have many of their properties - type, for example - changed.
Each function is passed a tuple, containing (object, name); where object is a type of object you’d expect for that function (ie. table for visit_table) and name is the object’s new name. NONE means the name is unchanged.
Starts ALTER COLUMN
Rename/change a column.
Rename an index
Rename a table. Other ops aren’t supported.
Common operations for ALTER TABLE statements.
Append content to the SchemaIterator’s query buffer.
Execute the contents of the SchemaIterator’s buffer.
Returns the start of an ALTER TABLE SQL-Statement.
Use the param object to determine the table name and use it for building the SQL statement.
Parameters: | param (sqlalchemy.Column, sqlalchemy.Index, sqlalchemy.schema.Constraint, sqlalchemy.Table, or string (table name)) – object to determine the table from |
---|
This module defines standalone schema constraint classes.
Bases: migrate.changeset.constraint.ConstraintChangeset, sqlalchemy.sql.schema.CheckConstraint
Construct CheckConstraint
Migrate’s additional parameters:
Parameters: |
|
---|
Add a new kind of dialect-specific keyword argument for this class.
E.g.:
Index.argument_for("mydialect", "length", None)
some_index = Index('a', 'b', mydialect_length=5)
The DialectKWArgs.argument_for() method is a per-argument way adding extra arguments to the DefaultDialect.construct_arguments dictionary. This dictionary provides a list of argument names accepted by various schema-level constructs on behalf of a dialect.
New dialects should typically specify this dictionary all at once as a data member of the dialect class. The use case for ad-hoc addition of argument names is typically for end-user code that is also using a custom compilation scheme which consumes the additional arguments.
Parameters: |
|
---|
New in version 0.9.4.
Return True if this constraint contains the given column.
Note that this object also contains an attribute .columns which is a ColumnCollection of Column objects.
Create the constraint in the database.
Parameters: |
|
---|
Drop the constraint from the database.
Parameters: |
|
---|---|
Returns: | Instance with cleared columns |
used to allow SchemaVisitor access
A collection of keyword arguments specified as dialect-specific options to this construct.
The arguments are present here in their original <dialect>_<kwarg> format. Only arguments that were actually passed are included; unlike the DialectKWArgs.dialect_options collection, which contains all options known by this dialect including defaults.
The collection is also writable; keys are accepted of the form <dialect>_<kwarg> where the value will be assembled into the list of options.
New in version 0.9.2.
Changed in version 0.9.4: The DialectKWArgs.dialect_kwargs collection is now writable.
See also
DialectKWArgs.dialect_options - nested dictionary form
A collection of keyword arguments specified as dialect-specific options to this construct.
This is a two-level nested registry, keyed to <dialect_name> and <argument_name>. For example, the postgresql_where argument would be locatable as:
arg = my_object.dialect_options['postgresql']['where']
New in version 0.9.2.
See also
DialectKWArgs.dialect_kwargs - flat dictionary form
Info dictionary associated with the object, allowing user-defined data to be associated with this SchemaItem.
The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as Table and Column.
A synonym for DialectKWArgs.dialect_kwargs.
Return the value of the quote flag passed to this schema object, for those schema items which have a name field.
Deprecated since version 0.9: Use <obj>.name.quote
Bases: object
Base class for Constraint classes.
Create the constraint in the database.
Parameters: |
|
---|
Drop the constraint from the database.
Parameters: |
|
---|---|
Returns: | Instance with cleared columns |
Bases: migrate.changeset.constraint.ConstraintChangeset, sqlalchemy.sql.schema.ForeignKeyConstraint
Construct ForeignKeyConstraint
Migrate’s additional parameters:
Parameters: |
|
---|
Add a new kind of dialect-specific keyword argument for this class.
E.g.:
Index.argument_for("mydialect", "length", None)
some_index = Index('a', 'b', mydialect_length=5)
The DialectKWArgs.argument_for() method is a per-argument way adding extra arguments to the DefaultDialect.construct_arguments dictionary. This dictionary provides a list of argument names accepted by various schema-level constructs on behalf of a dialect.
New dialects should typically specify this dictionary all at once as a data member of the dialect class. The use case for ad-hoc addition of argument names is typically for end-user code that is also using a custom compilation scheme which consumes the additional arguments.
Parameters: |
|
---|
New in version 0.9.4.
Mimic the database’s automatic constraint names
Return True if this constraint contains the given column.
Note that this object also contains an attribute .columns which is a ColumnCollection of Column objects.
Create the constraint in the database.
Parameters: |
|
---|
Drop the constraint from the database.
Parameters: |
|
---|---|
Returns: | Instance with cleared columns |
used to allow SchemaVisitor access
Return a list of string keys representing the local columns in this ForeignKeyConstraint.
This list is either the original string arguments sent to the constructor of the ForeignKeyConstraint, or if the constraint has been initialized with Column objects, is the string .key of each element.
New in version 1.0.0.
A collection of keyword arguments specified as dialect-specific options to this construct.
The arguments are present here in their original <dialect>_<kwarg> format. Only arguments that were actually passed are included; unlike the DialectKWArgs.dialect_options collection, which contains all options known by this dialect including defaults.
The collection is also writable; keys are accepted of the form <dialect>_<kwarg> where the value will be assembled into the list of options.
New in version 0.9.2.
Changed in version 0.9.4: The DialectKWArgs.dialect_kwargs collection is now writable.
See also
DialectKWArgs.dialect_options - nested dictionary form
A collection of keyword arguments specified as dialect-specific options to this construct.
This is a two-level nested registry, keyed to <dialect_name> and <argument_name>. For example, the postgresql_where argument would be locatable as:
arg = my_object.dialect_options['postgresql']['where']
New in version 0.9.2.
See also
DialectKWArgs.dialect_kwargs - flat dictionary form
Info dictionary associated with the object, allowing user-defined data to be associated with this SchemaItem.
The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as Table and Column.
A synonym for DialectKWArgs.dialect_kwargs.
Return the value of the quote flag passed to this schema object, for those schema items which have a name field.
Deprecated since version 0.9: Use <obj>.name.quote
The Table object to which this ForeignKeyConstraint references.
This is a dynamically calculated attribute which may not be available if the constraint and/or parent table is not yet associated with a metadata collection that contains the referred table.
New in version 1.0.0.
Bases: migrate.changeset.constraint.ConstraintChangeset, sqlalchemy.sql.schema.PrimaryKeyConstraint
Construct PrimaryKeyConstraint
Migrate’s additional parameters:
Parameters: |
|
---|
Add a new kind of dialect-specific keyword argument for this class.
E.g.:
Index.argument_for("mydialect", "length", None)
some_index = Index('a', 'b', mydialect_length=5)
The DialectKWArgs.argument_for() method is a per-argument way adding extra arguments to the DefaultDialect.construct_arguments dictionary. This dictionary provides a list of argument names accepted by various schema-level constructs on behalf of a dialect.
New dialects should typically specify this dictionary all at once as a data member of the dialect class. The use case for ad-hoc addition of argument names is typically for end-user code that is also using a custom compilation scheme which consumes the additional arguments.
Parameters: |
|
---|
New in version 0.9.4.
Mimic the database’s automatic constraint names
Return True if this constraint contains the given column.
Note that this object also contains an attribute .columns which is a ColumnCollection of Column objects.
Create the constraint in the database.
Parameters: |
|
---|
Drop the constraint from the database.
Parameters: |
|
---|---|
Returns: | Instance with cleared columns |
used to allow SchemaVisitor access
A collection of keyword arguments specified as dialect-specific options to this construct.
The arguments are present here in their original <dialect>_<kwarg> format. Only arguments that were actually passed are included; unlike the DialectKWArgs.dialect_options collection, which contains all options known by this dialect including defaults.
The collection is also writable; keys are accepted of the form <dialect>_<kwarg> where the value will be assembled into the list of options.
New in version 0.9.2.
Changed in version 0.9.4: The DialectKWArgs.dialect_kwargs collection is now writable.
See also
DialectKWArgs.dialect_options - nested dictionary form
A collection of keyword arguments specified as dialect-specific options to this construct.
This is a two-level nested registry, keyed to <dialect_name> and <argument_name>. For example, the postgresql_where argument would be locatable as:
arg = my_object.dialect_options['postgresql']['where']
New in version 0.9.2.
See also
DialectKWArgs.dialect_kwargs - flat dictionary form
Info dictionary associated with the object, allowing user-defined data to be associated with this SchemaItem.
The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as Table and Column.
A synonym for DialectKWArgs.dialect_kwargs.
Return the value of the quote flag passed to this schema object, for those schema items which have a name field.
Deprecated since version 0.9: Use <obj>.name.quote
Bases: migrate.changeset.constraint.ConstraintChangeset, sqlalchemy.sql.schema.UniqueConstraint
Construct UniqueConstraint
Migrate’s additional parameters:
Parameters: |
|
---|
New in version 0.6.0.
Add a new kind of dialect-specific keyword argument for this class.
E.g.:
Index.argument_for("mydialect", "length", None)
some_index = Index('a', 'b', mydialect_length=5)
The DialectKWArgs.argument_for() method is a per-argument way adding extra arguments to the DefaultDialect.construct_arguments dictionary. This dictionary provides a list of argument names accepted by various schema-level constructs on behalf of a dialect.
New dialects should typically specify this dictionary all at once as a data member of the dialect class. The use case for ad-hoc addition of argument names is typically for end-user code that is also using a custom compilation scheme which consumes the additional arguments.
Parameters: |
|
---|
New in version 0.9.4.
Mimic the database’s automatic constraint names
Return True if this constraint contains the given column.
Note that this object also contains an attribute .columns which is a ColumnCollection of Column objects.
Create the constraint in the database.
Parameters: |
|
---|
Drop the constraint from the database.
Parameters: |
|
---|---|
Returns: | Instance with cleared columns |
used to allow SchemaVisitor access
A collection of keyword arguments specified as dialect-specific options to this construct.
The arguments are present here in their original <dialect>_<kwarg> format. Only arguments that were actually passed are included; unlike the DialectKWArgs.dialect_options collection, which contains all options known by this dialect including defaults.
The collection is also writable; keys are accepted of the form <dialect>_<kwarg> where the value will be assembled into the list of options.
New in version 0.9.2.
Changed in version 0.9.4: The DialectKWArgs.dialect_kwargs collection is now writable.
See also
DialectKWArgs.dialect_options - nested dictionary form
A collection of keyword arguments specified as dialect-specific options to this construct.
This is a two-level nested registry, keyed to <dialect_name> and <argument_name>. For example, the postgresql_where argument would be locatable as:
arg = my_object.dialect_options['postgresql']['where']
New in version 0.9.2.
See also
DialectKWArgs.dialect_kwargs - flat dictionary form
Info dictionary associated with the object, allowing user-defined data to be associated with this SchemaItem.
The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as Table and Column.
A synonym for DialectKWArgs.dialect_kwargs.
Return the value of the quote flag passed to this schema object, for those schema items which have a name field.
Deprecated since version 0.9: Use <obj>.name.quote
This module contains database dialect specific changeset implementations.
Firebird database specific implementations of changeset classes.
Firebird column dropper implementation.
Firebird supports ‘DROP col’ instead of ‘DROP COLUMN col’ syntax
Drop primary key and unique constraints if dropped column is referencing it.
Firebird column generator implementation.
Firebird constaint dropper implementation.
Cascading constraints is not supported
Firebird constraint generator implementation.
PostgreSQL database specific implementations of changeset classes.
PostgreSQL column dropper implementation.
PostgreSQL column generator implementation.
PostgreSQL constaint dropper implementation.
PostgreSQL constraint generator implementation.
PostgreSQL schema changer implementation.
SQLite database specific implementations of changeset classes.
SQLite ColumnDropper
SQLite ColumnGenerator
Module for visitor class mapping.
Get the visitor implementation for the given dialect.
Finds the visitor implementation based on the dialect class and returns and instance initialized with the given name.
Binds dialect specific preparer to visitor.
Get the visitor implementation for the given database engine.
Parameters: |
|
---|---|
Returns: | visitor |
Taken from sqlalchemy.engine.base.Engine._run_single_visitor() with support for migrate visitors.
Schema module providing common schema operations.
Create a column, given the table.
API to ChangesetColumn.create().
Drop a column, given the table.
API to ChangesetColumn.drop().
Alter a column.
This is a helper function that creates a ColumnDelta and runs it.
Parameters: |
|
---|---|
Returns: | A ColumnDelta instance representing the change. |
Rename a table.
If Table instance is given, engine is not used.
API to ChangesetTable.rename().
Parameters: |
|
---|
Rename an index.
If Index instance is given, table and engine are not used.
API to ChangesetIndex.rename().
Parameters: |
|
---|
Changeset extensions to SQLAlchemy tables.
Creates a column.
The column parameter may be a column definition or the name of a column in this table.
API to ChangesetColumn.create()
Parameters: | column (Column instance or string) – Column to be created |
---|
Remove this table from its metadata
Drop a column, given its name or definition.
API to ChangesetColumn.drop()
Parameters: | column (Column instance or string) – Column to be droped |
---|
Rename this table.
Parameters: |
|
---|
Changeset extensions to SQLAlchemy columns.
Makes a call to alter_column() for the column this method is called on.
Create a copy of this Column, with all attributes.
Create this column in the database.
Assumes the given table exists. ALTER TABLE ADD COLUMN, for most databases.
Parameters: |
|
---|---|
Returns: | self |
Drop this column from the database, leaving its table intact.
ALTER TABLE DROP COLUMN, for most databases.
Parameters: | connection (sqlalchemy.engine.base.Connection instance) – reuse connection istead of creating new one. |
---|
Changeset extensions to SQLAlchemy Indexes.
Change the name of an index.
Parameters: |
|
---|
Implements comparison between DefaultClause instances
Extracts the differences between two columns/column-parameters
May receive parameters arranged in several different ways:
Additional parameters can be specified to override column differences.
Additional parameters alter current_column. Table name is extracted from current_column object. Name is changed to current_column.name from current_name, if current_name is specified.
Table kw must specified.
Parameters: |
|
---|---|
Returns: | ColumnDelta instance provides interface for altered attributes to result_column through dict() alike object. |
Populate dict and column object with new values
Compares two types to be equal
Compares one Column object
Compares two Column objects
Compares Column objects with reflection
Processes default values for column
This package provides functionality to create and manage repositories of database schema changesets and to apply these changesets to databases.
Code to generate a Python model from a database or differences between a model and database.
Some of this is borrowed heavily from the AutoCode project at: http://code.google.com/p/sqlautocode/
Various transformations from an A, B diff.
In the implementation, A tends to be called the model and B the database (although this is not true of all diffs). The diff is directionless, but transformations apply the diff in a particular direction, described in the method name.
Generate a migration from B to A.
Was: toUpgradeDowngradePython Assume model (A) is most current and database (B) is out-of-date.
Generates the source code for a definition of B.
Assumes a diff where A is empty.
Was: toPython. Assume database (B) is current and model (A) is empty.
Goes from B to A.
Was: applyModel. Apply model (A) to current database (B).
A path/directory class.
A class associated with a path/directory tree.
Only one instance of this class may exist for a particular file; __new__ will return an existing instance if possible
Ensures a given path already exists
Ensures a given path does not already exist
Schema differencing support.
Container for differences in one Column between two Table instances, A and B.
The Column object for A.
The Column object for B.
The most generic type of the Column object in A.
The most generic type of the Column object in A.
Compute the difference between two MetaData objects.
The string representation of a SchemaDiff will summarise the changes found between the two MetaData objects.
The length of a SchemaDiff will give the number of changes found, enabling it to be used much like a boolean in expressions.
Parameters: |
|
---|
A sequence of table names that were found in B but weren’t in A.
A sequence of table names that were found in A but weren’t in B.
Container for differences in one Table between two MetaData instances, A and B.
A sequence of column names that were found in B but weren’t in A.
A sequence of column names that were found in A but weren’t in B.
Return differences of model against database.
Returns: | object which will evaluate to True if there are differences else False. |
---|
Return differences of model against another model.
Returns: | object which will evaluate to True if there are differences else False. |
---|
Memoize(fn) - an instance which acts like fn but memoizes its arguments Will only work on functions with non-mutable arguments
ActiveState Code 52201
Do everything to use object as bool
Decorator that catches known api errors
New in version 0.5.4.
Constructs and returns SQLAlchemy engine.
Currently, there are 2 ways to pass create_engine options to migrate.versioning.api functions:
Parameters: |
|
---|---|
Returns: | SQLAlchemy Engine |
Note
keyword parameters override engine_dict values.
Do everything to guess object type from string
Tries to convert to int, bool and finally returns if not succeded.
Import module and use module-level variable”.
Parameters: | dotted_name – path to model in form of string: some.python.module:Class |
---|
Changed in version 0.5.4.
Decorator for migrate.versioning.api functions to safely close resources after function usage.
Passes engine parameters to construct_engine() and resulting parameter is available as kw[‘engine’].
Engine is disposed after wrapped function is executed.
Provide exception classes for migrate
Base class for API errors.
Base class for controlled schema errors.
Database shouldn’t be under version control, but it is
Database should be under version control, but it’s not.
Error base class.
Invalid constraint error
Invalid repository error.
Invalid script error.
Invalid version error.
A known error condition.
Warning for deprecated features in Migrate
The table does not exist.
Not supported error
Base class for path errors.
A path with a file was required; found no file.
A path with no file was required; found a file.
Base class for repository errors.
Base class for script errors.
A known error condition where help should be displayed.
This database is under version control by another repository.