fix: 0 is falsy, set correct defaults

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2023-11-16 13:39:42 +05:30
parent e3f6437245
commit e1bbcd73ab
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F
2 changed files with 6 additions and 5 deletions

View file

@ -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:

View file

@ -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: