File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -21,23 +21,24 @@ var primaryKeyTypes = map[string]bool{
2121
2222type GuessOption func (database.Schema , database.PrimaryKey ) bool
2323
24- func isPrimaryKeyType (dataType string ) bool {
25- _ , ok := primaryKeyTypes [dataType ]
26- return ok
24+ func isAcceptableAsPrimaryKey (columnType , primaryKeyType string ) bool {
25+ _ , colIsOk := primaryKeyTypes [columnType ]
26+ _ , pkIsOk := primaryKeyTypes [primaryKeyType ]
27+ return colIsOk && pkIsOk && columnType == primaryKeyType
2728}
2829
2930// Recongnize a column thats same name of other table's primary key is a foreign key
3031// This base idea refers to SchemaSpy DbAnalyzer:
3132// https://github.com/schemaspy/schemaspy/blob/master/src/main/java/org/schemaspy/DbAnalyzer.java
3233func GuessByPrimaryKey () GuessOption {
3334 return func (s database.Schema , pk database.PrimaryKey ) bool {
34- return isPrimaryKeyType ( pk . DataType ) && s .DataType == pk .DataType && s .Column == pk .Column && pk .Column != idColumn
35+ return isAcceptableAsPrimaryKey ( s .DataType , pk .DataType ) && s .Column == pk .Column && pk .Column != idColumn
3536 }
3637}
3738
3839func GuessByTableAndColumn () GuessOption {
3940 return func (s database.Schema , pk database.PrimaryKey ) bool {
40- if ! isPrimaryKeyType ( pk . DataType ) && s .DataType != pk .DataType {
41+ if ! isAcceptableAsPrimaryKey ( s .DataType , pk .DataType ) {
4142 return false
4243 }
4344
You can’t perform that action at this time.
0 commit comments