Fix primary key detection.

This commit is contained in:
Aaron L 2016-06-19 16:53:45 -07:00
parent 82115b24e0
commit c07d21cffc
2 changed files with 5 additions and 4 deletions

View file

@ -138,7 +138,7 @@ func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
where constraint_name = $1;`
var rows *sql.Rows
if rows, err = p.dbConn.Query(queryColumns, tableName); err != nil {
if rows, err = p.dbConn.Query(queryColumns, pkey.Name); err != nil {
return nil, err
}
@ -154,12 +154,12 @@ func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
columns = append(columns, column)
}
pkey.Columns = columns
if err = rows.Err(); err != nil {
return nil, err
}
pkey.Columns = columns
return pkey, nil
}

View file

@ -304,7 +304,8 @@ func AutoIncPrimaryKey(cols []dbdrivers.Column, pkey *dbdrivers.PrimaryKey) stri
for _, c := range cols {
if rgxAutoIncColumn.MatchString(c.Default) &&
c.IsNullable == false && c.Type == "int64" {
c.IsNullable == false &&
(strings.HasPrefix(c.Type, "int") || strings.HasPrefix(c.Type, "uint")) {
for _, p := range pkey.Columns {
if c.Name == p {
return p