Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions go/vt/sidecardb/sidecardb.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,11 @@ const (
var schemaLocation embed.FS

type sidecarTable struct {
module string // which module uses this table
path string // path of the schema relative to this module
name string // table name
schema string // create table dml
}

func (t *sidecarTable) String() string {
return fmt.Sprintf("%s.%s (%s)", SidecarDBName, t.name, t.module)
}

var sidecarTables []*sidecarTable
var ddlCount *stats.Counter

Expand Down Expand Up @@ -110,21 +105,11 @@ func initSchemaFiles() {
return err
}
if !entry.IsDir() {
var module string
dir, fname := filepath.Split(path)
_, fname := filepath.Split(path)
if !strings.HasSuffix(strings.ToLower(fname), sqlFileExtension) {
log.Infof("Ignoring non-SQL file: %s, found during sidecar database initialization", path)
return nil
}
dirparts := strings.Split(strings.Trim(dir, "/"), "/")
switch len(dirparts) {
case 1:
module = dir
case 2:
module = fmt.Sprintf("%s/%s", dirparts[0], dirparts[1])
default:
return fmt.Errorf("unexpected path value of %s specified for sidecar schema table; expected structure is <module>[/<submodule>]/<tablename>.sql", dir)
}

name := strings.Split(fname, ".")[0]
schema, err := schemaLocation.ReadFile(path)
Expand All @@ -135,7 +120,7 @@ func initSchemaFiles() {
if normalizedSchema, err = validateSchemaDefinition(name, string(schema)); err != nil {
return err
}
sidecarTables = append(sidecarTables, &sidecarTable{name: name, module: module, path: path, schema: normalizedSchema})
sidecarTables = append(sidecarTables, &sidecarTable{name: name, path: path, schema: normalizedSchema})
}
return nil
})
Expand Down