diff --git a/toolkit/dbvendor/ivendor.go b/toolkit/dbvendor/ivendor.go index bb91586e..350f5bc7 100644 --- a/toolkit/dbvendor/ivendor.go +++ b/toolkit/dbvendor/ivendor.go @@ -76,13 +76,16 @@ type Column struct { // Table defines a table type Table struct { - Name string - Columns []Column - BizColumns []Column - Pk string - Joins []string + TablePrefix string + Name string + Columns []Column + BizColumns []Column + Pk string + Joins []string // 父表 Inherited string + // 该表是否仅用于同步/复制数据 + IsCopy bool } func String(tmplname, tmpl string, data interface{}, pf PlaceholderFormat) (string, error) { diff --git a/toolkit/dbvendor/postgres/template.go b/toolkit/dbvendor/postgres/template.go index 354f802e..44345aef 100644 --- a/toolkit/dbvendor/postgres/template.go +++ b/toolkit/dbvendor/postgres/template.go @@ -1,16 +1,16 @@ package postgres var ( - createTable = `CREATE TABLE "{{.Name}}" ( + createTable = `CREATE TABLE IF NOT EXISTS {{if .TablePrefix }}"{{.TablePrefix}}".{{end}}"{{.Name}}" ( {{- range $co := .Columns }} -"{{$co.Name}}" {{$co.Type}} {{if $co.Nullable}}NULL{{else}}NOT NULL{{end}}{{if $co.Default}} DEFAULT {{$co.Default}}{{end}}, +"{{$co.Name}}" {{$co.Type}} {{if $co.Nullable}}NULL{{else}}NOT NULL{{end}}{{if $co.Default}} DEFAULT '{{$co.Default}}'{{end}}, {{- end }} PRIMARY KEY ("{{.Pk}}")) {{- if .Inherited }} INHERITS ({{.Inherited}}) {{- end }}; -{{- if not .Inherited }} +{{- if and (not .Inherited) (not .IsCopy) }} CREATE OR REPLACE FUNCTION update_updated_at_column() RETURNS TRIGGER AS $$ BEGIN diff --git a/version/version.go b/version/version.go index 0ebed9fd..3acdf7db 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,3 @@ package version -const Release = "v2.2.2" +const Release = "v2.2.3"