API Documentation

Module migrate.changeset

This module extends SQLAlchemy and provides additional DDL [1] support.

[1]SQL Data Definition Language

Module ansisql

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.

class migrate.changeset.ansisql.ANSIColumnDropper(connection)

Extends ANSI SQL dropper for column dropping (ALTER TABLE DROP COLUMN).

visit_column(column)

Drop a column from its table.

Parameter:column (sqlalchemy.Column) – the column object
class migrate.changeset.ansisql.ANSIColumnGenerator(dialect, connection, checkfirst=False, tables=None, **kwargs)

Extends ansisql generator for column creation (alter table add col)

visit_column(column)

Create a column (table already exists).

Parameter:column (sqlalchemy.Column) – column object
visit_table(table)

Default table visitor, does nothing.

Parameter:table (sqlalchemy.Table) – table object
class migrate.changeset.ansisql.ANSIConstraintCommon(connection)

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.

get_constraint_name(cons)

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.

Parameter:cons (migrate.changeset.constraint.ConstraintChangeset) – constraint object
class migrate.changeset.ansisql.ANSIFKGenerator(*args, **kwargs)

Extends ansisql generator for column creation (alter table add col)

visit_column(column)
Create foreign keys for a column (table already exists); #32
class migrate.changeset.ansisql.ANSISchemaChanger(dialect, connection, checkfirst=False, tables=None, **kwargs)

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.

visit_column(delta)
Rename/change a column.
visit_index(param)
Rename an index; #36
visit_table(param)
Rename a table. Other ops aren’t supported.
class migrate.changeset.ansisql.AlterTableVisitor(connection)
Common operations for ALTER TABLE statements
class migrate.changeset.ansisql.RawAlterTableVisitor

Common operations for ALTER TABLE statements.

start_alter_table(param)

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.

Parameter:param (sqlalchemy.Column, sqlalchemy.Index, sqlalchemy.schema.Constraint, sqlalchemy.Table, or string (table name)) – object to determine the table from

Module constraint

This module defines standalone schema constraint classes.

class migrate.changeset.constraint.CheckConstraint(sqltext, *args, **kwargs)
Check constraint class.
class migrate.changeset.constraint.ConstraintChangeset

Base class for Constraint classes.

accept_schema_visitor(visitor, *p, **k)
Raises:NotImplementedError if this method is not overridden by a subclass
autoname()

Automatically generate a name for the constraint instance.

Subclasses must implement this method.

Raises:NotImplementedError if this method is not overridden by a subclass
create(engine=None)

Create the constraint in the database.

Parameter:engine (sqlalchemy.engine.base.Engine) – the database engine to use. If this is None the instance’s engine will be used
drop(engine=None)

Drop the constraint from the database.

Parameter:engine (sqlalchemy.engine.base.Engine) – the database engine to use. If this is None the instance’s engine will be used
class migrate.changeset.constraint.ForeignKeyConstraint(columns, refcolumns, *p, **k)

Foreign key constraint class.

autoname()
Mimic the database’s automatic constraint names
class migrate.changeset.constraint.PrimaryKeyConstraint(*cols, **kwargs)

Primary key constraint class.

autoname()
Mimic the database’s automatic constraint names

Module databases

This module contains database dialect specific changeset implementations.

Module mysql

MySQL database specific implementations of changeset classes.

Module oracle

Oracle database specific implementations of changeset classes.

Module postgres

PostgreSQL database specific implementations of changeset classes.

class migrate.changeset.databases.postgres.PGColumnDropper(connection)
PostgreSQL column dropper implementation.
class migrate.changeset.databases.postgres.PGColumnGenerator(dialect, connection, checkfirst=False, tables=None, **kwargs)
PostgreSQL column generator implementation.
class migrate.changeset.databases.postgres.PGConstraintDropper(connection)
PostgreSQL constaint dropper implementation.
class migrate.changeset.databases.postgres.PGConstraintGenerator(connection)
PostgreSQL constraint generator implementation.
class migrate.changeset.databases.postgres.PGSchemaChanger(dialect, connection, checkfirst=False, tables=None, **kwargs)
PostgreSQL schema changer implementation.
class migrate.changeset.databases.postgres.PGSchemaGeneratorMixin
Common code used by the PostgreSQL specific classes.

Module sqlite

SQLite database specific implementations of changeset classes.

Module visitor

Module for visitor class mapping.

migrate.changeset.databases.visitor.get_dialect_visitor(sa_dialect, name)

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.

migrate.changeset.databases.visitor.get_engine_visitor(engine, name)
Get the visitor implementation for the given database engine.

Module exceptions

This module provides exception classes.

exception migrate.changeset.exceptions.Error
Changeset error.
exception migrate.changeset.exceptions.InvalidConstraintError
Invalid constraint error.
exception migrate.changeset.exceptions.NotSupportedError
Not supported error.

Module schema

Schema module providing common schema operations.

migrate.changeset.schema.alter_column(*p, **k)

Alter a column.

Parameters: column name, table name, an engine, and the properties of that column to change

migrate.changeset.schema.rename_table(table, name, engine=None)
Rename a table, given the table’s current name and the new name.
migrate.changeset.schema.rename_index(index, name, table=None, engine=None)

Rename an index.

Takes an index name/object, a table name/object, and an engine. Engine and table aren’t required if an index object is given.

Module migrate.versioning

This package provides functionality to create and manage repositories of database schema changesets and to apply these changesets to databases.

Module api

Module exceptions

Provide exception classes for migrate.versioning

exception migrate.versioning.exceptions.ApiError
Base class for API errors.
exception migrate.versioning.exceptions.ControlledSchemaError
Base class for controlled schema errors.
exception migrate.versioning.exceptions.DatabaseAlreadyControlledError
Database shouldn’t be under version control, but it is
exception migrate.versioning.exceptions.DatabaseNotControlledError
Database should be under version control, but it’s not.
exception migrate.versioning.exceptions.Error
Error base class.
exception migrate.versioning.exceptions.InvalidRepositoryError
Invalid repository error.
exception migrate.versioning.exceptions.InvalidScriptError
Invalid script error.
exception migrate.versioning.exceptions.InvalidVersionError
Invalid version error.
exception migrate.versioning.exceptions.KnownError
A known error condition.
exception migrate.versioning.exceptions.NoSuchTableError
The table does not exist.
exception migrate.versioning.exceptions.PathError
Base class for path errors.
exception migrate.versioning.exceptions.PathFoundError
A path with a file was required; found no file.
exception migrate.versioning.exceptions.PathNotFoundError
A path with no file was required; found a file.
exception migrate.versioning.exceptions.RepositoryError
Base class for repository errors.
exception migrate.versioning.exceptions.ScriptError
Base class for script errors.
exception migrate.versioning.exceptions.UsageError
A known error condition where help should be displayed.
exception migrate.versioning.exceptions.WrongRepositoryError
This database is under version control by another repository.

Module genmodel

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/

Module pathed

Module repository

Module schema

Module shell

Module util

Module schemadiff

Schema differencing support.

class migrate.versioning.schemadiff.SchemaDiff(model, conn, excludeTables=None, oldmodel=None)

Differences of model against database.

compareModelToDatabase()
Do actual comparison.
migrate.versioning.schemadiff.getDiffOfModelAgainstDatabase(model, conn, excludeTables=None)

Return differences of model against database.

Returns:object which will evaluate to True if there are differences else False.
migrate.versioning.schemadiff.getDiffOfModelAgainstModel(oldmodel, model, conn, excludeTables=None)

Return differences of model against another model.

Returns:object which will evaluate to True if there are differences else False.