Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed Dec 29, 2023
1 parent c013717 commit 3de00bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
2 changes: 0 additions & 2 deletions toolkit/dbvendor/ivendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ type Table struct {
Joins []string
// 父表
Inherited string
// 该表是否仅用于同步/复制数据
IsCopy bool
}

func String(tmplname, tmpl string, data interface{}, pf PlaceholderFormat) (string, error) {
Expand Down
20 changes: 3 additions & 17 deletions toolkit/dbvendor/postgres/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,9 @@ PRIMARY KEY ("{{.Pk}}"))
{{- if .Inherited }}
INHERITS ({{.Inherited}})
{{- end }};
{{- if and (not .Inherited) (not .IsCopy) }}
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
IF row(NEW.*) IS DISTINCT FROM row(OLD.*) THEN
NEW.updated_at = now();
RETURN NEW;
ELSE
RETURN OLD;
END IF;
END;
$$ language 'plpgsql';
CREATE TRIGGER update_{{.Name}}_updated_at BEFORE UPDATE ON {{.Name}} FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
ALTER TABLE "{{.Name}}" ALTER created_at TYPE timestamptz USING created_at AT TIME ZONE 'Asia/Shanghai';
ALTER TABLE "{{.Name}}" ALTER updated_at TYPE timestamptz USING updated_at AT TIME ZONE 'Asia/Shanghai';
{{- range $co := .Columns }}
COMMENT ON COLUMN {{if $.TablePrefix }}"{{$.TablePrefix}}".{{end}}"{{$.Name}}"."{{$co.Name}}" IS {{if $co.Comment}}'{{$co.Comment}}'{{else}}''{{end}};
{{- end }}
`

Expand Down

0 comments on commit 3de00bc

Please sign in to comment.