Skip to content

Commit f3d9c3e

Browse files
authored
Merge pull request #6 from nickmitchko/DPP-412796
IRIS workaround & SQL compatability
2 parents b02dcb1 + 95b503f commit f3d9c3e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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+
# }

0 commit comments

Comments
 (0)