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.
| Parameter: | column (sqlalchemy.Column) – the column object |
|---|
Extends ansisql generator for column creation (alter table add col)
Create a column (table already exists).
| Parameter: | column (sqlalchemy.Column) – column object |
|---|
Default table visitor, does nothing.
| Parameter: | table (sqlalchemy.Table) – table 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.
| Parameter: | cons (migrate.changeset.constraint.ConstraintChangeset) – constraint object |
|---|
Extends ansisql generator for column creation (alter table add col)
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.
Common operations for ALTER TABLE statements.
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 |
|---|
This module defines standalone schema constraint classes.
Base class for Constraint classes.
| Raises: | NotImplementedError if this method is not overridden by a subclass |
|---|
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 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 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 |
|---|
This module contains database dialect specific changeset implementations.
MySQL database specific implementations of changeset classes.
Oracle database specific implementations of changeset classes.
PostgreSQL database specific implementations of changeset classes.
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.
This module provides exception classes.
Schema module providing common schema operations.
Alter a column.
Parameters: column name, table name, an engine, and the properties of that column to change
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.
This package provides functionality to create and manage repositories of database schema changesets and to apply these changesets to databases.
This module provides an external API to the versioning system.
Changed in version 0.4.5: --preview_sql displays source file when using SQL scripts. If Python script is used, it runs the action with mocked engine and returns captured SQL statements.
Changed in version 0.4.5: Deprecated --echo parameter in favour of new migrate.versioning.util.construct_engine() behavior.
%prog help COMMAND
Displays help on a given command.
%prog create REPOSITORY_PATH NAME [–table=TABLE]
Create an empty repository at the specified path.
You can specify the version_table to be used; by default, it is ‘migrate_version’. This table is created in all version-controlled databases.
%prog script [–repository=REPOSITORY_PATH] DESCRIPTION
Create an empty change script using the next unused version number appended with the given description.
For instance, manage.py script “Add initial tables” creates: repository/versions/001_Add_initial_tables.py
%prog script_sql [–repository=REPOSITORY_PATH] DATABASE
Create empty change SQL scripts for given DATABASE, where DATABASE is either specific (‘postgres’, ‘mysql’, ‘oracle’, ‘sqlite’, etc.) or generic (‘default’).
For instance, manage.py script_sql postgres creates: repository/versions/001_postgres_upgrade.sql and repository/versions/001_postgres_postgres.sql
%prog make_update_script_for_model URL OLDMODEL MODEL REPOSITORY_PATH
Create a script changing the old Python model to the new (current) Python model, sending to stdout.
NOTE: This is EXPERIMENTAL.
%prog version REPOSITORY_PATH
Display the latest version available in a repository.
%prog source VERSION [DESTINATION] –repository=REPOSITORY_PATH
Display the Python code for a particular version in this repository. Save it to the file at DESTINATION or, if omitted, send to stdout.
%prog version_control URL REPOSITORY_PATH [VERSION]
Mark a database as under this repository’s version control.
Once a database is under version control, schema changes should only be done via change scripts in this repository.
This creates the table version_table in the database.
The url should be any valid SQLAlchemy connection string.
By default, the database begins at version 0 and is assumed to be empty. If the database is not empty, you may specify a version at which to begin instead. No attempt is made to verify this version’s correctness - the database schema is expected to be identical to what it would be if the database were created from scratch.
%prog db_version URL REPOSITORY_PATH
Show the current version of the repository with the given connection string, under version control of the specified repository.
The url should be any valid SQLAlchemy connection string.
%prog upgrade URL REPOSITORY_PATH [VERSION] [–preview_py|–preview_sql]
Upgrade a database to a later version.
This runs the upgrade() function defined in your change scripts.
By default, the database is updated to the latest available version. You may specify a version instead, if you wish.
You may preview the Python or SQL code to be executed, rather than actually executing it, using the appropriate ‘preview’ option.
%prog downgrade URL REPOSITORY_PATH VERSION [–preview_py|–preview_sql]
Downgrade a database to an earlier version.
This is the reverse of upgrade; this runs the downgrade() function defined in your change scripts.
You may preview the Python or SQL code to be executed, rather than actually executing it, using the appropriate ‘preview’ option.
%prog drop_version_control URL REPOSITORY_PATH
Removes version control from a database.
%prog manage FILENAME VARIABLES...
Creates a script that runs Migrate with a set of default values.
For example:
%prog manage manage.py --repository=/path/to/repository --url=sqlite:///project.db
would create the script manage.py. The following two commands would then have exactly the same results:
python manage.py version
%prog version --repository=/path/to/repository
%prog test REPOSITORY_PATH URL [VERSION]
Performs the upgrade and downgrade option on the given database. This is not a real test and may leave the database in a bad state. You should therefore better run the test on a copy of your database.
%prog compare_model_to_db URL MODEL REPOSITORY_PATH
Compare the current model (assumed to be a module level variable of type sqlalchemy.MetaData) against the current database.
NOTE: This is EXPERIMENTAL.
%prog create_model URL REPOSITORY_PATH
Dump the current database as a Python model to stdout.
NOTE: This is EXPERIMENTAL.
%prog update_db_from_model URL MODEL REPOSITORY_PATH
Modify the database to match the structure of the current Python model. This also sets the db_version number to the latest in the repository.
NOTE: This is EXPERIMENTAL.
Provide exception classes for migrate.versioning
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/
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
SQLAlchemy migrate repository management.
A collection of changes to be applied to a database.
Changesets are bound to a repository and manage a set of logsql scripts from that repository.
Behaves like a dict, for the most part. Keys are ordered based on start/end.
A project’s change script repository
Ensure the target path is a valid repository.
| Raises: | InvalidRepositoryError if not valid |
|---|
Database schema version management.
A database under version control
The migrate command-line tool.
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: |
|
|---|
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”.
| Parameter: | dotted_name – path to model in form of string: some.python.module:Class |
|---|
Changed in version 0.5.4.
Schema differencing support.
Differences of model against database.
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. |
|---|