fix: 0 is falsy, set correct defaults
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
e3f6437245
commit
e1bbcd73ab
2 changed files with 6 additions and 5 deletions
|
|
@ -143,12 +143,13 @@ class PostgresTable(DBTable):
|
|||
|
||||
change_nullability = []
|
||||
for col in self.change_nullability:
|
||||
default = col.default or get_not_null_defaults(col.fieldtype)
|
||||
if isinstance(default, str):
|
||||
default = frappe.db.escape(default)
|
||||
change_nullability.append(
|
||||
f"ALTER COLUMN \"{col.fieldname}\" {'SET' if col.not_nullable else 'DROP'} NOT NULL"
|
||||
)
|
||||
change_nullability.append(
|
||||
f'ALTER COLUMN "{col.fieldname}" SET DEFAULT {col.default or frappe.db.escape(col.default)}'
|
||||
)
|
||||
change_nullability.append(f'ALTER COLUMN "{col.fieldname}" SET DEFAULT {default}')
|
||||
|
||||
if col.not_nullable:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ class DbColumn:
|
|||
return column_def
|
||||
|
||||
null = True
|
||||
default = ""
|
||||
default = None
|
||||
unique = False
|
||||
|
||||
if self.fieldtype in ("Check", "Int"):
|
||||
|
|
@ -240,7 +240,7 @@ class DbColumn:
|
|||
if not null:
|
||||
column_def += " NOT NULL"
|
||||
|
||||
if default:
|
||||
if default is not None:
|
||||
column_def += f" DEFAULT {default}"
|
||||
|
||||
if unique:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue