ent: allow non-numeric columns as PKs

Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/180

Reviewed By: alexsn

Differential Revision: D18636443

fbshipit-source-id: f14b34926817f6d9652f49a640bfb377f3f3cdaf
This commit is contained in:
Ariel Mashraki
2019-11-21 08:48:12 -08:00
committed by Facebook Github Bot
parent bc4284cf2c
commit e54373f410
3 changed files with 21 additions and 9 deletions

View File

@@ -75,9 +75,10 @@ func (d *SQLite) tBuilder(t *Table) *sql.TableBuilder {
for _, fk := range t.ForeignKeys {
b.ForeignKeys(fk.DSL())
}
// if it's an ID based primary key, we add the `PRIMARY KEY`
// clause to the column declaration.
if len(t.PrimaryKey) == 1 {
// If it's an ID based primary key with autoincrement, we add
// the `PRIMARY KEY` clause to the column declaration. Otherwise,
// we append it to the constraint clause.
if len(t.PrimaryKey) == 1 && t.PrimaryKey[0].Increment {
return b
}
for _, pk := range t.PrimaryKey {