@@ -12,18 +12,44 @@ func init() {
1212 RegisterRule ("DCT01" , changedColumnTypeRule {})
1313}
1414
15+ // ChangedTypeRuleError raised when a Column changed type
16+ type ChangedTypeRuleError struct {
17+ RuleError
18+
19+ OldColumn string `json:"old_column_name"`
20+ OldColumnType string `json:"old_column_type"`
21+ Schema string `json:"schema_name"`
22+ Table string `json:"table_name"`
23+ NewColumnType string `json:"new_column_type"`
24+ }
25+
26+ func (r ChangedTypeRuleError ) Error () string {
27+ return fmt .Sprintf ("[%s] colunm %s type %s of table %s.%s is incohérent in new type %s" ,
28+ r .RuleCode ,
29+ r .OldColumn ,
30+ r .OldColumnType ,
31+ r .Schema ,
32+ r .Table ,
33+ r .NewColumnType ,
34+ )
35+ }
36+
1537func (changedColumnTypeRule ) CheckCompatibility (oldDatabase , newDatabase * model.DatabaseSchema ) []error {
1638 return checkDatabaseSchemaTable (oldDatabase , newDatabase , func (schema model.Schema , oldTable , newTable model.TableSchema ) []error {
1739 errors := make ([]error , 0 )
1840 for _ , oldColumn := range oldTable .Columns {
1941 for _ , newColumn := range newTable .Columns {
2042 if oldColumn .ColunmName == newColumn .ColunmName && oldColumn .ColumnType != newColumn .ColumnType {
21- errors = append (errors , fmt .Errorf ("colunm %s type %s of table %s.%s is incohérent in new type %s" ,
22- oldColumn .ColunmName ,
23- oldColumn .ColumnType ,
24- schema .SchemaName ,
25- oldTable .TableName ,
26- newColumn .ColumnType ))
43+ errors = append (errors , ChangedTypeRuleError {
44+ RuleError : RuleError {
45+ RuleCode : "DCT01" ,
46+ },
47+ OldColumn : oldColumn .ColunmName ,
48+ OldColumnType : oldColumn .ColumnType ,
49+ Schema : schema .SchemaName ,
50+ Table : oldTable .TableName ,
51+ NewColumnType : newColumn .ColumnType ,
52+ })
2753 break
2854 }
2955 }
0 commit comments