diff options
author | 2022-04-24 12:26:22 +0200 | |
---|---|---|
committer | 2022-04-24 12:26:22 +0200 | |
commit | 88979b35d462516e1765524d70a41c0d26eec911 (patch) | |
tree | fd37cb19317217e226ee7717824f24031f53b031 /vendor/github.com/uptrace/bun/query_table_create.go | |
parent | Revert "[chore] Tidy up federating db locks a tiny bit (#472)" (#479) (diff) | |
download | gotosocial-88979b35d462516e1765524d70a41c0d26eec911.tar.xz |
[chore] Update bun and sqlite dependencies (#478)
* update bun + sqlite versions
* step bun to v1.1.3
Diffstat (limited to 'vendor/github.com/uptrace/bun/query_table_create.go')
-rw-r--r-- | vendor/github.com/uptrace/bun/query_table_create.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/vendor/github.com/uptrace/bun/query_table_create.go b/vendor/github.com/uptrace/bun/query_table_create.go index f2312bc69..4aad10070 100644 --- a/vendor/github.com/uptrace/bun/query_table_create.go +++ b/vendor/github.com/uptrace/bun/query_table_create.go @@ -102,6 +102,21 @@ func (q *CreateTableQuery) TableSpace(tablespace string) *CreateTableQuery { return q } +func (q *CreateTableQuery) WithForeignKeys() *CreateTableQuery { + for _, relation := range q.tableModel.Table().Relations { + if relation.Type == schema.ManyToManyRelation || + relation.Type == schema.HasManyRelation { + continue + } + q = q.ForeignKey("(?) REFERENCES ? (?)", + Safe(appendColumns(nil, "", relation.BaseFields)), + relation.JoinTable.SQLName, + Safe(appendColumns(nil, "", relation.JoinFields)), + ) + } + return q +} + //------------------------------------------------------------------------------ func (q *CreateTableQuery) Operation() string { @@ -121,7 +136,7 @@ func (q *CreateTableQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []by b = append(b, "TEMP "...) } b = append(b, "TABLE "...) - if q.ifNotExists { + if q.ifNotExists && fmter.Dialect().Features().Has(feature.TableNotExists) { b = append(b, "IF NOT EXISTS "...) } b, err = q.appendFirstTable(fmter, b) @@ -142,8 +157,13 @@ func (q *CreateTableQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []by if field.NotNull { b = append(b, " NOT NULL"...) } - if fmter.Dialect().Features().Has(feature.AutoIncrement) && field.AutoIncrement { - b = append(b, " AUTO_INCREMENT"...) + if field.AutoIncrement { + switch { + case fmter.Dialect().Features().Has(feature.AutoIncrement): + b = append(b, " AUTO_INCREMENT"...) + case fmter.Dialect().Features().Has(feature.Identity): + b = append(b, " IDENTITY"...) + } } if field.SQLDefault != "" { b = append(b, " DEFAULT "...) |