118 Commits

Author SHA1 Message Date
Mike Bayer
971b9e62df Use engine.connect(); don't use private _run_visitor method
SQLAlchemy 1.3 has deprecated engine.contextual_connect() which
will be removed in 1.4.   Additionally, private methods like
Engine._run_visitor will also be removed.

Change-Id: I319785d7dd83ffe2c6e651a2494b073becc84684
2019-07-16 09:39:49 -04:00
Zuul
f0664995a1 Merge "Import MutableMapping from the correct Python module" 2019-01-21 22:17:29 +00:00
Zuul
6803334bb1 Merge "Don't use deprecated / non-functional "force" parameter" 2019-01-21 22:13:03 +00:00
Mike Bayer
fe64667106 Don't use deprecated / non-functional "force" parameter
The "force" parameter in SQLAlchemy IdentifierPreparer.quote()
has been a no-op since 0.9 in
031ef08078,
which was six years ago.   In SQLAlchemy 1.3 this parameter
will be removed entirely.   Bump requirements to 0.9 series
here and remove usage of the "force" flag.

Change-Id: I4492df2e7d2075fefbf13d6782de11f7d402f6b8
2019-01-18 13:11:40 -05:00
Corey Bryant
231a4d2ae9 Use legacy_alter_table ON in sqlite recreate_table
Use "PRAGMA legacy_alter_table = ON" with sqlite >= 3.26 when
using "ALTER TABLE RENAME TO migration_tmp" to maintain legacy
behavior.

As of sqlite version 3.26, when a table is renamed using
"ALTER TABLE RENAME TO", REFERENCES clauses that refer to the
table will be updated. To maintain legacy (3.24 and earlier)
behavior, "PRAGMA legacy_alter_table" can be set to true and
"PRAGMA foreign_keys" can be set to false. [1]

[1] https://www.sqlite.org/src/info/ae9638e9c0ad0c36

Thanks to "László Böszörményi (GCS)" <gcs@debian.org> for
providing the code for this patch, which has since been
slightly modified.

