Commit Graph

52 Commits

Author SHA1 Message Date
Mike Bayer c5dccd82da - Fixed regression in new "naming convention" feature where conventions
would fail if the referred table in a foreign key contained a schema
name.  Pull request courtesy Thomas Farvour. pullreq github:67
2014-02-05 16:54:31 -05:00
Mike Bayer 2d4b457924 - The behavior of :meth:.Table.tometadata has been adjusted such that
the schema target of a :class:`.ForeignKey` will not be changed unless
that schema matches that of the parent table.  That is, if
a table "schema_a.user" has a foreign key to "schema_b.order.id",
the "schema_b" target will be maintained whether or not the
"schema" argument is passed to :meth:`.Table.tometadata`.  However
if a table "schema_a.user" refers to "schema_a.order.id", the presence
of "schema_a" will be updated on both the parent and referred tables.
This is a behavioral change hence isn't likely to be backported to
0.8; it is assumed that the previous behavior is pretty buggy
however and that it's unlikely anyone was relying upon it.

Additionally, a new parameter has been added
:paramref:`.Table.tometadata.referred_schema_fn`.  This refers to a
callable function which will be used to determine the new referred
schema for any :class:`.ForeignKeyConstraint` encountered in the
tometadata operation.  This callable can be used to revert to the
previous behavior or to customize how referred schemas are treated
on a per-constraint basis.  [ticket:2913]

- rework the tests in test.sql.test_metadata, all the "tometadata" tests
now under new class ToMetaDataTest
2014-02-02 14:37:43 -05: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 3dc9f9b3db - alter behavior such that dialect_kwargs is still immutable, but
now represents exactly the kwargs that were passed, and not the defaults.
the defaults are still in dialect_options.  This allows repr() schemes such as that
of alembic to not need to look through and compare for defaults.
2014-01-19 16:32:36 -05:00
Mike Bayer 8e1a4fdced - some test fixes
- clean up some shenanigans in reflection
2014-01-19 00:34:37 -05:00
Mike Bayer 1af8e2491d - implement kwarg validation and type system for dialect-specific
arguments; [ticket:2866]
- add dialect specific kwarg functionality to ForeignKeyConstraint, ForeignKey
2014-01-18 19:26:56 -05:00
Mike Bayer 84af7e6c22 - The :class:.ForeignKey class more aggressively checks the given
column argument.   If not a string, it checks that the object is
at least a :class:`.ColumnClause`, or an object that resolves to one,
and that the ``.table`` attribute, if present, refers to a
:class:`.TableClause` or subclass, and not something like an
:class:`.Alias`.  Otherwise, a :class:`.ArgumentError` is raised.
[ticket:2883]
2013-12-11 19:48:27 -05:00
Mike Bayer 73669c7284 - The :meth:.Table.tometadata method now produces copies of
all :attr:`.SchemaItem.info` dictionaries from all :class:`.SchemaItem`
objects within the structure including columns, constraints,
foreign keys, etc.   As these dictionaries
are copies, they are independent of the original dictionary.
Previously, only the ``.info`` dictionary of :class:`.Column` was transferred
within this operation, and it was only linked in place, not copied.
[ticket:2716]
2013-10-18 20:01:45 -04:00
Mike Bayer 78a38967c4 The `.unique flag on :class:.Index could be produced as None`
if it was generated from a :class:`.Column` that didn't specify ``unique``
(where it defaults to ``None``).  The flag will now always be ``True`` or
``False``. [ticket:2825]
2013-10-14 14:53:28 -04:00
Mike Bayer 9d38ed3340 The "name" attribute is set on :class:.Index before the "attach"
events are called, so that attachment events can be used to dynamically
generate a name for the index based on the parent table and/or
columns. [ticket:2835]
2013-10-11 15:55:57 -04:00
Mike Bayer 650c7e46be - these tests now fail on a normalize name DB, as they should! because we're quoting the lowercase name. 2013-08-28 00:11:15 -04:00
Mike Bayer 031ef08078 - A rework to the way that "quoted" identifiers are handled, in that
instead of relying upon various ``quote=True`` flags being passed around,
these flags are converted into rich string objects with quoting information
included at the point at which they are passed to common schema constructs
like :class:`.Table`, :class:`.Column`, etc.   This solves the issue
of various methods that don't correctly honor the "quote" flag such
as :meth:`.Engine.has_table` and related methods.  The :class:`.quoted_name`
object is a string subclass that can also be used explicitly if needed;
the object will hold onto the quoting preferences passed and will
also bypass the "name normalization" performed by dialects that
standardize on uppercase symbols, such as Oracle, Firebird and DB2.
The upshot is that the "uppercase" backends can now work with force-quoted
names, such as lowercase-quoted names and new reserved words.
[ticket:2812]
2013-08-27 20:43:22 -04:00
Mike Bayer 28a3f15206 tweak this for now, would need a test 2013-06-23 16:08:01 -04:00
Mike Bayer e288aff8ea The resolution of :class:.ForeignKey objects to their
target :class:`.Column` has been reworked to be as
immediate as possible, based on the moment that the
target :class:`.Column` is associated with the same
:class:`.MetaData` as this :class:`.ForeignKey`, rather
than waiting for the first time a join is constructed,
or similar. This along with other improvements allows
earlier detection of some foreign key configuration
issues.  Also included here is a rework of the
type-propagation system, so that
it should be reliable now to set the type as ``None``
on any :class:`.Column` that refers to another via
:class:`.ForeignKey` - the type will be copied from the
target column as soon as that other column is associated,
and now works for composite foreign keys as well.
[ticket:1765]
2013-06-23 15:58:07 -04:00
Mike Bayer 8a865a4d1f Fixed bug whereby joining a select() of a table "A" with multiple
foreign key paths to a table "B", to that table "B", would fail
to produce the "ambiguous join condition" error that would be
reported if you join table "A" directly to "B"; it would instead
produce a join condition with multiple criteria.
[ticket:2738]
2013-06-03 17:03:15 -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 6ddfe3b390 - :meth:.MetaData.create_all and :meth:.MetaData.drop_all will
now accommodate an empty list as an instruction to not create/drop
any items, rather than ignoring the collection. [ticket:2664].
This is a behavioral change and extra notes to the changelog
and migration document have been added.

