def no_fk_names(self): """foreign key constraints *never* have names in the DB""" return exclusions.only_if( lambda config: exclusions.against(config, "sqlite") and not util.sqla_100 )
def _mariadb_only_102(self, config): return exclusions.against(config, "mysql") and \ sqla_compat._is_mariadb(config.db.dialect) and \ sqla_compat._mariadb_normalized_version_info( config.db.dialect) >= (10, 2) and \ sqla_compat._mariadb_normalized_version_info( config.db.dialect) < (10, 3)
def reflects_fk_options(self): return exclusions.only_on([ "postgresql", "mysql", lambda config: util.sqla_110 and exclusions.against( config, "sqlite"), ])
def _mariadb_102(self, config): return ( exclusions.against(config, "mysql") and sqla_compat._is_mariadb(config.db.dialect) and sqla_compat._mariadb_normalized_version_info(config.db.dialect) > (10, 2) )
def _prep_testing_database(options, file_config): from alembic.testing import config from alembic.testing.exclusions import against from sqlalchemy import schema from alembic import util if util.sqla_08: from sqlalchemy import inspect else: from sqlalchemy.engine.reflection import Inspector inspect = Inspector.from_engine if options.dropfirst: for cfg in config.Config.all_configs(): e = cfg.db inspector = inspect(e) try: view_names = inspector.get_view_names() except NotImplementedError: pass else: for vname in view_names: e.execute(schema._DropView( schema.Table(vname, schema.MetaData()) )) if config.requirements.schemas.enabled_for_config(cfg): try: view_names = inspector.get_view_names( schema="test_schema") except NotImplementedError: pass else: for vname in view_names: e.execute(schema._DropView( schema.Table(vname, schema.MetaData(), schema="test_schema") )) for tname in reversed(inspector.get_table_names( order_by="foreign_key")): e.execute(schema.DropTable( schema.Table(tname, schema.MetaData()) )) if config.requirements.schemas.enabled_for_config(cfg): for tname in reversed(inspector.get_table_names( order_by="foreign_key", schema="test_schema")): e.execute(schema.DropTable( schema.Table(tname, schema.MetaData(), schema="test_schema") )) if against(cfg, "postgresql") and util.sqla_100: from sqlalchemy.dialects import postgresql for enum in inspector.get_enums("*"): e.execute(postgresql.DropEnumType( postgresql.ENUM( name=enum['name'], schema=enum['schema'])))
def check(config): if not exclusions.against(config, "postgresql"): return False count = config.db.scalar( "SELECT count(*) FROM pg_extension " "WHERE extname='%s'" % name) return bool(count)
def check(config): if not exclusions.against(config, "postgresql"): return False count = config.db.scalar( "SELECT count(*) FROM pg_extension " "WHERE extname='%s'" % name ) return bool(count)
def check_uuid_ossp(config): if not exclusions.against(config, "postgresql"): return False try: config.db.execute("SELECT uuid_generate_v4()") return True except: return False
def test_change_type_int_to_boolean(self): self._int_to_boolean_fixture() with self.op.batch_alter_table("hasbool") as batch_op: batch_op.alter_column('x', type_=Boolean(create_constraint=True, name='ck1')) insp = Inspector.from_engine(config.db) if exclusions.against(config, "sqlite"): eq_([ c['type']._type_affinity for c in insp.get_columns('hasbool') if c['name'] == 'x' ], [Boolean]) elif exclusions.against(config, "mysql"): eq_([ c['type']._type_affinity for c in insp.get_columns('hasbool') if c['name'] == 'x' ], [Integer])
def reflects_pk_names(self): """Target driver reflects the name of primary key constraints.""" return exclusions.fails_on_everything_except( 'postgresql', 'oracle', 'mssql', 'sybase', lambda config: ( util.sqla_110 and exclusions.against(config, "sqlite") ) )
def reflects_fk_options(self): return exclusions.only_on( [ "postgresql", "mysql", lambda config: util.sqla_110 and exclusions.against(config, "sqlite"), ] )
def test_remove_computed_default_on_computed(self): """Asserts the current behavior which is that on PG and Oracle, the GENERATED ALWAYS AS is reflected as a server default which we can't tell is actually "computed", so these come out as a modification to the server default. """ m1 = MetaData() m2 = MetaData() Table( "user", m1, Column("id", Integer, primary_key=True), Column("bar", Integer), Column("foo", Integer, sa.Computed("bar + 42")), ) Table( "user", m2, Column("id", Integer, primary_key=True), Column("bar", Integer), Column("foo", Integer), ) diffs = self._fixture(m1, m2) eq_(diffs[0][0][0], "modify_default") eq_(diffs[0][0][2], "user") eq_(diffs[0][0][3], "foo") old = diffs[0][0][-2] new = diffs[0][0][-1] is_(new, None) is_true(isinstance(old, sa.DefaultClause)) if exclusions.against(config, "postgresql"): eq_(str(old.arg.text), "(bar + 42)") elif exclusions.against(config, "oracle"): eq_(str(old.arg.text), '"BAR"+42')
def test_change_type_int_to_boolean(self): self._int_to_boolean_fixture() with self.op.batch_alter_table( "hasbool" ) as batch_op: batch_op.alter_column( 'x', type_=Boolean(create_constraint=True, name='ck1')) insp = Inspector.from_engine(config.db) if exclusions.against(config, "sqlite"): eq_( [c['type']._type_affinity for c in insp.get_columns('hasbool') if c['name'] == 'x'], [Boolean] ) elif exclusions.against(config, "mysql"): eq_( [c['type']._type_affinity for c in insp.get_columns('hasbool') if c['name'] == 'x'], [Integer] )
def _mysql_and_check_constraints_exist(self, config): # 1. we have mysql / mariadb and # 2. it enforces check constraints if exclusions.against(config, "mysql"): if sqla_compat._is_mariadb(config.db.dialect): mnvi = sqla_compat._mariadb_normalized_version_info norm_version_info = mnvi(config.db.dialect) return norm_version_info >= (10, 2) else: norm_version_info = config.db.dialect.server_version_info return norm_version_info >= (8, 0, 16) else: return False
def _mysql_and_check_constraints_exist(self, config): # 1. we have mysql / mariadb and # 2. it enforces check constraints if exclusions.against(config, ["mysql", "mariadb"]): if sqla_compat._is_mariadb(config.db.dialect): mnvi = sqla_compat._mariadb_normalized_version_info norm_version_info = mnvi(config.db.dialect) return norm_version_info >= (10, 2) else: norm_version_info = config.db.dialect.server_version_info return norm_version_info >= (8, 0, 16) else: return False
def mysql_check_col_name_change(self, config): # MySQL has check constraints that enforce an reflect, however # they prevent a column's name from being changed due to a bug in # MariaDB 10.2 as well as MySQL 8.0.16 if exclusions.against(config, "mysql"): if sqla_compat._is_mariadb(config.db.dialect): mnvi = sqla_compat._mariadb_normalized_version_info norm_version_info = mnvi(config.db.dialect) return norm_version_info >= (10, 2) and norm_version_info < ( 10, 2, 22, ) else: norm_version_info = config.db.dialect.server_version_info return norm_version_info >= (8, 0, 16) else: return True
def mysql_check_col_name_change(self, config): # MySQL has check constraints that enforce an reflect, however # they prevent a column's name from being changed due to a bug in # MariaDB 10.2 as well as MySQL 8.0.16 if exclusions.against(config, ["mysql", "mariadb"]): if sqla_compat._is_mariadb(config.db.dialect): mnvi = sqla_compat._mariadb_normalized_version_info norm_version_info = mnvi(config.db.dialect) return norm_version_info >= (10, 2) and norm_version_info < ( 10, 2, 22, ) else: norm_version_info = config.db.dialect.server_version_info return norm_version_info >= (8, 0, 16) else: return True
def reflects_fk_options(self): return exclusions.only_on([ 'postgresql', 'mysql', lambda config: util.sqla_110 and exclusions.against(config, 'sqlite')])
def _mysql_not_mariadb_102(self, config): return exclusions.against(config, "mysql") and ( not sqla_compat._is_mariadb(config.db.dialect) or sqla_compat._mariadb_normalized_version_info(config.db.dialect) < (10, 2))
def _mariadb_102(self, config): return (exclusions.against(config, ["mysql", "mariadb"]) and sqla_compat._is_mariadb(config.db.dialect) and sqla_compat._mariadb_normalized_version_info( config.db.dialect) > (10, 2))
def _mysql_check_constraints_exist(self, config): # 1. we dont have mysql / mariadb or # 2. we have mysql / mariadb that enforces check constraints return not exclusions.against( config, ["mysql", "mariadb" ]) or self._mysql_and_check_constraints_exist(config)
def _mysql_check_constraints_exist(self, config): # 1. we dont have mysql / mariadb or # 2. we have mysql / mariadb that enforces check constraints return not exclusions.against( config, "mysql" ) or self._mysql_and_check_constraints_exist(config)