Commit Graph

99 Commits

Author SHA1 Message Date
Mike Bayer 917a971764 Support mariadb 10.2
Fixed issue where CURRENT_TIMESTAMP would not reflect correctly
in the MariaDB 10.2 series due to a syntax change, where the function
is now represented as ``current_timestamp()``.

Fixes: #4096

MariaDB 10.2 now supports CHECK constraints (warning: use version 10.2.9
or greater due to upstream issues noted in 🎫`4097`).  Reflection
now takes these CHECK constraints into account when they are present in
the ``SHOW CREATE TABLE`` output.

Fixes: #4098

Change-Id: I8666d61814e8145ca12cbecad94019b44af868e3
(cherry picked from commit 29b752f8b2)
2017-09-29 13:21:16 -04:00
Khairi Hafsham 772374735d Make all tests to be PEP8 compliant
tested using pycodestyle version 2.2.0

Fixes: #3885
Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
2017-02-07 11:21:56 -05:00
Mike Bayer 388d8db68d Accept FetchedValue, text() for column "default" value
Fixed bug whereby the :meth:`.DDLEvents.column_reflect` event would not
allow a non-textual expression to be passed as the value of the
"default" for the new column, such as a :class:`.FetchedValue`
object to indicate a generic triggered default or a
:func:`.sql.expression.text` construct.  Clarified the documentation
in this regard as well.

Fixes: #3905

Change-Id: I829796c3e9f87f375149bebee7eef133a6876d4d
2017-02-01 17:00:42 -05:00
Valery Yundin bccc1419a6 Better hide engine password
Avoid putting engine password in the exception message in
`MetaData.reflect` (since exception messages often appear in logs).
Use the same redacted `__repr__` implementation in
`TLEngine` as in its base class `Engine`

Change-Id: Ic0a7baea917a9c8d87dffdd82ef566673ab08e02
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/327
2017-01-16 14:02:26 -05:00
Mike Bayer 55ad10370f Add _extend_on deduplicating set for metadata.reflect()
The "extend_existing" option of :class:`.Table` reflection would
cause indexes and constraints to be doubled up in the case that the parameter
were used with :meth:`.MetaData.reflect` (as the automap extension does)
due to tables being reflected both within the foreign key path as well
as directly.  A new de-duplicating set is passed through within the
:meth:`.MetaData.reflect` sequence to prevent double reflection in this
way.

Change-Id: Ibf6650c1e76a44ccbe15765fd79df2fa53d6bac7
Fixes: #3861
2016-11-23 10:31:56 -05:00
Alex Grönholm a8e7bb8782 Implemented CHECK constraint reflection for SQLite and PostgreSQL
Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: Ie6cf2d2958d1c567324db9e08fef2d3186e97350
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/80
2016-06-01 12:57:36 -04:00
Mike Bayer 4856493efc Merge remote-tracking branch 'origin/pr/270' 2016-05-24 16:29:49 -04:00
Mike Bayer c124fa36d5 Support "blank" schema when MetaData.schema is set
Previously, it was impossible to have a Table that has
None for a schema name when the "schema" parameter on
MetaData was set.  A new symbol sqlalchemy.schema.BLANK_SCHEMA
is added which indicates that the schema name should unconditionally
be set to None.  In particular, this value must be passed within
cross-schema foreign key reflection, so that a Table which
is in the "default" schema can be represented properly.

