@@ -505,6 +505,21 @@ def column_updatable(cr, table, column):
505
505
return nfo and nfo [2 ]
506
506
507
507
508
+ def _normalize_pg_type (type_ ):
509
+ aliases = {
510
+ "boolean" : "bool" ,
511
+ "smallint" : "int2" ,
512
+ "integer" : "int4" ,
513
+ "bigint" : "int8" ,
514
+ "real" : "float4" ,
515
+ "double precision" : "float8" ,
516
+ "character varying" : "varchar" ,
517
+ "timestamp with time zone" : "timestamptz" ,
518
+ "timestamp without time zone" : "timestamp" ,
519
+ }
520
+ return aliases .get (type_ .lower (), type_ )
521
+
522
+
508
523
def create_column (cr , table , column , definition , ** kwargs ):
509
524
"""
510
525
Create a column.
@@ -546,18 +561,7 @@ def create_column(cr, table, column, definition, **kwargs):
546
561
elif on_delete_action is not no_def :
547
562
raise ValueError ("`on_delete_action` argument can only be used if `fk_table` argument is set." )
548
563
549
- aliases = {
550
- "boolean" : "bool" ,
551
- "smallint" : "int2" ,
552
- "integer" : "int4" ,
553
- "bigint" : "int8" ,
554
- "real" : "float4" ,
555
- "double precision" : "float8" ,
556
- "character varying" : "varchar" ,
557
- "timestamp with time zone" : "timestamptz" ,
558
- "timestamp without time zone" : "timestamp" ,
559
- }
560
- definition = aliases .get (definition .lower (), definition )
564
+ definition = _normalize_pg_type (definition )
561
565
562
566
if definition == "bool" and default is no_def :
563
567
default = False
@@ -612,6 +616,13 @@ def remove_column(cr, table, column, cascade=False):
612
616
def alter_column_type (cr , table , column , type , using = None , where = None , logger = _logger ):
613
617
if where and not using :
614
618
raise ValueError ("`where` parameter is only relevant with a non-default `using` parameter" )
619
+
620
+ if not using :
621
+ current_type = column_type (cr , table , column )
622
+ if current_type and current_type == _normalize_pg_type (type ):
623
+ logger .info ("Column %r of table %r is already defined as %r" , column , table , type )
624
+ return
625
+
615
626
# remove the existing linked `ir_model_fields_selection` recods in case it was a selection field
616
627
if table_exists (cr , "ir_model_fields_selection" ):
617
628
cr .execute (
0 commit comments