summaryrefslogtreecommitdiff
path: root/test/sql/test_constraints.py
Commit message (Collapse)AuthorAgeFilesLines
* Try running pyupgrade on the codeFederico Caselli2022-11-161-9/+7
| | | | | | | | command run is "pyupgrade --py37-plus --keep-runtime-typing --keep-percent-format <files...>" pyupgrade will change assert_ to assertTrue. That was reverted since assertTrue does not exists in sqlalchemy fixtures Change-Id: Ie1ed2675c7b11d893d78e028aad0d1576baebb55
* Make if_exists and if_not_exists flags on ddl statements match compilerJesse Bakker2022-10-041-0/+14
| | | | | | | | | | | | | | | Added ``if_exists`` and ``if_not_exists`` parameters for all "Create" / "Drop" constructs including :class:`.CreateSequence`, :class:`.DropSequence`, :class:`.CreateIndex`, :class:`.DropIndex`, etc. allowing generic "IF EXISTS" / "IF NOT EXISTS" phrases to be rendered within DDL. Pull request courtesy Jesse Bakker. Fixes: #7354 Closes: #8492 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8492 Pull-request-sha: d107c6ce553bd430111607815f5b3938ffc4770c Change-Id: I367e57b2d9216f5180bcc44e86ca6f3dc794e5ca
* feat: add `drop constraint if exists` to compilerMike Fiedler2022-07-031-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Description Add `DROP CONSTRAINT ... IF EXISTS` behavior to the compiler. Fixes https://github.com/sqlalchemy/sqlalchemy/issues/8141 ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [x] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #8161 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8161 Pull-request-sha: 43276e29fa864fc66900c5a3fa0bf84df5f14271 Change-Id: I18bae3cf013159b6fffde4413fb59ce19ff83c16
* pep484: schema APIMike Bayer2022-04-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | implement strict typing for schema.py this module has lots of public API, lots of old decisions and very hard to follow construction sequences in many cases, and is also where we get a lot of new feature requests, so strict typing should help keep things clean. among improvements here, fixed the pool .info getters and also figured out how to get ColumnCollection and related to be covariant so that we may set them up as returning Column or ColumnClause without any conflicts. DDL was affected, noting that superclasses of DDLElement (_DDLCompiles, added recently) can now be passed into "ddl_if" callables; reorganized ddl into ExecutableDDLElement as a new name for DDLElement and _DDLCompiles renamed to BaseDDLElement. setting up strict also located an API use case that is completely broken, which is connection.execute(some_default) returns a scalar value. This case has been deprecated and new paths have been set up so that connection.scalar() may be used. This likely wasn't possible in previous versions because scalar() would assume a CursorResult. The scalar() change also impacts Session as we have explicit support (since someone had reported it as a regression) for session.execute(Sequence()) to work. They will get the same deprecation message (which omits the word "Connection", just uses ".execute()" and ".scalar()") and they can then use Session.scalar() as well. Getting this to type correctly while still supporting ORM use cases required some refactoring, and I also set up a keyword only delimeter for Session.execute() and related as execution_options / bind_arguments should always be keyword only, applied these changes to AsyncSession as well. Additionally simpify Table __init__ now that we are Python 3 only, we can have positional plus explicit kwargs finally. Simplify Column.__init__ as well again taking advantage of kw only arguments. Fill in most/all __init__ methods in sqltypes.py as the constructor for types is most of the API. should likely do this for dialect-specific types as well. Apply _InfoType for all info attributes as should have been done originally and update descriptor decorators. Change-Id: I3f9f8ff3f1c8858471ff4545ac83d68c88107527
* Update Black's target-version to py37Hugo van Kemenade2022-01-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <!-- Provide a general summary of your proposed changes in the Title field above --> ### Description <!-- Describe your changes in detail --> Black's `target-version` was still set to `['py27', 'py36']`. Set it to `[py37]` instead. Also update Black and other pre-commit hooks and re-format with Black. ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #7536 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7536 Pull-request-sha: b3aedf5570d7e0ba6c354e5989835260d0591b08 Change-Id: I8be85636fd2c9449b07a8626050c8bd35bd119d5
* remove metadata.bind use from test suiteMike Bayer2021-01-031-17/+18
| | | | | | | | | | | | | | importantly this means we can remove bound metadata from the fixtures that are used by Alembic's test suite. hopefully this is the last one that has to happen to allow Alembic to be fully 1.4/2.0. Start moving from @testing.provide_metadata to a pytest metadata fixture. This does not seem to have any negative effects even though TablesTest uses a "self.metadata" attribute. Change-Id: Iae6ab95938a7e92b6d42086aec534af27b5577d3
* Ensure all Index arguments are counted when matching expr/columnsMike Bayer2019-07-241-11/+35
| | | | | | | | | | Fixed issue where :class:`.Index` object which contained a mixture of functional expressions which were not resolvable to a particular column, in combination with string-based column names, would fail to initialize its internal state correctly leading to failures during DDL compilation. Fixes: #4778 Change-Id: I0fa9c627a1fde92ba8b9ed10af167c156012bd5d
* Enable F841Mike Bayer2019-06-201-1/+1
| | | | | | | | | | | This is a very useful assertion which prevents unused variables from being set up allows code to be more readable and sometimes even more efficient. test suites seem to be where the most problems are and there do not seem to be documentation examples that are using this, or at least the linter is not taking effect within rst blocks. Change-Id: I2b3341d8dd14da34879d8425838e66a4b9f8e27d
* Post black reformattingMike Bayer2019-01-061-30/+25
| | | | | | | | | | | | | Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
* Run black -l 79 against all source filesMike Bayer2019-01-061-539/+701
| | | | | | | | | | | | | | This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
* Apply SQL compilation to sqltext for column-level CHECK constraintMike Bayer2017-04-041-0/+13
| | | | | | | | | | | | | Fixed bug where a column-level :class:`.CheckConstraint` would fail to compile the SQL expression using the underlying dialect compiler as well as apply proper flags to generate literal values as inline, in the case that the sqltext is a Core expression and not just a plain string. This was long-ago fixed for table-level check constraints in 0.9 as part of :ticket:`2742`, which more commonly feature Core SQL expressions as opposed to plain string expressions. Change-Id: I1301ba4b40063e91bc47726aecc5f4990ffcaeda Fixes: #3957
* Make all tests to be PEP8 compliantKhairi Hafsham2017-02-071-15/+11
| | | | | | | | tested using pycodestyle version 2.2.0 Fixes: #3885 Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
* - Consoliate test/sql/test_constraint ConstraintAPITestMike Bayer2016-07-301-342/+0
| | | | | | | and test/sql/test_metadata IndexTest into test/sql/test_metadata ConstraintTest Change-Id: I7aeee9a1edbbd889200afc393695f73d5fbac3f3
* - Fixed bug in enhanced constraint-attachment logic introduced inMike Bayer2015-05-021-0/+59
| | | | | | | | | | | :ticket:`3341` where in the unusual case of a constraint that refers to a mixture of :class:`.Column` objects and string column names at the same time, the auto-attach-on-column-attach logic will be skipped; for the constraint to be auto-attached in this case, all columns must be assembled on the target table up front. Added a new section to the migration document regarding the original feature as well as this change. fixes #3411
* - repair a regression caused by #3282, where we no longer wereMike Bayer2015-04-221-78/+276
| | | | | | | | | | applying any topological sort to tables on SQLite. See the changelog for details, but we now continue to sort tables for SQLite on DROP, prohibit the sort from considering alter, and only warn if we encounter an unresolvable cycle, in which case, then we forego the ordering. use_alter as always is used to break such a cycle. fixes #3378
* - The "auto-attach" feature of constraints such as :class:`.UniqueConstraint`Mike Bayer2015-03-241-0/+97
| | | | | | | | | | and :class:`.CheckConstraint` has been further enhanced such that when the constraint is associated with non-table-bound :class:`.Column` objects, the constraint will set up event listeners with the columns themselves such that the constraint auto attaches at the same time the columns are associated with the table. This in particular helps in some edge cases in declarative but is also of general use. fixes #3341
* - The :class:`.CheckConstraint` construct now supports namingMike Bayer2015-01-301-1/+1
| | | | | | | | | | conventions that include the token ``%(column_0_name)s``; the constraint expression is scanned for columns. Additionally, naming conventions for check constraints that don't include the ``%(constraint_name)s`` token will now work for :class:`.SchemaType`- generated constraints, such as those of :class:`.Boolean` and :class:`.Enum`; this stopped working in 0.9.7 due to :ticket:`3067`. fixes #3299
* - rework assertsql system, fixes #3293Mike Bayer2015-01-181-6/+6
|
* - restate sort_tables in terms of a more fine grainedMike Bayer2015-01-011-26/+181
| | | | | | | | | | | | | sort_tables_and_constraints function. - The DDL generation system of :meth:`.MetaData.create_all` and :meth:`.Metadata.drop_all` has been enhanced to in most cases automatically handle the case of mutually dependent foreign key constraints; the need for the :paramref:`.ForeignKeyConstraint.use_alter` flag is greatly reduced. The system also works for constraints which aren't given a name up front; only in the case of DROP is a name required for at least one of the constraints involved in the cycle. fixes #3282
* require check constraints for testsScott Dugas2014-10-231-0/+1
|
* - update the flake8 rules againMike Bayer2014-07-181-208/+208
| | | | - apply autopep8 + manual fixes to most of test/sql/
* - fix test failuresMike Bayer2014-06-211-3/+3
|
* - Liberalized the contract for :class:`.Index` a bit in that you canMike Bayer2014-04-191-10/+33
| | | | | | | specify a :func:`.text` expression as the target; the index no longer needs to have a table-bound column present if the index is to be manually added to the table, either via inline declaration or via :meth:`.Table.append_constraint`. fixes #3028
* - rename __multiple__ to __backend__, and apply __backend__ to a large ↵Mike Bayer2014-03-241-0/+2
| | | | | | number of tests. - move out logging tests from test_execute to test_logging
* Bug Fix: Stop generating bad sql if an empty UniqueConstraint() is givendonkopotamus2014-01-171-0/+22
|
* - Fixed bug in default compiler plus those of postgresql, mysql, andMike Bayer2013-10-121-0/+21
| | | | | | | | mssql to ensure that any literal SQL expression values are rendered directly as literals, instead of as bound parameters, within a CREATE INDEX statement. [ticket:2742] - don't need expression_as_ddl(); literal_binds and include_table take care of this functionality.
* genericize tests hereMike Bayer2013-06-041-5/+10
|
* - auto-append for CheckConstraint should skip table if the expression is againstMike Bayer2013-03-091-0/+13
| | | | a lower-case-t table
* :class:`.Index` now supports arbitrary SQL expressions and/orMike Bayer2013-01-161-1/+65
| | | | | | | | functions, in addition to straight columns. Common modifiers include using ``somecolumn.desc()`` for a descending index and ``func.lower(somecolumn)`` for a case-insensitive index, depending on the capabilities of the target backend. [ticket:695]
* - preparing for #695, modernize constraint/index testsMike Bayer2013-01-161-192/+371
|
* Fixed a regression caused by :ticket:`2410` whereby aMike Bayer2012-12-111-0/+39
| | | | | | | | | :class:`.CheckConstraint` would apply itself back to the original table during a :meth:`.Table.tometadata` operation, as it would parse the SQL expression for a parent table. The operation now copies the given expression to correspond to the new table. [ticket:2633]
* trying different approaches to test layout. in this one, the testing modulesMike Bayer2012-09-271-5/+6
| | | | | | | 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.
* - [bug] Fixed the DropIndex construct to supportMike Bayer2012-09-241-0/+39
| | | | | an Index associated with a Table in a remote schema. [ticket:2571]
* -whitespace bonanza, contdMike Bayer2012-07-281-13/+13
|
* - [feature] Added "MATCH" clause to ForeignKey,Mike Bayer2012-06-211-1/+20
| | | | | ForeignKeyConstraint, courtesy Ryan Kelly. [ticket:2502]
* - [bug] All of UniqueConstraint, ForeignKeyConstraint,Mike Bayer2012-04-241-1/+42
| | | | | | | | | | | CheckConstraint, and PrimaryKeyConstraint will attach themselves to their parent table automatically when they refer to a Table-bound Column object directly (i.e. not just string column name), and refer to one and only one Table. Prior to 0.8 this behavior occurred for UniqueConstraint and PrimaryKeyConstraint, but not ForeignKeyConstraint or CheckConstraint. [ticket:2410]
* - sqlMike Bayer2012-04-011-6/+2
| | | | | | | | | | | | | | | - [bug] Removed warning when Index is created with no columns; while this might not be what the user intended, it is a valid use case as an Index could be a placeholder for just an index of a certain name. - mssql - [feature] Added interim create_engine flag supports_unicode_binds to PyODBC dialect, to force whether or not the dialect passes Python unicode literals to PyODBC or not.
* - [bug] Index will raise when arguments passedMike Bayer2012-02-121-0/+33
| | | | | | cannot be interpreted as columns or expressions. Will warn when Index is created with no columns at all. [ticket:2380]
* - [bug] the "name" of a column-level CHECK constraint,Mike Bayer2011-12-041-1/+12
| | | | | | if present, is now rendered in the CREATE TABLE statement using "CONSTRAINT <name> CHECK <expression>". [ticket:2305]
* - move all the comments that got shoved below the fixture grabs back upMike Bayer2011-03-271-0/+1
|
* - remove test.sql._base, test.engine._base, test.orm._base, move those ↵Mike Bayer2011-03-271-2/+2
| | | | | | | classes to a new test.lib.fixtures module - move testing.TestBase to test.lib.fixtures - massive search and replace
* - establish an "insert" option for events to control ordering if needed (not ↵Mike Bayer2011-02-251-0/+22
| | | | | | needed yet tho) - render foreign key constraints in the order in which they were cerated
* make it more explicit in tests which dialect we want to use for thingsMike Bayer2011-02-111-0/+1
|
* - Non-DBAPI errors which occur in the scope of an `execute()`Mike Bayer2011-02-091-4/+4
| | | | | | | | call are now wrapped in sqlalchemy.exc.StatementError, and the text of the SQL statement and repr() of params is included. This makes it easier to identify statement executions which fail before the DBAPI becomes involved. [ticket:2015]
* - The Index() construct can be created inline with a TableMike Bayer2011-01-041-0/+37
| | | | | definition, using strings as column names, as an alternative to the creation of the index outside of the Table.
* - whitespace removal bonanzaMike Bayer2011-01-021-22/+22
|
* - move sqlalchemy.test to test.libMike Bayer2010-11-151-5/+5
|
* - The generated index name also is based onMike Bayer2010-08-021-15/+21
| | | | | | | | a "max index name length" attribute which is separate from the "max identifier length" - this to appease MySQL who has a max length of 64 for index names, separate from their overall max length of 255. [ticket:1412]
* - Changed the scheme used to generate truncatedMike Bayer2010-07-211-10/+23
| | | | | | | | | | | | "auto" index names when using the "index=True" flag on Column. The truncation only takes place with the auto-generated name, not one that is user-defined (an error would be raised instead), and the truncation scheme itself is now based on a fragment of an md5 hash of the identifier name, so that multiple indexes on columns with similar names still have unique names. [ticket:1855]
* - Fixed concatenation of constraints when "PRIMARY KEY"Mike Bayer2010-05-271-1/+1
| | | | | | | constraint gets moved to column level due to SQLite AUTOINCREMENT keyword being rendered. [ticket:1812] - remove some extra space in between constraint DDL - added alias() to binary comparison test, fixing pg + mysql failures