Merge pull request #138 from nkonin/fix/dsn-ignore-tables
fix -ignore-tables, -ignore-enums and -ignore-views when -dsn is present
This commit is contained in:
commit
3ff9241eea
5 changed files with 214 additions and 78 deletions
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: gomod
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
70
.github/workflows/codeql-analysis.yml
vendored
Normal file
70
.github/workflows/codeql-analysis.yml
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '36 17 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
|
@ -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