fix -ignore-tables, -ignore-enums and -ignore-views when -dsn is present
This commit is contained in:
parent
f17d05e823
commit
971e2df442
3 changed files with 138 additions and 78 deletions
|
|
@ -3,6 +3,9 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
sqlitegen "github.com/go-jet/jet/v2/generator/sqlite"
|
||||
"github.com/go-jet/jet/v2/generator/template"
|
||||
|
|
@ -11,8 +14,6 @@ import (
|
|||
"github.com/go-jet/jet/v2/mysql"
|
||||
postgres2 "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/sqlite"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
mysqlgen "github.com/go-jet/jet/v2/generator/mysql"
|
||||
postgresgen "github.com/go-jet/jet/v2/generator/postgres"
|
||||
|
|
@ -112,8 +113,9 @@ func main() {
|
|||
|
||||
switch source {
|
||||
case "postgresql", "postgres":
|
||||
generatorTemplate := genTemplate(postgres2.Dialect, ignoreTablesList, ignoreViewsList, ignoreEnumsList)
|
||||
if dsn != "" {
|
||||
err = postgresgen.GenerateDSN(dsn, schemaName, destDir)
|
||||
err = postgresgen.GenerateDSN(dsn, schemaName, destDir, generatorTemplate)
|
||||
break
|
||||
}
|
||||
dbConn := postgresgen.DBConnection{
|
||||
|
|
@ -131,12 +133,13 @@ func main() {
|
|||
err = postgresgen.Generate(
|
||||
destDir,
|
||||
dbConn,
|
||||
genTemplate(postgres2.Dialect, ignoreTablesList, ignoreViewsList, ignoreEnumsList),
|
||||
generatorTemplate,
|
||||
)
|
||||
|
||||
case "mysql", "mysqlx", "mariadb":
|
||||
generatorTemplate := genTemplate(mysql.Dialect, ignoreTablesList, ignoreViewsList, ignoreEnumsList)
|
||||
if dsn != "" {
|
||||
err = mysqlgen.GenerateDSN(dsn, destDir)
|
||||
err = mysqlgen.GenerateDSN(dsn, destDir, generatorTemplate)
|
||||
break
|
||||
}
|
||||
dbConn := mysqlgen.DBConnection{
|
||||
|
|
@ -151,7 +154,7 @@ func main() {
|
|||
err = mysqlgen.Generate(
|
||||
destDir,
|
||||
dbConn,
|
||||
genTemplate(mysql.Dialect, ignoreTablesList, ignoreViewsList, ignoreEnumsList),
|
||||
generatorTemplate,
|
||||
)
|
||||
case "sqlite":
|
||||
if dsn == "" {
|
||||
|
|
|
|||
|
|
@ -88,17 +88,40 @@ func TestCmdGenerator(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIgnoreTablesViewsEnums(t *testing.T) {
|
||||
cmd := exec.Command("jet",
|
||||
"-source=MySQL",
|
||||
"-dbname=dvds",
|
||||
"-host="+dbconfig.MySqLHost,
|
||||
"-port="+strconv.Itoa(dbconfig.MySQLPort),
|
||||
"-user="+dbconfig.MySQLUser,
|
||||
"-password="+dbconfig.MySQLPassword,
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
}{
|
||||
{
|
||||
name: "with dsn",
|
||||
args: []string{
|
||||
"-dsn=mysql://" + dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds"),
|
||||
"-ignore-tables=actor,ADDRESS,Category, city ,country,staff,store,rental",
|
||||
"-ignore-views=actor_info,CUSTomER_LIST, film_list",
|
||||
"-ignore-enums=film_list_rating,film_rating",
|
||||
"-path="+genTestDir3)
|
||||
"-path=" + genTestDir3,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "without dsn",
|
||||
args: []string{
|
||||
"-source=MySQL",
|
||||
"-dbname=dvds",
|
||||
"-host=" + dbconfig.MySqLHost,
|
||||
"-port=" + strconv.Itoa(dbconfig.MySQLPort),
|
||||
"-user=" + dbconfig.MySQLUser,
|
||||
"-password=" + dbconfig.MySQLPassword,
|
||||
"-ignore-tables=actor,ADDRESS,Category, city ,country,staff,store,rental",
|
||||
"-ignore-views=actor_info,CUSTomER_LIST, film_list",
|
||||
"-ignore-enums=film_list_rating,film_rating",
|
||||
"-path=" + genTestDir3,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := exec.Command("jet", tt.args...)
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
|
|
@ -127,6 +150,8 @@ func TestIgnoreTablesViewsEnums(t *testing.T) {
|
|||
"customer.go", "film.go", "film_actor.go", "film_category.go", "film_text.go", "inventory.go", "language.go",
|
||||
"payment.go", "nicer_but_slower_film_list_rating.go", "nicer_but_slower_film_list.go", "sales_by_film_category.go",
|
||||
"sales_by_store.go", "staff_list.go")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertGeneratedFiles(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -93,13 +93,33 @@ func TestCmdGenerator(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGeneratorIgnoreTables(t *testing.T) {
|
||||
err := os.RemoveAll(genTestDir2)
|
||||
require.NoError(t, err)
|
||||
|
||||
cmd := exec.Command("jet",
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
}{
|
||||
{
|
||||
name: "with dsn",
|
||||
args: []string{
|
||||
"-dsn=" + fmt.Sprintf("postgresql://%s:%s@%s:%d/%s?sslmode=disable",
|
||||
dbconfig.PgUser,
|
||||
dbconfig.PgPassword,
|
||||
dbconfig.PgHost,
|
||||
dbconfig.PgPort,
|
||||
"jetdb",
|
||||
),
|
||||
"-schema=dvds",
|
||||
"-ignore-tables=actor,ADDRESS,country, Film , cITY,",
|
||||
"-ignore-views=Actor_info, FILM_LIST ,staff_list",
|
||||
"-ignore-enums=mpaa_rating",
|
||||
"-path=" + genTestDir2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "without dsn",
|
||||
args: []string{
|
||||
"-source=PostgreSQL",
|
||||
"-host=localhost",
|
||||
"-port="+strconv.Itoa(dbconfig.PgPort),
|
||||
"-port=" + strconv.Itoa(dbconfig.PgPort),
|
||||
"-user=jet",
|
||||
"-password=jet",
|
||||
"-dbname=jetdb",
|
||||
|
|
@ -107,7 +127,17 @@ func TestGeneratorIgnoreTables(t *testing.T) {
|
|||
"-ignore-tables=actor,ADDRESS,country, Film , cITY,",
|
||||
"-ignore-views=Actor_info, FILM_LIST ,staff_list",
|
||||
"-ignore-enums=mpaa_rating",
|
||||
"-path="+genTestDir2)
|
||||
"-path=" + genTestDir2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := os.RemoveAll(genTestDir2)
|
||||
require.NoError(t, err)
|
||||
|
||||
cmd := exec.Command("jet", tt.args...)
|
||||
|
||||
fmt.Println(cmd.Args)
|
||||
cmd.Stderr = os.Stderr
|
||||
|
|
@ -143,6 +173,8 @@ func TestGeneratorIgnoreTables(t *testing.T) {
|
|||
"payment.go", "rental.go", "staff.go", "store.go",
|
||||
"nicer_but_slower_film_list.go", "sales_by_film_category.go",
|
||||
"customer_list.go", "sales_by_store.go")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerator(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue