@@ -1127,4 +1127,142 @@ mod tests {
11271127 let result = render_entity ( & table) . unwrap ( ) ;
11281128 assert ! ( result. contains( "UniqueConstraint(\" col_a\" , \" col_b\" )," ) ) ;
11291129 }
1130+
1131+ #[ test]
1132+ fn test_used_types_add_column_type_simple_types ( ) {
1133+ let mut used = UsedTypes :: default ( ) ;
1134+
1135+ // Test each simple type individually
1136+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: SmallInt ) , false ) ;
1137+ assert ! ( used. sa_types. contains( "SmallInteger" ) ) ;
1138+
1139+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Integer ) , false ) ;
1140+ assert ! ( used. sa_types. contains( "Integer" ) ) ;
1141+
1142+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: BigInt ) , false ) ;
1143+ assert ! ( used. sa_types. contains( "BigInteger" ) ) ;
1144+
1145+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Real ) , false ) ;
1146+ assert ! ( used. sa_types. contains( "Float" ) ) ;
1147+
1148+ used. add_column_type (
1149+ & ColumnType :: Simple ( SimpleColumnType :: DoublePrecision ) ,
1150+ false ,
1151+ ) ;
1152+ assert ! ( used. sa_types. contains( "Float" ) ) ;
1153+
1154+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Text ) , false ) ;
1155+ assert ! ( used. sa_types. contains( "Text" ) ) ;
1156+
1157+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Boolean ) , false ) ;
1158+ assert ! ( used. sa_types. contains( "Boolean" ) ) ;
1159+
1160+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Date ) , false ) ;
1161+ assert ! ( used. sa_types. contains( "Date" ) ) ;
1162+ assert ! ( used. datetime_types. contains( "date" ) ) ;
1163+
1164+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Time ) , false ) ;
1165+ assert ! ( used. sa_types. contains( "Time" ) ) ;
1166+ assert ! ( used. datetime_types. contains( "time" ) ) ;
1167+
1168+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Timestamp ) , false ) ;
1169+ assert ! ( used. sa_types. contains( "DateTime" ) ) ;
1170+ assert ! ( used. datetime_types. contains( "datetime" ) ) ;
1171+
1172+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Timestamptz ) , false ) ;
1173+ assert ! ( used. sa_types. contains( "DateTime" ) ) ;
1174+
1175+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Interval ) , false ) ;
1176+ assert ! ( used. sa_types. contains( "Interval" ) ) ;
1177+
1178+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Bytea ) , false ) ;
1179+ assert ! ( used. sa_types. contains( "LargeBinary" ) ) ;
1180+
1181+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Uuid ) , false ) ;
1182+ assert ! ( used. sa_types. contains( "Uuid" ) ) ;
1183+ assert ! ( used. needs_uuid) ;
1184+
1185+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Json ) , false ) ;
1186+ assert ! ( used. sa_types. contains( "JSON" ) ) ;
1187+
1188+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Jsonb ) , false ) ;
1189+ assert ! ( used. sa_types. contains( "JSON" ) ) ;
1190+
1191+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Inet ) , false ) ;
1192+ assert ! ( used. sa_types. contains( "String" ) ) ;
1193+
1194+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Cidr ) , false ) ;
1195+ assert ! ( used. sa_types. contains( "String" ) ) ;
1196+
1197+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Macaddr ) , false ) ;
1198+ assert ! ( used. sa_types. contains( "String" ) ) ;
1199+
1200+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Xml ) , false ) ;
1201+ assert ! ( used. sa_types. contains( "Text" ) ) ;
1202+ }
1203+
1204+ #[ test]
1205+ fn test_used_types_add_column_type_complex_types ( ) {
1206+ let mut used = UsedTypes :: default ( ) ;
1207+
1208+ used. add_column_type (
1209+ & ColumnType :: Complex ( ComplexColumnType :: Varchar { length : 100 } ) ,
1210+ false ,
1211+ ) ;
1212+ assert ! ( used. sa_types. contains( "String" ) ) ;
1213+
1214+ used. add_column_type (
1215+ & ColumnType :: Complex ( ComplexColumnType :: Char { length : 10 } ) ,
1216+ false ,
1217+ ) ;
1218+ assert ! ( used. sa_types. contains( "String" ) ) ;
1219+
1220+ used. add_column_type (
1221+ & ColumnType :: Complex ( ComplexColumnType :: Numeric {
1222+ precision : 10 ,
1223+ scale : 2 ,
1224+ } ) ,
1225+ false ,
1226+ ) ;
1227+ assert ! ( used. sa_types. contains( "Numeric" ) ) ;
1228+ assert ! ( used. needs_decimal) ;
1229+
1230+ used. add_column_type (
1231+ & ColumnType :: Complex ( ComplexColumnType :: Custom {
1232+ custom_type : "FOO" . into ( ) ,
1233+ } ) ,
1234+ false ,
1235+ ) ;
1236+ // Custom type doesn't add any sa_types
1237+
1238+ used. add_column_type (
1239+ & ColumnType :: Complex ( ComplexColumnType :: Enum {
1240+ name : "status" . into ( ) ,
1241+ values : EnumValues :: String ( vec ! [ "a" . into( ) ] ) ,
1242+ } ) ,
1243+ false ,
1244+ ) ;
1245+ assert ! ( used. sa_types. contains( "Enum" ) ) ;
1246+
1247+ let mut used2 = UsedTypes :: default ( ) ;
1248+ used2. add_column_type (
1249+ & ColumnType :: Complex ( ComplexColumnType :: Enum {
1250+ name : "priority" . into ( ) ,
1251+ values : EnumValues :: Integer ( vec ! [ NumValue {
1252+ name: "Low" . into( ) ,
1253+ value: 0 ,
1254+ } ] ) ,
1255+ } ) ,
1256+ false ,
1257+ ) ;
1258+ assert ! ( used2. sa_types. contains( "Integer" ) ) ;
1259+ }
1260+
1261+ #[ test]
1262+ fn test_used_types_nullable_sets_optional ( ) {
1263+ let mut used = UsedTypes :: default ( ) ;
1264+ assert ! ( !used. needs_optional) ;
1265+ used. add_column_type ( & ColumnType :: Simple ( SimpleColumnType :: Integer ) , true ) ;
1266+ assert ! ( used. needs_optional) ;
1267+ }
11301268}
0 commit comments