From 4a916671f1169f29a8998935db79bc1920cfd18f Mon Sep 17 00:00:00 2001 From: wubin1989 <328454505@qq.com> Date: Fri, 29 Dec 2023 15:42:18 +0800 Subject: [PATCH 1/2] ... --- toolkit/dbvendor/ivendor.go | 13 ++++++++----- toolkit/dbvendor/postgres/template.go | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) 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 From c013717b64643ead6c989626284aa7a877a1a6e3 Mon Sep 17 00:00:00 2001 From: wubin1989 <328454505@qq.com> Date: Fri, 29 Dec 2023 15:46:59 +0800 Subject: [PATCH 2/2] v2.2.3 --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"