- create a new test suite for exercising codepaths
in engine/ddl.py
2013-03-02 17:47:58 -05:00
Mike Bayer 45ba7b6e0e - some linter cleanup, though have disabled the newer linter rules which are just
too much for now
2013-03-02 16:37:58 -05:00
Mike Bayer da3d817f36 Added a new argument to :class:.Enum and its base
:class:`.SchemaType` ``inherit_schema``.  When set to ``True``,
the type will set its ``schema`` attribute of that of the
:class:`.Table` to which it is associated.  This also occurs
during a :meth:`.Table.tometadata` operation; the :class:`.SchemaType`
is now copied in all cases when :meth:`.Table.tometadata` happens,
and if ``inherit_schema=True``, the type will take on the new
schema name passed to the method.   The ``schema`` is important
when used with the Postgresql backend, as the type results in
a ``CREATE TYPE`` statement. [ticket:2657]
2013-02-01 20:47:02 -05:00
Mike Bayer e26b28224d Fixed bug where :meth:.Table.tometadata would fail if a
:class:`.Column` had both a foreign key as well as an
alternate ".key" name for the column.   Also in 0.7.10.
[ticket:2643]
2013-01-27 11:23:59 -05:00
Mike Bayer 3859742a91 Fixed bug where using server_onupdate=<FetchedValue|DefaultClause>
without passing the "for_update=True" flag would apply the default
object to the server_default, blowing away whatever was there.
The explicit for_update=True argument shouldn't be needed with this usage
(especially since the documentation shows an example without it being
used) so it is now arranged internally using a copy of the given default
object, if the flag isn't set to what corresponds to that argument.
Also in 0.7.10. [ticket:2631]
2012-12-08 20:28:43 -05: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 152163b333 - [bug] When the primary key column of a Table
is replaced, such as via extend_existing,
    the "auto increment" column used by insert()
    constructs is reset.  Previously it would
    remain referring to the previous primary
    key column.  [ticket:2525]
