Commit Graph

296 Commits

Author SHA1 Message Date
Sean Mooney 5d1f322542 remove inspect.getargspec deprecation warning
In python 3 inspect.getargspec is deprecated and
replaced with inspect.getfullargspec which does not
exist on python 2.7. This change uses six to select
the correct version to use based on the python version
used.

Change-Id: I234a3509ff850d0c5616ebcfa240212b03db9e76
Closes-Bug: #1814288
2019-09-17 02:05:19 +01:00
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
Jenkins 9a7a37fba4 Merge "Fix spelling mistake" 2017-03-24 21:23:38 +00:00
dineshbhor 09ec8f7816 Fix spelling mistake
TrivialFix

Change-Id: I089d9e8b57895d9878bf82d2fac397722fccc083
2016-10-26 19:57:24 +05:30
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
Jenkins d58469a6ae Merge "Raise VersionNotFoundError instead of KeyError" 2016-06-03 13:45:36 +00:00
dineshbhor 2a32681036 Raise VersionNotFoundError instead of KeyError
Currently migrate.versioning.api.upgrade() raises KeyError
instead of sqlalchemy-migrate specific exception if migration
script file is not present in migration repository.

Raised migrate.exception.VersionNotFoundError if the specified
migration script does not exist in the repository. Made
VersionNotFoundError exception class as a subclass of KeyError
in order to avoid breaking existing users looking for KeyError.

Related-Bug: #1546441
Change-Id: I0210d56a6e85f03c44cea027f50863faaf050c1d
2016-05-27 11:57:24 +05:30
dineshbhor 9356e5e28a Fix DeprecationWarning on setuptools >= 11.3
Python 3.4 unit test is failing because of
DeprecationWarning: Parameters to load are deprecated.
Called .resolve and .require separately on setuptools >= 11.3.

Made provision to call .resolve() method if setuptools >= 10.2
and less than 11.3 else call .load() method.

Change-Id: I5ba80edfbf6b7c8399c66f01d57c91bd02eab274
Closes-Bug: #1586060
2016-05-26 20:12:25 +05:30
Jenkins 3c7ac7559c Merge "Add VerNum.__index__() for Python 3 support" 2015-07-31 02:11:27 +00:00
Victor Stinner 1384e901b0 Add VerNum.__index__() for Python 3 support
On Python 3, some functions like range() don't try to call the __int__()
method to cast an object to integer, but try instead the __index__()
method.

Add an __index__() method to mimick correctly the int type on Python 3.

Change-Id: I8df116d80e201778714a59367600eaef644266ed
2015-07-28 12:56:52 +02:00
Thomas Goirand fb55b01a9a Fixes usage function for Py3
The usage function of migrate_repository.py isn't Python 3 compatible,
and this hasn't be caught by unit tests. This patch fixes the function,
so at least the file can be compiled in Py3.

Change-Id: Ib9333e46e7526e82acde573d4b2046b2bf9a7ae0
2015-07-22 18:03:34 +00:00
Matt Riedemann 8252703f56 Unblock migrate (py26 and py3* testing issues)
There are two changes which have to go together to pass the gate
tests:

1. Update pbr and mock requirements from global-requirements

mock 1.2 supports py26 again so make that the minimum version. The
same change is being made in g-r with:

Ic6b9e18eaec9c81bbbbc57129e024904be928e09

Sync up with latest pbr in global-requirements while we're at it.

Closes-Bug: #1474925

2. Fix the importpath module to work with python >= 3.3 where the
__import__ built-in is raising an ImportError on a temporary file
that is added to the system path.

Closes-Bug: #1475339

Change-Id: Ie98938ba75f3983094dd540b7d26a7ec46be4f6e
2015-07-18 10:39:35 -07:00
Matt Riedemann dc07f8de8f Update flake8 related dependencies
In order to raise the cap on pbr we need to update
the dependent versions of the flake8 related packages
for the pep8 job since they have capped pbr.

A couple of simple hacking issues are fixed, the rest
are ignored.

Change-Id: Icddb5bf284da7b6463ebcfc7512726149ffe6085
2015-07-05 06:44:03 -07: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
Mike Bayer b8def7cbfb Ignore stderr output when invoking migrate script in tests
Under Python 2.6 a setuptools warning is produced when
the migrate runner runs.  Since migrate invokes its own
commandline client from tests in a separate shell, the
fixture we're using to do that must be told not to complain
about this stderr.

Change-Id: Ib5823754d6ffabe954665f2a7529ed0e56591ebf
2015-07-01 11:27:15 -04: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
Jenkins 8a638ce9d6 Merge "Don't run the test if _setup() fails" 2015-02-24 23:07:21 +00:00
Jenkins 24521798bc Merge "script: strip comments in SQL statements" 2015-02-24 23:05:33 +00:00
Roman Podoliaka 5feeaba69f Don't run the test if _setup() fails
Change-Id: I2c89c98961044f0e0a1d9b4c2eeea190c5830eed
2015-02-23 17:03:25 +02: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
Jenkins 0a618361ba Merge "Fixes the auto-generated manage.py" 2015-01-15 22:53:59 +00:00
Jenkins a15a7cec42 Merge "Replace assertNotEquals with assertNotEqual." 2015-01-15 22:18:05 +00:00
Ihar Hrachyshka b9caaae4fc script: strip comments in SQL statements
Regular expression does not match correctly against statements that contain
comments at their start. So strip those comments first (and whitespaces, while
we are at it).

