Fix pg model generation without tag (#1407)

1. fix pg model struct haven't tag
2. add pg command test from datasource
master
spectatorMrZ 3 years ago committed by GitHub
parent 9d67fc4cfb
commit 240132e7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,45 @@
package command
import (
"github.com/stretchr/testify/assert"
"github.com/tal-tech/go-zero/tools/goctl/config"
"github.com/tal-tech/go-zero/tools/goctl/model/sql/gen"
"github.com/tal-tech/go-zero/tools/goctl/util"
"path/filepath"
"testing"
)
// generate test table sql
/*
CREATE TABLE "public"."users" (
"id" serial NOT NULL,
"account" varchar(20) COLLATE "pg_catalog"."default" NOT NULL,
"avatar" text COLLATE "pg_catalog"."default",
"nick_name" varchar(60) COLLATE "pg_catalog"."default",
"register_time" timestamp(6) NOT NULL,
"update_time" timestamp(6),
"password" varchar(255) COLLATE "pg_catalog"."default",
"email" varchar(100) COLLATE "pg_catalog"."default",
"reset_key" varchar(10) COLLATE "pg_catalog"."default",
"active" bool NOT NULL DEFAULT true,
CONSTRAINT "users_pk" PRIMARY KEY ("id")
)
;
ALTER TABLE "public"."users"
OWNER TO "postgres";
*/
func TestFromDatasource(t *testing.T) {
err := gen.Clean()
assert.Nil(t, err)
url := "postgres://postgres:postgres@127.0.0.1:5432/demo?sslmode=disable"
pattern := "users" // table name
cfg, err := config.NewConfig("")
tempDir := filepath.Join(util.MustTempDir(), "test")
err = fromPostgreSqlDataSource(url, pattern, tempDir, "public", cfg, false, false)
assert.Nil(t, err)
}

@ -360,6 +360,7 @@ func getTableFields(table *model.Table) (map[string]*Field, error) {
} }
field := &Field{ field := &Field{
NameOriginal: each.Name,
Name: stringx.From(each.Name), Name: stringx.From(each.Name),
DataType: dt, DataType: dt,
Comment: each.Comment, Comment: each.Comment,

Loading…
Cancel
Save