From 1ac16188fcbc657e6d13e5e50a2d2645f4e387d2 Mon Sep 17 00:00:00 2001 From: Isaque Alves Date: Fri, 17 Jun 2022 01:34:55 -0300 Subject: [PATCH] refactor: Improve db inspection - Add support to postgresql numeric type. - Improve field configuration handling for numeric and decimal types --- aerich/inspect/__init__.py | 9 +++++++-- aerich/inspect/postgres.py | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/aerich/inspect/__init__.py b/aerich/inspect/__init__.py index 25d7d24..ee7fd1b 100644 --- a/aerich/inspect/__init__.py +++ b/aerich/inspect/__init__.py @@ -30,8 +30,13 @@ class Column(BaseModel): index = "index=True, " if self.data_type in ["varchar", "VARCHAR"]: length = f"max_length={self.length}, " - if self.data_type == "decimal": - length = f"max_digits={self.max_digits}, decimal_places={self.decimal_places}, " + if self.data_type in ["decimal", "numeric"]: + length_parts = [] + if self.max_digits: + length_parts.append(f"max_digits={self.max_digits}") + if self.decimal_places: + length_parts.append(f"decimal_places={self.decimal_places}") + length = "".join(length_parts) if self.null: null = "null=True, " if self.default is not None: diff --git a/aerich/inspect/postgres.py b/aerich/inspect/postgres.py index a30b947..8327618 100644 --- a/aerich/inspect/postgres.py +++ b/aerich/inspect/postgres.py @@ -25,6 +25,7 @@ class InspectPostgres(Inspect): "date": self.date_field, "time": self.time_field, "decimal": self.decimal_field, + "numeric": self.decimal_field, "uuid": self.uuid_field, "jsonb": self.json_field, "bytea": self.binary_field,