2012-09-23 12:51:24 -04:00
Mike Bayer e354dd10f8 - [feature] An explicit error is raised when
a ForeignKeyConstraint() that was
    constructed to refer to multiple remote tables
    is first used. [ticket:2455]
2012-09-23 12:42:38 -04:00
Mike Bayer 4da34b4cb7 - clean pyflakes 2012-09-23 12:31:41 -04:00
Mike Bayer 7e815c67a9 finished fixes for mxodbc; need to use at least version 3.2.1 2012-09-21 17:43:22 -04:00
Mike Bayer 1c325dc9c7 - [feature] Added a hook to the system of rendering
CREATE TABLE that provides access to the render for each
Column individually, by constructing a @compiles
function against the new schema.CreateColumn
construct.  [ticket:2463]
2012-09-09 14:39:25 -04:00
Mike Bayer f46f16d4c7 fixes to prevent the new MyISAM engine from breaking other tests 2012-08-29 12:16:18 -04:00
Mike Bayer 7a81ecc82c - adjustments for py3.3 unit tests, [ticket:2542] 2012-08-11 21:46:48 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Mike Bayer d50ea3eabf - [bug] Index will raise when arguments passed
cannot be interpreted as columns or expressions.
Will warn when Index is created
with no columns at all.  [ticket:2380]
2012-02-12 17:47:36 -05:00
Mike Bayer 96dce7686c - [feature] New reflection feature "autoload_replace";
when set to False on Table, the Table can be autoloaded
without existing columns being replaced.  Allows
more flexible chains of Table construction/reflection
to be constructed, including that it helps with
combining Declarative with table reflection.
See the new example on the wiki.  [ticket:2356]

- [bug] Improved the API for add_column() such that
if the same column is added to its own table,
an error is not raised and the constraints
don't get doubled up.  Also helps with some
reflection/declarative patterns. [ticket:2356]
2012-01-28 15:54:28 -05:00
Mike Bayer 8301651428 - [feature] Added new support for remote "schemas":
- MetaData() accepts "schema" and "quote_schema"
      arguments, which will be applied to the same-named
      arguments of a Table
      or Sequence which leaves these at their default
      of ``None``.
    - Sequence accepts "quote_schema" argument
    - tometadata() for Table will use the "schema"
      of the incoming MetaData for the new Table
      if the schema argument is explicitly "None"
    - Added CreateSchema and DropSchema DDL
      constructs - these accept just the string
      name of a schema and a "quote" flag.
    - When using default "schema" with MetaData,
      ForeignKey will also assume the "default" schema
      when locating remote table.  This allows the "schema"
      argument on MetaData to be applied to any
      set of Table objects that otherwise don't have
      a "schema".
    - a "has_schema" method has been implemented
      on dialect, but only works on Postgresql so far.
    Courtesy Manlio Perillo, [ticket:1679]
2011-10-23 16:57:48 -04:00
Mike Bayer e4c04590a6 - Modified Column.copy() to use _constructor(),
which defaults to self.__class__, in order to
    create the new object.  This allows easier support
    of subclassing Column.  [ticket:2284]
2011-09-23 20:51:58 -04:00
Mike Bayer 76a9219a1e - Added a slightly nicer __repr__() to SchemaItem
classes.  Note the repr here can't fully support
the "repr is the constructor" idea since schema
items can be very deeply nested/cyclical, have
late initialization of some things, etc.
[ticket:2223]
2011-08-14 12:20:54 -04:00
Mike Bayer c1295ce57b - Added an informative error message when
ForeignKeyConstraint refers to a column name in
    the parent that is not found.  Also in 0.6.9.