Change-Id: Iad9b544bf995374d76cab1e125658aae2f8511f4
Closes-Bug: #1410494
2015-01-14 01:45:25 +01:00
Jenkins 397682b9c8 Merge "Use native sqlalchemy 0.9 quote attribute with ibmdb2" 2015-01-10 00:03:23 +00:00
Ihar Hrachyshka 938757e7aa Ignore transaction management statements in SQL scripts
Now that we don't run SQL script with a single .execute() call,
transaction management statements (BEGIN, COMMIT, END) fail with
operational error. Ignore them if occurred in a script.

All in all, transactions are managed by SQLAlchemy-migrate itself, so
there is no reason for the calling code to pass those statements in a
SQL script. Warn user about the statements that are ignored.

The ideal response to such a warning from library users is removing
those redundant transaction management statements from their scripts.

Note: ROLLBACK is not ignored even though it's one of transaction
management statements because its usage in migration scripts is insane
anyway, and we're better fail on it and not (almost) silently ignore it.

Change-Id: Ie4179c0e9341d42656d66821aaac23f8dcd33927
Closes-bug: 1368391
2015-01-09 14:32:27 -08:00
Rahul Priyadarshi 74553f426c Use native sqlalchemy 0.9 quote attribute with ibmdb2
Commit 8d6ce64cd0 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
Cyril Roelandt 677f374a68 Replace assertNotEquals with assertNotEqual.
The former is deprecated and the latter should be used.

Change-Id: I9d6dca41cb737062e6d4467c24dbc88901ab9a14
2014-10-30 08:56:50 +01:00
Jenkins 1e83840c98 Merge "Fix ibmdb2 unique constraint handling for sqlalchemy 0.9" 2014-10-10 12:32:25 +00:00
Ihar Hrachyshka 93ae21007d SqlScript: execute multiple statements one by one
Some drivers [f.e. MySQL Connector] do not like multiple statements
being passed to .execute(). They require either passing multi=True
parameter to .execute() that is not DB-API 2.0 defined, or executing
those statements one by one.

For that patch, I've chosen the second option to stay away from driver
specific hacks.

Also removed SQLite hack that seems to be related to the same multiple
statements issue.

blueprint enable-mysql-connector

Change-Id: Ic6d53ed1fef8aee9471f3540f06b39cd5ee4ef82
2014-08-23 21:34:13 +02:00
Ihar Hrachyshka be1dd6730a Make sure we don't throw away exception on SQL script failure
If SQL script failed, we don't currently log the failure anywhere, so
users have hard time debugging an issue, if anything arises.

Let's log the failure before proceeding with rollback.

Change-Id: Ic92b1403c00bb238a68265a15150a4be6f6b2346
2014-08-23 21:34:13 +02: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
Peter Conerly 5542e1c59a Fixes the auto-generated manage.py
Removes `six` from the locals().copy() so that it won't be templated into
manage.py.  Currently manage.py is mis-templated and is failing.

Change-Id: Ib3b7c7caac998fbaa45c3370547c9b8bf13abe41
Closes-Bug: 171
2014-08-02 11:41:39 -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
Cyril Roelandt 07909159ae tests: Replace "self.assert_" by "self.assertTrue"
The assert_() method is deprecated and can be safely replaced by assertTrue().
This patch makes sure that running the tests does not fill the screen with
warnings.

Change-Id: I8966b7f7a44f1573a4d2c398717bfc68ae40b197
2014-03-31 15:08:29 +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 b58b4a353c fix scripttest compat
There's no script_path param in the current version of
scripttest. This patch fixes that by removing the param,
which by the way isn't useful.

Change-Id: Ic78cea25bb472702473e98b48a8ff74c01545aa3
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
Thomas Goirand bcb6991615 Fix genmodel for SQLA 0.9
Problem:
* Some python code was auto generated and exec'ed in that
package.
* The python code that was problematic had a 'Table' definition
* The generated code imports '*' from sqlalchemy
* One among the 'Column' was defined as an 'INTEGER' type, which
points to sqlalchemy.sql.sqltypes.INTEGER
* The INTEGER class was initialised with a parameter display_width
which contradicts with sqlalchemy.sql.sqltypes.INTEGER.__init__,
which does not accept any parameters
* The 'INTEGER' class should have been imported from mysql dialects'
type module
Solution:
* While generating, in the header part, I am now checking if any of
the column.type.__class__.__name__ has 'dialects' in it.
* If I find any, I am adding the import rule such that the type is
imported from the dialects' type.

This patch has been tested with SQLA 0.9.3, for which it fixes the
unit tests, and with SQLA 0.8.2, which doesn't have (new) problems
with this patch.

Change-Id: Ie0e09b45388462629100017bea3ea8a314d148d8
2014-03-05 06:55:25 -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