summaryrefslogtreecommitdiff
path: root/tests/test_oracle.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/test_oracle.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/test_oracle.py')
-rw-r--r--tests/test_oracle.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_oracle.py b/tests/test_oracle.py
index 9556a2e..537d8c6 100644
--- a/tests/test_oracle.py
+++ b/tests/test_oracle.py
@@ -11,6 +11,7 @@ from alembic.testing.env import three_rev_fixture
from alembic.testing.fixtures import capture_context_buffer
from alembic.testing.fixtures import op_fixture
from alembic.testing.fixtures import TestBase
+from alembic.util import sqla_compat
class FullEnvironmentTests(TestBase):
@@ -67,6 +68,18 @@ class OpTest(TestBase):
"COMMENT ON COLUMN t1.c1 IS 'c1 comment'",
)
+ @config.requirements.computed_columns_api
+ def test_add_column_computed(self):
+ context = op_fixture("oracle")
+ op.add_column(
+ "t1",
+ Column("some_column", Integer, sqla_compat.Computed("foo * 5")),
+ )
+ context.assert_(
+ "ALTER TABLE t1 ADD some_column "
+ "INTEGER GENERATED ALWAYS AS (foo * 5)"
+ )
+
def test_alter_column_rename_oracle(self):
context = op_fixture("oracle")
op.alter_column("t", "c", name="x")