Fixes: #3716
Change-Id: I3d24f99c22cded206c5379fd32a225e74edb7a8e
2016-05-18 11:43:38 -04:00
Ville Skyttä 61f9e37612 Spelling fixes: "an SQL" -> "a SQL", see #266 2016-05-05 09:02:38 +03:00
Mike Bayer 89facbed88 - Multi-tenancy schema translation for :class:.Table objects is added.
This supports the use case of an application that uses the same set of
:class:`.Table` objects in many schemas, such as schema-per-user.
A new execution option
:paramref:`.Connection.execution_options.schema_translate_map` is
added. fixes #2685
- latest tox doesn't like the {posargs} in the profile rerunner
2016-01-08 22:12:25 -05:00
Mike Bayer 414af7b612 - The system by which a :class:.Column considers itself to be an
"auto increment" column has been changed, such that autoincrement
is no longer implicitly enabled for a :class:`.Table` that has a
composite primary key.  In order to accommodate being able to enable
autoincrement for a composite PK member column while at the same time
maintaining SQLAlchemy's long standing behavior of enabling
implicit autoincrement for a single integer primary key, a third
state has been added to the :paramref:`.Column.autoincrement` parameter
``"auto"``, which is now the default. fixes #3216
- The MySQL dialect no longer generates an extra "KEY" directive when
generating CREATE TABLE DDL for a table using InnoDB with a
composite primary key with AUTO_INCREMENT on a column that isn't the
first column;  to overcome InnoDB's limitation here, the PRIMARY KEY
constraint is now generated with the AUTO_INCREMENT column placed
first in the list of columns.
2015-10-07 10:02:45 -04:00
Eric Streeper 0f0e305d25 PEP8 cleanup in /test/engine 2015-03-20 00:32:05 -07:00
Scott Dugas 9687b272bd Added new requirement for check_constraints 2014-10-23 11:46:34 -04:00
Mike Bayer ec840a6eea - An adjustment to table/index reflection such that if an index
reports a column that isn't found to be present in the table,
a warning is emitted and the column is skipped.  This can occur
for some special system column situations as has been observed
with Oracle. fixes #3180
2014-09-02 14:18:09 -04:00
Malik Diarra ad8f921e96 Providing an autoload_with info automatically sets autoload to True 2014-08-09 21:43:32 +02:00
Mike Bayer 0bf33068f4 - ensure all tests are named test_* 2014-07-30 12:18:33 -04:00
Mike Bayer d2358629c9 - scale up for mysql, sqlite 2014-07-26 20:50:57 -04:00
Mike Bayer 2f150bee28 - rename __multiple__ to __backend__, and apply __backend__ to a large number of tests.
- move out logging tests from test_execute to test_logging
2014-03-24 11:33:53 -04:00
Mike Bayer be3c185fd4 - Added new datatype :class:.oracle.DATE, which is a subclass of
:class:`.DateTime`.  As Oracle has no "datetime" type per se,
it instead has only ``DATE``, it is appropriate here that the
``DATE`` type as present in the Oracle dialect be an instance of
:class:`.DateTime`.  This issue doesn't change anything as far as
the behavior of the type, as data conversion is handled by the
DBAPI in any case, however the improved subclass layout will help
the use cases of inspecting types for cross-database compatibility.
Also removed uppercase ``DATETIME`` from the Oracle dialect as this
type isn't functional in that context.  fixes #2987
2014-03-22 18:22:17 -04:00
Roman Podoliaka 0bb00db558 Remove tables from metadata when autoload fails
If autoloading of a table fails, don't register it in a metadata
instance. It seems that the original behaviour was accidentally
changed in f6198d9abf, restore it.

Closes issue #2988
2014-03-12 17:56:42 -07:00
Mike Bayer ea05a23218 - Support has been added for pytest to run tests. This runner
is currently being supported in addition to nose, and will likely
be preferred to nose going forward.   The nose plugin system used
by SQLAlchemy has been split out so that it works under pytest as
well.  There are no plans to drop support for nose at the moment
and we hope that the test suite itself can continue to remain as
agnostic of testing platform as possible.  See the file
README.unittests.rst for updated information on running tests
with pytest.

