)
@util.deprecated_20(
- ":meth:`.DDL.execute`",
+ ":meth:`.DDLElement.execute`",
alternative="All statement execution in SQLAlchemy 2.0 is performed "
"by the :meth:`_engine.Connection.execute` method of "
":class:`_engine.Connection`, "
"""
+ @util.deprecated_params(
+ bind=(
+ "2.0",
+ "The :paramref:`_ddl.DDLElement.bind` argument is "
+ "deprecated and "
+ "will be removed in SQLAlchemy 2.0.",
+ ),
+ )
def __init__(
- self, element, bind=None, if_exists=False, if_not_exists=False
+ self,
+ element,
+ bind=None,
+ if_exists=False,
+ if_not_exists=False,
+ _legacy_bind=None,
):
self.element = element
- self.bind = bind
+ if bind:
+ self.bind = bind
+ elif _legacy_bind:
+ self.bind = _legacy_bind
self.if_exists = if_exists
self.if_not_exists = if_not_exists
__visit_name__ = "create_table"
+ @util.deprecated_params(
+ bind=(
+ "2.0",
+ "The :paramref:`_ddl.CreateTable.bind` argument is deprecated and "
+ "will be removed in SQLAlchemy 2.0.",
+ ),
+ )
def __init__(
self,
element,
"""
super(CreateTable, self).__init__(
- element, bind=bind, if_not_exists=if_not_exists
+ element, _legacy_bind=bind, if_not_exists=if_not_exists
)
self.columns = [CreateColumn(column) for column in element.columns]
self.include_foreign_key_constraints = include_foreign_key_constraints
__visit_name__ = "drop_table"
+ @util.deprecated_params(
+ bind=(
+ "2.0",
+ "The :paramref:`_ddl.DropTable.bind` argument is "
+ "deprecated and "
+ "will be removed in SQLAlchemy 2.0.",
+ ),
+ )
def __init__(self, element, bind=None, if_exists=False):
"""Create a :class:`.DropTable` construct.
"""
super(DropTable, self).__init__(
- element, bind=bind, if_exists=if_exists
+ element, _legacy_bind=bind, if_exists=if_exists
)
__visit_name__ = "create_index"
+ @util.deprecated_params(
+ bind=(
+ "2.0",
+ "The :paramref:`_ddl.CreateIndex.bind` argument is "
+ "deprecated and "
+ "will be removed in SQLAlchemy 2.0.",
+ ),
+ )
def __init__(self, element, bind=None, if_not_exists=False):
"""Create a :class:`.Createindex` construct.
"""
super(CreateIndex, self).__init__(
- element, bind=bind, if_not_exists=if_not_exists
+ element, _legacy_bind=bind, if_not_exists=if_not_exists
)
__visit_name__ = "drop_index"
+ @util.deprecated_params(
+ bind=(
+ "2.0",
+ "The :paramref:`_ddl.DropIndex.bind` argument is "
+ "deprecated and "
+ "will be removed in SQLAlchemy 2.0.",
+ ),
+ )
def __init__(self, element, bind=None, if_exists=False):
"""Create a :class:`.DropIndex` construct.
"""
super(DropIndex, self).__init__(
- element, bind=bind, if_exists=if_exists
+ element, _legacy_bind=bind, if_exists=if_exists
)
from sqlalchemy import MetaData
from sqlalchemy import null
from sqlalchemy import or_
+from sqlalchemy import schema
from sqlalchemy import select
from sqlalchemy import Sequence
from sqlalchemy import sql
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import in_
from sqlalchemy.testing import is_
+from sqlalchemy.testing import is_false
from sqlalchemy.testing import is_true
from sqlalchemy.testing import mock
from sqlalchemy.testing import not_in
r"The Engine.scalar\(\) method is considered legacy"
):
self._assert_seq_result(testing.db.scalar(select(s.next_value())))
+
+
+class DDLDeprecatedBindTest(fixtures.TestBase):
+ def teardown(self):
+ with testing.db.begin() as conn:
+ if inspect(conn).has_table("foo"):
+ conn.execute(schema.DropTable(table("foo")))
+
+ def test_bind_ddl_deprecated(self, connection):
+ with testing.expect_deprecated_20(
+ "The DDL.bind argument is deprecated"
+ ):
+ ddl = schema.DDL("create table foo(id integer)", bind=connection)
+
+ with testing.expect_deprecated_20(
+ r"The DDLElement.execute\(\) method is considered legacy"
+ ):
+ ddl.execute()
+
+ def test_bind_create_table_deprecated(self, connection):
+ t1 = Table("foo", MetaData(), Column("id", Integer))
+
+ with testing.expect_deprecated_20(
+ "The CreateTable.bind argument is deprecated"
+ ):
+ ddl = schema.CreateTable(t1, bind=connection)
+
+ with testing.expect_deprecated_20(
+ r"The DDLElement.execute\(\) method is considered legacy"
+ ):
+ ddl.execute()
+
+ is_true(inspect(connection).has_table("foo"))
+
+ def test_bind_create_index_deprecated(self, connection):
+ t1 = Table("foo", MetaData(), Column("id", Integer))
+ t1.create(connection)
+
+ idx = schema.Index("foo_idx", t1.c.id)
+
+ with testing.expect_deprecated_20(
+ "The CreateIndex.bind argument is deprecated"
+ ):
+ ddl = schema.CreateIndex(idx, bind=connection)
+
+ with testing.expect_deprecated_20(
+ r"The DDLElement.execute\(\) method is considered legacy"
+ ):
+ ddl.execute()
+
+ is_true(
+ "foo_idx"
+ in [ix["name"] for ix in inspect(connection).get_indexes("foo")]
+ )
+
+ def test_bind_drop_table_deprecated(self, connection):
+ t1 = Table("foo", MetaData(), Column("id", Integer))
+
+ t1.create(connection)
+
+ with testing.expect_deprecated_20(
+ "The DropTable.bind argument is deprecated"
+ ):
+ ddl = schema.DropTable(t1, bind=connection)
+
+ with testing.expect_deprecated_20(
+ r"The DDLElement.execute\(\) method is considered legacy"
+ ):
+ ddl.execute()
+
+ is_false(inspect(connection).has_table("foo"))
+
+ def test_bind_drop_index_deprecated(self, connection):
+ t1 = Table("foo", MetaData(), Column("id", Integer))
+ idx = schema.Index("foo_idx", t1.c.id)
+ t1.create(connection)
+
+ is_true(
+ "foo_idx"
+ in [ix["name"] for ix in inspect(connection).get_indexes("foo")]
+ )
+
+ with testing.expect_deprecated_20(
+ "The DropIndex.bind argument is deprecated"
+ ):
+ ddl = schema.DropIndex(idx, bind=connection)
+
+ with testing.expect_deprecated_20(
+ r"The DDLElement.execute\(\) method is considered legacy"
+ ):
+ ddl.execute()
+
+ is_false(
+ "foo_idx"
+ in [ix["name"] for ix in inspect(connection).get_indexes("foo")]
+ )
+
+ @testing.combinations(
+ (schema.AddConstraint,),
+ (schema.DropConstraint,),
+ (schema.CreateSequence,),
+ (schema.DropSequence,),
+ (schema.CreateSchema,),
+ (schema.DropSchema,),
+ (schema.SetTableComment,),
+ (schema.DropTableComment,),
+ (schema.SetColumnComment,),
+ (schema.DropColumnComment,),
+ )
+ def test_bind_other_constructs(self, const):
+ m1 = mock.Mock()
+
+ with testing.expect_deprecated_20(
+ "The DDLElement.bind argument is deprecated"
+ ):
+ c1 = const(m1, bind=testing.db)
+
+ is_(c1.bind, testing.db)