Implement schemagen ignore-indexes flag
Co-authored by Alexander Setzer <Alexander.Setzer@alfatraining.de>
This commit is contained in:
committed by
Roy Dahan
parent
e8f30f8dda
commit
8bda349563
@@ -20,14 +20,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||||
flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
|
flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
|
||||||
flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect")
|
flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect")
|
||||||
flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package")
|
flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package")
|
||||||
flagOutput = cmd.String("output", "models", "the name of the folder to output to")
|
flagOutput = cmd.String("output", "models", "the name of the folder to output to")
|
||||||
flagUser = cmd.String("user", "", "user for password authentication")
|
flagUser = cmd.String("user", "", "user for password authentication")
|
||||||
flagPassword = cmd.String("password", "", "password for password authentication")
|
flagPassword = cmd.String("password", "", "password for password authentication")
|
||||||
flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore")
|
flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore")
|
||||||
|
flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -88,6 +89,13 @@ func renderTemplate(md *gocql.KeyspaceMetadata) ([]byte, error) {
|
|||||||
for _, ignoredName := range strings.Split(*flagIgnoreNames, ",") {
|
for _, ignoredName := range strings.Split(*flagIgnoreNames, ",") {
|
||||||
ignoredNames[ignoredName] = struct{}{}
|
ignoredNames[ignoredName] = struct{}{}
|
||||||
}
|
}
|
||||||
|
if *flagIgnoreIndexes {
|
||||||
|
for name := range md.Tables {
|
||||||
|
if strings.HasSuffix(name, "_index") {
|
||||||
|
ignoredNames[name] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for name := range ignoredNames {
|
for name := range ignoredNames {
|
||||||
delete(md.Tables, name)
|
delete(md.Tables, name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ func TestSchemagen(t *testing.T) {
|
|||||||
"composers_by_name",
|
"composers_by_name",
|
||||||
"label",
|
"label",
|
||||||
}, ",")
|
}, ",")
|
||||||
|
*flagIgnoreIndexes = true
|
||||||
|
|
||||||
b := runSchemagen(t, "foobar")
|
b := runSchemagen(t, "foobar")
|
||||||
|
|
||||||
const goldenFile = "testdata/models.go.txt"
|
const goldenFile = "testdata/models.go.txt"
|
||||||
@@ -153,6 +155,11 @@ func createTestSchema(t *testing.T) {
|
|||||||
t.Fatal("create table:", err)
|
t.Fatal("create table:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = session.ExecStmt(`CREATE INDEX IF NOT EXISTS songs_title ON schemagen.songs (title)`)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("create index:", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = session.ExecStmt(`CREATE TABLE IF NOT EXISTS schemagen.composers (
|
err = session.ExecStmt(`CREATE TABLE IF NOT EXISTS schemagen.composers (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
name text)`)
|
name text)`)
|
||||||
|
|||||||
Reference in New Issue
Block a user