-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ flake8 | |
pytest | ||
black | ||
twine | ||
alembic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import logging | ||
|
||
from sqlalchemy.ext.compiler import compiles | ||
from alembic.ddl import DefaultImpl | ||
from alembic.ddl.base import ColumnNullable | ||
from alembic.ddl.base import ColumnType | ||
from alembic.ddl.base import ColumnName | ||
from alembic.ddl.base import Column | ||
from alembic.ddl.base import alter_table | ||
from alembic.ddl.base import alter_column | ||
from alembic.ddl.base import format_type | ||
from alembic.ddl.base import format_column_name | ||
|
||
from .base import IRISDDLCompiler | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class IRISImpl(DefaultImpl): | ||
__dialect__ = "iris" | ||
|
||
type_synonyms = DefaultImpl.type_synonyms + ( | ||
{"BLOB", "LONGVARBINARY"}, | ||
{"DOUBLE", "FLOAT"}, | ||
{"DATETIME", "TIMESTAMP"}, | ||
) | ||
|
||
def compare_type(self, inspector_column: Column, metadata_column: Column) -> bool: | ||
# Don't change type of IDENTITY column | ||
if ( | ||
metadata_column.primary_key | ||
and metadata_column is metadata_column.table._autoincrement_column | ||
): | ||
return False | ||
|
||
return super().compare_type(inspector_column, metadata_column) | ||
|
||
def compare_server_default( | ||
self, | ||
inspector_column: Column, | ||
metadata_column: Column, | ||
rendered_metadata_default, | ||
rendered_inspector_default, | ||
): | ||
# don't do defaults for IDENTITY columns | ||
if ( | ||
metadata_column.primary_key | ||
and metadata_column is metadata_column.table._autoincrement_column | ||
): | ||
return False | ||
|
||
return super().compare_server_default( | ||
inspector_column, | ||
metadata_column, | ||
rendered_metadata_default, | ||
rendered_inspector_default, | ||
) | ||
|
||
def correct_for_autogen_constraints( | ||
self, | ||
conn_unique_constraints, | ||
conn_indexes, | ||
metadata_unique_constraints, | ||
metadata_indexes, | ||
): | ||
|
||
doubled_constraints = { | ||
index | ||
for index in conn_indexes | ||
if index.info.get("duplicates_constraint") | ||
} | ||
|
||
for ix in doubled_constraints: | ||
conn_indexes.remove(ix) | ||
|
||
# if not sqla_compat.sqla_2: | ||
# self._skip_functional_indexes(metadata_indexes, conn_indexes) | ||
|
||
@compiles(ColumnNullable, "iris") | ||
def visit_column_nullable( | ||
element: ColumnNullable, compiler: IRISDDLCompiler, **kw | ||
) -> str: | ||
return "%s %s %s" % ( | ||
alter_table(compiler, element.table_name, element.schema), | ||
alter_column(compiler, element.column_name), | ||
"NULL" if element.nullable else "NOT NULL", | ||
) | ||
|
||
|
||
@compiles(ColumnType, "iris") | ||
def visit_column_type(element: ColumnType, compiler: IRISDDLCompiler, **kw) -> str: | ||
return "%s %s %s" % ( | ||
alter_table(compiler, element.table_name, element.schema), | ||
alter_column(compiler, element.column_name), | ||
"%s" % format_type(compiler, element.type_), | ||
) | ||
|
||
|
||
@compiles(ColumnName, "iris") | ||
def visit_rename_column(element: ColumnName, compiler: IRISDDLCompiler, **kw) -> str: | ||
return "%s %s RENAME %s" % ( | ||
alter_table(compiler, element.table_name, element.schema), | ||
alter_column(compiler, element.column_name), | ||
format_column_name(compiler, element.newname), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
try: | ||
import alembic # noqa | ||
except: # noqa | ||
pass | ||
else: | ||
from alembic.testing.suite.test_op import ( | ||
BackendAlterColumnTest as _BackendAlterColumnTest, | ||
) | ||
from alembic.testing.suite.test_autogen_diffs import ( | ||
AutoincrementTest as _AutoincrementTest, | ||
) | ||
from alembic.testing.suite import * # noqa | ||
|
||
class BackendAlterColumnTest(_BackendAlterColumnTest): | ||
def test_rename_column(self): | ||
# IRIS Uppercases new names | ||
self._run_alter_col({}, {"name": "NEWNAME"}) | ||
|
||
class AutoincrementTest(_AutoincrementTest): | ||
# pk don't change type | ||
def test_alter_column_autoincrement_pk_implicit_true(self): | ||
pass | ||
|
||
def test_alter_column_autoincrement_pk_explicit_true(self): | ||
pass |