Skip to content

Commit 3d11453

Browse files
nmitchkonmitchko
authored andcommitted
Changes for Alert Statements, NO DEFAULT
1 parent 73fc66c commit 3d11453

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

django_iris/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,13 @@ def is_usable(self):
182182
return False
183183
else:
184184
return True
185+
186+
def schema_editor(self, *args, **kwargs):
187+
"""
188+
Return a new instance of this backend's SchemaEditor.
189+
"""
190+
if self.SchemaEditorClass is None:
191+
raise NotImplementedError(
192+
"The SchemaEditorClass attribute of this database wrapper is still None"
193+
)
194+
return DatabaseSchemaEditor(self, *args, **kwargs)

django_iris/compiler.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django.core.exceptions import FieldError
2+
from django.db.models.expressions import Col
3+
from django.db.models.sql import compiler
4+
5+
class SQLCompiler(compiler.SQLCompiler):
6+
def as_subquery_condition(self, alias: str, columns, compiler):
7+
return super().as_subquery_condition(alias, columns, compiler)
8+
9+
10+
class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):
11+
def as_sql(self):
12+
return super().as_sql()
13+
14+
15+
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
16+
def as_sql(self):
17+
return super().as_sql()
18+
19+
20+
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler):
21+
def as_sql(self):
22+
return super().as_sql()
23+
24+
25+
class SQLAggregateCompiler(compiler.SQLAggregateCompiler, SQLCompiler):
26+
def as_sql(self):
27+
return super().as_sql()

django_iris/operations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import traceback
99

1010
class DatabaseOperations(BaseDatabaseOperations):
11+
12+
# compiler_module = "django_iris.compiler"
13+
1114
def quote_name(self, name):
1215
if name.startswith('"') and name.endswith('"'):
1316
return name # Quoting once is enough.

django_iris/schema.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
44
from django.db import NotSupportedError
55

6+
67
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
78
sql_alter_column_type = "ALTER COLUMN %(column)s %(type)s"
89
sql_alter_column_null = "ALTER COLUMN %(column)s NULL"
910

11+
# Fix for correct alter column syntax
12+
# ALTER TABLE tablename ALTER COLUMN oldname RENAME newname
13+
sql_rename_column = (
14+
"ALTER TABLE %(table)s ALTER COLUMN %(old_column)s RENAME %(new_column)s"
15+
)
16+
17+
sql_rename_table = "ALTER TABLE %(old_table)s RENAME %(new_table)s"
18+
1019
def quote_value(self, value):
1120
if isinstance(value, bool):
1221
return str(int(value))
@@ -26,4 +35,25 @@ def table_sql(self, model):
2635
raise NotSupportedError(
2736
"Invalid table name '%s'" % (model._meta.db_table)
2837
)
29-
return super().table_sql(model)
38+
return super().table_sql(model)
39+
40+
def skip_default_on_alter(self, field):
41+
"""
42+
Some backends don't accept default values for certain columns types
43+
(i.e. MySQL longtext and longblob) in the ALTER COLUMN statement.
44+
"""
45+
return True
46+
47+
# Due to DP-412796 and DP-412798 disable default fields
48+
# on alter statements
49+
def skip_default(self, field):
50+
# return super().skip_default(field)
51+
return True
52+
53+
# def _rename_field_sql(self, table, old_field, new_field, new_type):
54+
# return self.sql_rename_column % {
55+
# "table": self.quote_name(table),
56+
# "old_column": self.quote_name(old_field.column),
57+
# "new_column": self.quote_name(new_field.column),
58+
# "type": new_type,
59+
# }

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = django-iris
3-
version = 0.1.7
3+
version = 0.1.8b4
44
url = https://github.com/caretdev/django-iris
55
maintainer = CaretDev
66
maintainer_email = [email protected]

0 commit comments

Comments
 (0)