Change-Id: I539988ab2ad6df6c8f423ecec15364ad8fcc7267
Closes-Bug: 1807262
2019-01-15 22:01:26 +00:00
Chih-Hsuan Yen
a00dab7bcf Import MutableMapping from the correct Python module
Change-Id: Ifb66fe22bc607b13f5c4756d3b93f5e8206c33e3
2019-01-15 18:16:06 +00:00
Mike Bayer
e9175a37ce Set autoincrement to False when modifying to non-Integer datatype
Starting in SQLAlchemy 1.1, the rules for when "autoincrement=True"
may be set on a column are more strict.  The migrate tests are
testing the alteration of a column from Integer to String
and then regenerating; this means we need to set autoincrement
to False as well.   A related issue in SQLAlchemy 1.1 is
also being fixed (see https://bitbucket.org/zzzeek/sqlalchemy/issues/3835/),
however this fix is not needed in order for the tests to pass here.

Change-Id: Ibd3a75fff13312411df87e17b6e5764865d69728
2016-10-20 17:47:19 -04:00
Mike Bayer
a94dae7a01 Update tests and reqs for SQLA 1.0
Lift the requirements to support SQLAlchemy 1.0.  Two tests
were calling upon revised APIs and required adjustment.

Change-Id: Ic91a91bb3c915027b522eace302f2ed074233294
2015-07-01 20:01:52 +00:00
Qin Zhao
e57ee4c3a4 Fix ibmdb2 index name handling
The ibmdb2 code calls _index_identifier() when it handles index name. This
method only exists from sqlalchemy 0.6.5 to 0.7.*. Nova code change
https://review.openstack.org/#/c/153123/ attempts to drop a db constraint and
it fails to sync nova db with sqlalchemy 0.9.8 running against db2. Need to let
ibmdb2 code identify sqlalchemy version and call the correct method to handle
index name.

Closes-Bug: 1428477

Change-Id: Ie6333f9cea0209c1ea290356873a1a1bcf409bed
2015-03-16 15:21:03 +00:00
Matt Riedemann
ae64d828df allow dropping fkeys with sqlite
This implements the ability to drop foreign keys
with sqlite. It's basically the same implementation
used for dropping unique constraints so the common
code is refactored.

The existing FKey test that was skipping sqlite is
no longer skipped to show this works.

Change-Id: Idaaf4229e34af4c21c3bcead4b4e22491d24238e
Closes-Bug: #1423955
2015-02-20 10:04:35 -08:00
Rahul Priyadarshi
74553f426c Use native sqlalchemy 0.9 quote attribute with ibmdb2
Commit 8d6ce64cd08c0598963a92844495782997cd59f3 started using the native
quote attribute built into sqlalchemy 0.9 but missed the changes to the
ibmdb2 changeset, so alter table statements fail for DB2 on sqlalchemy
>= 0.9 (tested against 0.9.8).

This fixes the same issue for the ibmdb2 changeset.

Change-Id: Ia3fa6c3090b5eab29ed7746f4795d502990b8a2f
2015-01-09 14:31:28 -08:00
Brant Knudson
244c6c55d7 Don't add warnings filter on import
The changeset module was adding a warnings filter on import. This
affects all applications that wind up importing it. A library
shouldn't modify the warnings filters unless asked.

Closes-Bug: #1407736
Change-Id: I893f8be48efd3d3642e977ab587c9e6dc867258b
2015-01-08 16:22:59 -06:00
Matt Riedemann
7bb74f70e9 Fix ibmdb2 unique constraint handling for sqlalchemy 0.9
The ibmdb2 unique constraint code was accessing the private _all_cols
member var in iterating over columns which breaks in sqlalchemy 0.9 so
fix up the code to not use internals of sqlalchemy.

UniqueConstraint in sqlalchemy extends ColumnCollectionConstraint
which implements __iter__ to generate a tuple of the columns in
the constraint, so we just iterate over the constraint as the fix.

This is based on a patch from Rahul Priyadarshi in ibm-db-sa issue
158:

https://code.google.com/p/ibm-db/issues/detail?id=158

Co-Authored-By: Rahul Priyadarshi <rahul.priyadarshi@in.ibm.com>

Change-Id: I0f06f6314c382e83573d762abe5981db0a02a83a
2014-08-04 07:34:08 -07:00
Jenkins
942e03b2b1 Merge "Fix 3 files with Windows line endings to Unix line endings." 2014-07-22 21:48:39 +00:00
Jenkins
089663761c Merge "Move patch from oslo to drop unique constraints with sqlite" 2014-05-05 15:15:03 +00:00
Matt Riedemann
93efb62fd1 Move patch from oslo to drop unique constraints with sqlite
oslo-incubator commit 3f503faac for making sqlite work with dropping
unique constraints in database migrations. This was made in
oslo-incubator since at the time sqlalchemy-migrate was not in
stackforge. Now that we can update sqlalchemy-migrate, move the patch
over from oslo.

This change also adds the support for the case that a unique constraint
is dropped because the column it's on is dropped.

Note that there are already unit tests that cover dropping a unique
constraint directly and implicitly via dropping a column that is in
the unique constraint.

Related-Bug: #1307266

Change-Id: I5ee8082a83aebf66f6e1dacb093ed79e13f73f5e
2014-04-15 19:22:03 -07:00
Cyril Roelandt
a03b141a95 Port to Python3
Brief summary of the modifications:

* Use six for compatibility with both Python 2 and 3;
* Replace UserDict.DictMixin with collections.MutableMapping;
* Fix relative imports;
* Use test-requirements.txt for requirements that are common to both Python 2
  and 3, and test-requirements-py{2,3}.txt for version-specific requirements;
* Miscellaneous fixes.
* Use a specific test_db_py3.cfg file for Python 3, that only runs tests on
  sqlite.

Thanks to Victor Stinner who co-wrote this patch.

Change-Id: Ia6dc536c39d274924c21fd5bb619e8e5721e04c4
Co-Authored-By: Victor Stinner <victor.stinner@enovance.com>
2014-04-09 17:32:52 +02:00
Jenkins
e20068490b Merge "Eradicate trailing whitespace" 2014-03-29 18:27:33 +00:00
Thomas Goirand
7161cf2c9e Replace AbstractType by TypeEngine
AbstractType not longer exists in the class  hierarchy for types.
TypeEngine was its direct descendant, so use that instead.

Change-Id: Idbfaee4b0d3acbc4795913ddf2ab4e1c9b6d065c
2014-03-05 08:20:54 -05:00
Thomas Goirand
8d6ce64cd0 Use native quote attribute introduced in sqla 0.9
In SQLA 0.9 there is now a native .quote attribute on many objects.
Conditionally use this instead of the old method if the attribute
exists, to remove deprecation messages (and prepare for when the
other way will be fully removed).

Change-Id: I3c5fada13e044c1c4102acc0455226ce1524f2e2
2014-03-05 08:20:49 -05:00
Jenkins
0ffaaae935 Merge "UniqueConstraint named and escaped twice" 2014-03-05 08:46:17 +00:00
Matt Riedemann
12a6bcfa8c Conditionally import ibmdb2/ibm_db_sa
Since ibm_db_sa is not part of sqlalchemy, we need to handle the
conditional import of the module in visitor.py so we don't get an
ImportError if ibm_db_sa is not available.

Closes-Bug: #1287229

Change-Id: Ida070b629ce3b9be727ae49973bb6a71543c1dcf
2014-03-04 10:12:40 -08:00
Thomas Goirand
98ae3ac832 UniqueConstraint named and escaped twice
This patch fixes get_constraint_name in the
ANSIConstraintCommon class. It's part of the
fixes needed for SQLA 0.9.x compat.

Change-Id: I1f1648af48f459bd18f99bb42fa9a272186fb37d
2014-03-02 13:12:45 +08:00
David Ripton
6502d4017a Fix 3 files with Windows line endings to Unix line endings.
Change-Id: Iadc8e5d195bf998a117da4b7102a8955e238dd4e
2014-02-27 10:32:17 -05:00
David Ripton
d6fbf12989 Eradicate trailing whitespace
Remove all trailing spaces and tabs in every file in the project.
People have editors configured to do this, which causes them to
accidentally make little whitespace changes in unrelated commits,
which makes those commits harder to review.  Better to fix them all
at once.

Change-Id: I17d89f55f41d8599e0ab1a31f646cd161289703e
2014-02-26 15:04:54 -05:00
Matt Riedemann
85317aead6 Add DB2 10.5 Support
This patch adds the initial support for DB2 10.5 to migrate. It
includes:

1. The dialect implementation for DB2.
2. The dialect registration with the visitor.
3. Code to parse the engine name in version.py.
4. A new dependency on ibm_db_sa in test-requirements.txt.
5. A connection string in test_db.cfg for ibm_db_sa.

Part of blueprint add-db2-support

Co-authored-by: Sheng Bo Hou <sbhou@cn.ibm.com>
Co-authored-by: Thuy Christenson <thuy@us.ibm.com>
Co-authored-by: Rahul Priyadarshi <rahul.priyadarshi@in.ibm.com>
Change-Id: I745ec615487b1b06c5d1a09ea316f376d66ee4c0
2014-02-17 07:17:31 -08:00
Roman Podolyaka
2485118c24 Fix dropping of indexed columns in sqlite/sa08
Version 0.8 of SQLAlchemy added support of indexes
on expressions in addition to plain table columns,
which changed the way indexes are created.

This broke support of dropping columns of composite
indexes for SQLite: due to limitations of ALTER in
SQLite every time a column is dropped, we recreate
the whole table without the given column; if a
column is a part of a composite index, we change the
index definition to omit that column and then indexes
are recreated too.

SQLAlchemy versions starting from 0.8 no more pay
attention to 'columns' attribute of Index instances
when generating DDL for indexes, so when one of columns
of a composite index is dropped, we try to create a
new index on the column that doesn't exist anymore,
which of course fails.

Closes-Bug: #1241038

Change-Id: I777b8ce36e36f49bfb0889908811a063cf1a527b
2013-10-18 16:09:16 +03:00
Pádraig Brady
5c646eb558 decouple index name generation from sqlalchemy version
In commit 0.7.2-16-gc670d1d the _index_identifier() implementation
was copied from sqlalchemy, as that function was renamed
in sqlalchemy 0.8.  Instead handle call the renamed function
when appropriate, to decouple ourselves from the sqlalchemy
implementation.

Change-Id: I97b22c20d96758fc5b6bd55318218edb26c5b5d0
2013-09-23 15:18:59 +01:00
Josip Delic
c670d1d36a added bugfixes for 0.8 2013-07-11 17:07:04 -04:00
Jan Dittberner
a48190c006 merge e5bd2821eea8 from https://code.google.com/r/alyazdi-patches/
(fixes issue 125)
2011-10-28 12:25:22 +02:00
Jan Dittberner
3619347441 drop SQLAlchemy < 0.6 compatibility code 2011-10-28 10:59:10 +02:00
Jan Dittberner
95a329b16a fix SQLAlchemy 0.6.x compatibility of issue 128 patch 2011-10-28 10:06:19 +02:00
markbmc@gmail.com
6ecf665f14 fix issue 128: "table rename failure with sqlalchemy 0.7.x" 2011-10-28 09:34:08 +02:00
al.yazdi@gmail.com
cef7676b58 Fix for issue #125, create the table on the same connection as the ALTER and INSERT happen 2011-10-26 06:32:59 +00:00
Jan Dittberner
ca5d59910a fix column.create() properly 2011-05-27 21:59:35 +02:00
Jan Dittberner
27e24c3374 no special treatment for SQLA 0.7 required in migrate.changeset.ansisql 2011-05-27 12:55:11 +02:00
Jan Dittberner
108f28ae6b remove commented code 2011-05-26 21:56:11 +02:00
Jan Dittberner
1af477e661 fix unit test for adding new columns with foreign keys 2011-05-26 21:43:27 +02:00
Jan Dittberner
e11a9e5cba use Table._columns to remove columns (addresses #112)
- add SQLA_07 predicate in migrate/changeset/__init__.py

- use Table._columns instead of Table.c when removing columns in
  migrate/changeset/schema.py
2011-05-25 15:29:28 +02:00
Chris Withers
0645c2fc9a Bring back alter_metadata on ColumnDelta: it seems intertwined with a lot of the tests.
So, it's a private API now...
2011-02-11 10:27:39 +00:00
Chris Withers
cda65c38b5 try to get firebird stuff working with 0.6.6 2011-02-10 17:02:42 +00:00
Chris Withers
b5a02cb7cf remove the alter_metadata feature 2011-02-10 16:49:20 +00:00
Chris Withers
c80120da55 work around firebird's insistence that indexes and constraints are dropped before columns that are references by them. 2011-02-10 15:19:00 +00:00
Chris Withers
500cb6f5df fix sqlite column dropper now that the table is only modified after the visitor is run 2011-02-10 15:17:28 +00:00
Chris Withers
9c9fe2fc24 Only alter the SA objects after running the visitor, so the visitor may inspect 2011-02-10 15:15:22 +00:00
Jan Dittberner
05e39b2c6c make migrate.changeset.constraint.ForeignKeyConstraint.autoname work
with SQLAlchemy 0.5 and 0.6
2010-11-09 22:33:20 +01:00
Jan Dittberner
a3ae4baa29 use _index_identifier instead of _validate_identifier if
_validate_identifier does not exist in migrate/changeset/ansisql.py

remove executable bits from migrate/tests/fixture/warnings.py
2010-11-09 21:38:17 +01:00
Jan Dittberner
73796f3e54 fix generation of foreign key constraint name in
migrate.changeset.constraint.ForeignKeyConstraint.autoname

use <table>_<firstcol>_fkey instead of <table>_<reftable>_fkey

Fixes Issue 101
2010-11-07 22:19:36 +01:00
chrisw
adf4113a0b Fix issue 94 - it was impossible to add a column with a non-unique index.
Also implement more functionality with unique and foreign key constrains for sqlite.
2010-09-09 15:38:42 +01:00
chrisw
a085ffa590 implement column adding with foreign keys on sqlite 2010-09-09 13:58:41 +01:00