perf(postgres): skip unnecessary migrations due to type mismatch (#34784)

This commit is contained in:
Aarol D'Souza 2025-12-29 18:29:22 +05:30 committed by GitHub
parent b39498e7e8
commit 799123c341
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -444,6 +444,8 @@ class PostgresDatabase(PostgresExceptionUtil, Database):
CASE LOWER(a.data_type)
WHEN 'character varying' THEN CONCAT('varchar(', a.character_maximum_length ,')')
WHEN 'timestamp without time zone' THEN 'timestamp'
WHEN 'integer' THEN 'int'
WHEN 'numeric' THEN CONCAT('decimal(', a.numeric_precision, ',', a.numeric_scale, ')')
ELSE a.data_type
END AS type,
BOOL_OR(b.index) AS index,
@ -460,7 +462,7 @@ class PostgresDatabase(PostgresExceptionUtil, Database):
ON SUBSTRING(b.indexdef, '(.*)') LIKE CONCAT('%', a.column_name, '%')
WHERE a.table_name = '{table_name}'
AND a.table_schema = '{self.db_schema}'
GROUP BY a.column_name, a.data_type, a.column_default, a.character_maximum_length, a.is_nullable;
GROUP BY a.column_name, a.data_type, a.column_default, a.character_maximum_length, a.is_nullable, a.numeric_precision, a.numeric_scale;
""",
as_dict=1,
)

View file

@ -1,4 +1,5 @@
import random
from unittest.case import skipIf
import frappe
from frappe.core.doctype.doctype.test_doctype import new_doctype
@ -207,7 +208,10 @@ class TestDBUpdate(IntegrationTestCase):
class TestDBUpdateSanityChecks(IntegrationTestCase):
@run_only_if(db_type_is.MARIADB)
@skipIf(
(frappe.conf.db_type == "sqlite"),
"Not for SQLite for now",
)
def test_no_unnecessary_migrates(self):
doctypes = frappe.get_all("DocType", {"is_virtual": 0, "custom": 0}, pluck="name")