summaryrefslogtreecommitdiff
path: root/tests/requirements.py
diff options
context:
space:
mode:
authorCaselIT <cfederico87@gmail.com>2019-12-27 17:26:38 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-01-01 15:11:00 -0500
commit3ea190f843c7f246f73f91a9b79ede63d8d610fb (patch)
tree3f9109e9189189315c15c081d2d2c6e47842bba9 /tests/requirements.py
parent286fbcf2408d0264500e0527c3cb9d2f41cb5b1e (diff)
downloadalembic-3ea190f843c7f246f73f91a9b79ede63d8d610fb.tar.gz
Add support for computed columns
Added support for rendering of "computed" elements on :class:`.Column` objects, supported in SQLAlchemy via the new :class:`.Computed` element introduced in version 1.3.11. Pull request courtesy Federico Caselli. Note that there is currently no support for ALTER COLUMN to add, remove, or modify the "GENERATED ALWAYS AS" element from a column; at least for PostgreSQL, it does not seem to be supported by the database. Additionally, SQLAlchemy does not currently reliably reflect the "GENERATED ALWAYS AS" phrase from an existing column, so there is also no autogenerate support for addition or removal of the :class:`.Computed` element to or from an existing column, there is only support for adding new columns that include the :class:`.Computed` element. In the case that the :class:`.Computed` element is removed from the :class:`.Column` object in the table metadata, PostgreSQL and Oracle currently reflect the "GENERATED ALWAYS AS" expression as the "server default" which will produce an op that tries to drop the element as a default. In order to facilitate using testing combinations with elements that are not necessarily present, the support for lambda combinations from SQLAlchemy Ia63a510f9c1d08b055eef62cf047f1f427f0450c is also ported here, as well as a vendoring in of the current sqlalchemy.testing.exclusions module where we need the additional combinations support added in I15d2839954d77a252bab5aaf6e3fd9f388c99dd5. Fixes: #624 Closes: #631 Pull-request: https://github.com/sqlalchemy/alembic/pull/631 Pull-request-sha: 9c45651295626edf5f172ec827a5ced1440818cf Change-Id: Ifd27c2f541b22fb7a78de1afaa36dbf509ff6d3f
Diffstat (limited to 'tests/requirements.py')
-rw-r--r--tests/requirements.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/requirements.py b/tests/requirements.py
index e07a517..7eb528e 100644
--- a/tests/requirements.py
+++ b/tests/requirements.py
@@ -1,5 +1,4 @@
-from sqlalchemy.testing import exclusions
-
+from alembic.testing import exclusions
from alembic.testing.requirements import SuiteRequirements
from alembic.util import sqla_compat
@@ -136,6 +135,36 @@ class DefaultRequirements(SuiteRequirements):
return exclusions.only_on("postgresql", "mysql")
@property
+ def computed_columns(self):
+ # TODO: in theory if these could come from SQLAlchemy dialects
+ # that would be helpful
+ return self.computed_columns_api + exclusions.only_on(
+ ["postgresql >= 12", "oracle", "mssql", "mysql >= 5.7"]
+ )
+
+ @property
+ def computed_reflects_as_server_default(self):
+ # note that this rule will go away when SQLAlchemy correctly
+ # supports reflection of the "computed" construct; the element
+ # will consistently be present as both column.computed and
+ # column.server_default for all supported backends.
+ return self.computed_columns + exclusions.only_if(
+ ["postgresql", "oracle"],
+ "backend reflects computed construct as a server default",
+ )
+
+ @property
+ def computed_doesnt_reflect_as_server_default(self):
+ # note that this rule will go away when SQLAlchemy correctly
+ # supports reflection of the "computed" construct; the element
+ # will consistently be present as both column.computed and
+ # column.server_default for all supported backends.
+ return self.computed_columns + exclusions.skip_if(
+ ["postgresql", "oracle"],
+ "backend reflects computed construct as a server default",
+ )
+
+ @property
def check_constraint_reflection(self):
return exclusions.fails_on_everything_except(
"postgresql",