The test plugin system has also been enhanced to support running
tests against mutiple database URLs at once, by specifying the ``--db``
and/or ``--dburi`` flags multiple times.  This does not run the entire test
suite for each database, but instead allows test cases that are specific
to certain backends make use of that backend as the test is run.
When using pytest as the test runner, the system will also run
specific test suites multiple times, once for each database, particularly
those tests within the "dialect suite".   The plan is that the enhanced
system will also be used by Alembic, and allow Alembic to run
migration operation tests against multiple backends in one run, including
third-party backends not included within Alembic itself.
Third party dialects and extensions are also encouraged to standardize
on SQLAlchemy's test suite as a basis; see the file README.dialects.rst
for background on building out from SQLAlchemy's test platform.
2014-03-03 15:55:17 -05:00
Mike Bayer 198a900bd1 Merge branch 'master' of https://github.com/eblume/sqlalchemy into t 2014-02-16 16:43:42 -05:00
Erich Blume e47f994503 SQLite dialect - support relection from affinity
SQLite allows column types that aren't technically understood in sqlite
by using 'data affinity', which is an algorithm for converting column
types in to some sort of useful type that can be stored and retrieved
from the db. Unfortunatly, this breaks reflection since we (previously)
expected a sqlite db to reflect column types that we permit in the
`ischema_names` for that dialect.

This patch changes the logic for 'unknown' column types during
reflection to instead run through SQLite's data affinity algorithm, and
assigns appropriate types from that.

It also expands the matching for column type to include column types
with spaces (strongly discouraged but allowed by sqlite) and also
completely empty column types (in which case the NullType is assigned,
which sqlite will treat as a Blob - or rather, Blob is treated as
NullType). These changes mean that SQLite will never raise an error for
an unknown type during reflection - there will always be some 'useful'
type returned, which follows the spirit of SQLite (accomodation before
sanity!).
2014-02-03 16:55:00 -08:00
Mike Bayer 5b0919f3f5 - Added a new feature which allows automated naming conventions to be
applied to :class:`.Constraint` and :class:`.Index` objects.  Based
on a recipe in the wiki, the new feature uses schema-events to set up
names as various schema objects are associated with each other.  The
events then expose a configuration system through a new argument
:paramref:`.MetaData.naming_convention`.  This system allows production
of both simple and custom naming schemes for constraints and indexes
on a per-:class:`.MetaData` basis.  [ticket:2923]

commit 7e65e52c086652de3dd3303c723f98f09af54db8
Author: Mike Bayer <mike_mp@zzzcomputing.com>
Date:   Sat Feb 1 15:09:04 2014 -0500

    - first pass at new naming approach
2014-02-01 18:21:04 -05:00
Mike Bayer 49f1807f8f - simplify the mechanics of PrimaryKeyConstraint with regards to reflection;
reflection now updates the PKC in place.
- support the use case of the empty PrimaryKeyConstraint in order to specify
constraint options; the columns marked as primary_key=True will now be gathered
into the columns collection, rather than being ignored. [ticket:2910]
- add validation such that column specification should only take place
in the PrimaryKeyConstraint directly, or by using primary_key=True flags;
if both are present, they have to match exactly, otherwise the condition is
assumed to be ambiguous, and a warning is emitted; the old behavior of
using the PKC columns only is maintained.
2014-01-20 18:06:18 -05:00
Mike Bayer ecb3865615 - The :paramref:.Table.extend_existing and :paramref:.Table.autoload_replace
parameters are now available on the :meth:`.MetaData.reflect`
method.
- starting to use paramref and need newer paramlinks version.
2014-01-04 21:12:31 -05:00
Mike Bayer 59ca4633ac - remove informix dialect, moved out to https://bitbucket.org/zzzeek/sqlalchemy_informixdb
- remove informix, maxdb, access symbols from tests etc.
2013-11-17 13:45:23 -05:00
Mike Bayer 46ac022e57 - move this test to PG test_reflection
- don't use locals()
2013-10-25 17:19:03 -04:00
ijl f17e8a4452 ForeignKeyConstraint reflection test respects MySQL limitations 2013-10-15 16:01:25 -04:00
ijl 52cfa74e09 #2183: Metadata.reflect() foreign keys include options when the dialect exposes it 2013-10-13 17:13:28 -04:00
Mike Bayer 21fac20884 use a different col here to keep oracle happy 2013-09-02 12:11:24 -04:00
Mike Bayer 97168dbf69 plus some more adjustments for mysql, or in general if an Index refers to
in-python only cols
2013-08-28 17:31:40 -04:00
Mike Bayer fe66951f5d Fixed bug where using the `column_reflect event to change the .key`
of the incoming :class:`.Column` would prevent primary key constraints,
indexes, and foreign key constraints from being correctly reflected.
Also in 0.8.3. [ticket:2811]
2013-08-28 17:25:44 -04:00
Mike Bayer 258d2a8315 - get_unique_constraints() pull request
- version (0.9 for now)
- changelog
- move the test into the test suite so that all dialects can take advantage of it
2013-06-09 17:54:11 -04:00
Roman Podolyaka c69fe4acf8 Add basic support of unique constraints reflection
Inspection API already supports reflection of table
indexes information and those also include unique
constraints (at least for PostgreSQL and MySQL).
But it could be actually useful to distinguish between
indexes and plain unique constraints (though both are
implemented in the same way internally in RDBMS).