- add tests for [ticket:2226], as if we hit each @declared_attr
directly with obj.__get__(obj, name) instead of using
getattr(cls, name).  Basic inheritance mechanics are improperly
used in this case, so 2226 is invalid.
2011-07-21 11:44:31 -04:00
Mike Bayer 3452a2ba03 - Fixed bug whereby if FetchedValue was passed
to column server_onupdate, it would not
have its parent "column" assigned, added
test coverage for all column default assignment
patterns.  [ticket:2147]  also in 0.6.8
2011-04-23 12:34:17 -04:00
Mike Bayer 0c560edee7 - Added explicit check for when Column .name
is assigned as blank string [ticket:2140]
2011-04-20 15:49:33 -04:00
Mike Bayer ae363b0663 - Before/after attach events for PrimaryKeyConstraint
now function, tests added for before/after events
on all constraint types.  [ticket:2105]
2011-04-17 13:53:21 -04:00
Mike Bayer d34bc7da31 - The 'useexisting' flag on Table has been superceded
by a new pair of flags 'keep_existing' and
'extend_existing'.   'extend_existing' is equivalent
to 'useexisting' - the existing Table is returned,
and additional constructor elements are added.
With 'keep_existing', the existing Table is returned,
but additional constructor elements are not added -
these elements are only applied when the Table
is newly created.   [ticket:2109]
2011-04-05 12:04:42 -04:00
Mike Bayer 68a350d462 - remove test.sql._base, test.engine._base, test.orm._base, move those classes to a new test.lib.fixtures module
- move testing.TestBase to test.lib.fixtures
- massive search and replace
2011-03-27 16:27:27 -04:00
Mike Bayer ebd0fdad73 - convert @provide_metadata to use self access
- having occasional issues with BasicEntity grabbing, if it persists
may have to pass an explicit base class into setup_classes()/setup_mappers()
2011-03-26 21:40:05 -04:00
Mike Bayer de529fb81c - adjust the previous checkin a bit. need to transfer sequences over from pickle
even if they are *not* restated.  its necessary here to do a "replacement"
scheme when an incoming sequence replaces the previous.  Theoretically
we could do what Table does here, i.e. use a singleton constructor, but
this is heavyhanded.   The most recent sequence placed in is the winner
is likely the most expected behavior.
2011-03-23 17:38:54 -04:00
Mike Bayer 93da3087f1 - Fixed regression whereby MetaData() coming
back from unpickling did not keep track of
new things it keeps track of now, i.e.
collection of Sequence objects, list
of schema names.  [ticket:2104]
2011-03-23 17:25:57 -04:00
Mike Bayer cf51131150 - Added a fully descriptive error message for the
case where Column is subclassed and _make_proxy()
fails to make a copy due to TypeError on the
constructor.   The method _constructor should
be implemented in this case.
2011-02-28 12:47:04 -05:00
Mike Bayer 01cb94690d - The Column.references() method now returns True
if it has a foreign key referencing the
given column exactly, not just it's parent
table.  [ticket:2064]
2011-02-17 20:27:35 -05:00
Mike Bayer 12073e281e - SchemaItem, SchemaType now descend from common type
SchemaEventTarget, which supplies dispatch
- the dispatch now provides before_parent_attach(),
after_parent_attach(), events which generally bound the _set_parent()
event. [ticket:2037]
- the _on_table_attach mechanism now usually uses the
event dispatch
- fixed class-level event dispatch to propagate to all subclasses, not just
immediate subclasses
- fixed class-level event unpickling to handle more involved
inheritance hierarchies, needed by the new schema event dispatch.
- ForeignKeyConstraint doesn't re-call the column attach event
on ForeignKey objects that are already associated with the correct
Column
- we still need that ImportError on mysqldb CLIENT FLAGS to support
mock DBAPIs
2011-01-30 20:29:48 -05:00
Mike Bayer 1c1ff92fa9 - Column.copy(), as used in table.tometadata(), copies the
'doc' attribute.  [ticket:2028]
2011-01-30 13:09:45 -05:00
Mike Bayer 4e9e0f041c - merge r43460573c27a:4993c7eae8e5d117ff342bdc59f3b0635b898e2c of 0.6 branch 2011-01-08 16:14:47 -05:00