This change adds a new method to Inspection API - get_unique_constraints()
and implements it for SQLite, PostgreSQL and MySQL dialects.
2013-06-09 23:49:55 +03:00
Mike Bayer f1bdc3e999 - clean up some of the requires for cross-schema reflection
- add oracle profile counts
2013-06-03 18:11:32 -04:00
Mike Bayer ec04620f1f Fixed bug whereby using :meth:.MetaData.reflect across a remote
schema as well as a local schema could produce wrong results
in the case where both schemas had a table of the same name.
[ticket:2728]
2013-06-03 16:40:59 -04:00
Mike Bayer 021b5143e6 that's all of engine 2013-05-04 15:57:03 -04:00
Mike Bayer ef629e7b3d cleanup 2013-05-04 15:35:47 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer a0ef9edc19 - adding in requirements
- get test_naturalpks to be more generalized
2013-02-06 19:06:09 -05:00
Mike Bayer 504daf1bc0 Fixed :meth:.MetaData.reflect to correctly use
the given :class:`.Connection`, if given, without
opening a second connection from that connection's
:class:`.Engine`. [ticket:2604]
2012-11-14 00:52:31 -05:00
Mike Bayer f4ba5b856e - test updates 2012-10-04 10:28:21 -04:00
Mike Bayer b9ea55f861 - more tests, move some tests out of test_reflection, test_query 2012-09-27 16:11:32 -04:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Mike Bayer 2925167550 - [feature] The "deferred declarative
reflection" system has been moved into the
declarative extension itself, using the
new DeferredReflection class.  This
class is now tested with both single
and joined table inheritance use cases.
[ticket:2485]
- [bug] The autoload_replace flag on Table,
when False, will cause any reflected foreign key
constraints which refer to already-declared
columns to be skipped, assuming that the
in-Python declared column will take over
the task of specifying in-Python ForeignKey
or ForeignKeyConstraint declarations.
2012-05-17 11:45:05 -04:00
Mike Bayer 1fe06a551c - [feature] Inspector.get_primary_keys() is
deprecated; use Inspector.get_pk_constraint().
Courtesy Diana Clarke.  [ticket:2422]
- restored default get_primary_keys()/get_pk_constraint() wrapper
to help maintain compatibility with third party dialects
created against 0.6 or 0.7
2012-04-24 16:25:20 -04:00
Diana Clarke 3cbe90efbe deprecate inspector.get_primary_keys() in favor of inspector.get_pk_constraint()
- see #2422
2012-04-02 21:07:37 -04:00
Mike Bayer 998c66fa8b - [feature] The column_reflect event now
accepts the Inspector object as the first
argument, preceding "table".   Code which
uses the 0.7 version of this very new
event will need modification to add the
"inspector" object as the first argument.
[ticket:2418]
2012-04-24 12:01:04 -04:00