Permalink
Browse files

Performance improvements after refactors in previous commit

  • Loading branch information...
evanelias committed Jun 1, 2018
1 parent b9b4e1c commit 32618e4b0f4f7e9439294be6f759bcda65bd88c0
Showing with 87 additions and 74 deletions.
  1. +1 −1 Godeps/Godeps.json
  2. +9 −17 cmd_init.go
  3. +7 −3 cmd_pull.go
  4. +1 −1 cmd_push.go
  5. +1 −5 dir.go
  6. +3 −4 skeema_test.go
  7. +11 −4 target.go
  8. +54 −39 vendor/github.com/skeema/tengo/instance.go
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -94,24 +94,16 @@ func InitHandler(cfg *mybase.Config) error {
}
// Build list of schemas
var schemas []*tengo.Schema
schemaNameFilter := []string{}
if onlySchema != "" {
if has, err := inst.HasSchema(onlySchema); err != nil {
return err
} else if !has {
return NewExitValue(CodeBadConfig, "Schema %s does not exist on instance %s", onlySchema, inst)
}
s, err := inst.Schema(onlySchema)
if err != nil {
return NewExitValue(CodeFatalError, "Cannot examine schema %s: %s", onlySchema, err)
}
schemas = []*tengo.Schema{s}
} else {
var err error
schemas, err = inst.Schemas()
if err != nil {
return NewExitValue(CodeFatalError, "Cannot examine schemas on %s: %s", inst, err)
}
schemaNameFilter = []string{onlySchema}
}
schemas, err := inst.Schemas(schemaNameFilter...)
if err != nil {
return NewExitValue(CodeFatalError, "Cannot examine schemas on %s: %s", inst, err)
}
if onlySchema != "" && len(schemas) == 0 {
return NewExitValue(CodeBadConfig, "Schema %s does not exist on instance %s", onlySchema, inst)
}
// Look up server charset and collation, so that we know which schemas override
View
@@ -294,12 +294,16 @@ func findNewSchemas(dir *Dir) error {
} else if inst == nil {
return fmt.Errorf("Unable to obtain instance for %s", dir)
}
schemas, err := inst.Schemas()
schemaNames, err := inst.SchemaNames()
if err != nil {
return err
}
for _, s := range schemas {
if !subdirHasSchema[s.Name] {
for _, name := range schemaNames {
if !subdirHasSchema[name] {
s, err := inst.Schema(name)
if err != nil {
return err
}
// use same logic from init command
if err := PopulateSchemaDir(s, dir, true, instCharSet != s.CharSet, instCollation != s.Collation); err != nil {
return err
View
@@ -164,7 +164,7 @@ func pushWorker(sps *sharedPushState) {
targetStmtCount++
if !sps.dryRun {
if strings.HasPrefix(diff.SchemaDDL, "CREATE DATABASE") && t.SchemaFromInstance == nil {
t.SchemaFromInstance, err = t.Instance.CreateSchema(schemaName, t.SchemaFromDir.CharSet, t.SchemaFromDir.Collation)
_, err = t.Instance.CreateSchema(schemaName, t.SchemaFromDir.CharSet, t.SchemaFromDir.Collation)
if err != nil {
sps.setFatalError(fmt.Errorf("Error creating schema %s on %s: %s", schemaName, t.Instance, err))
return
View
6 dir.go
@@ -274,14 +274,10 @@ func (dir *Dir) SchemaNames(instance *tengo.Instance) ([]string, error) {
if schemaValue == "*" {
// This automatically already filters out information_schema, performance_schema, sys, test, mysql
schemasByName, err := instance.SchemasByName()
schemaNames, err := instance.SchemaNames()
if err != nil {
return nil, err
}
schemaNames := make([]string, 0, len(schemasByName))
for name := range schemasByName {
schemaNames = append(schemaNames, name)
}
// Schema name list must be sorted so that generateTargetsForDir with
// firstOnly==true consistently grabs the alphabetically first schema
sort.Strings(schemaNames)
View
@@ -290,19 +290,18 @@ func (s *SkeemaIntegrationSuite) objectExists(schemaName, tableName, columnName
}
if tableName == "" && columnName == "" {
phrase = fmt.Sprintf("schema %s", schemaName)
has, err := s.d.HasSchema(schemaName)
return has, phrase, err
} else if columnName == "" {
phrase = fmt.Sprintf("table %s.%s", schemaName, tableName)
} else {
phrase = fmt.Sprintf("column %s.%s.%s", schemaName, tableName, columnName)
}
schema, err := s.d.Schema(schemaName)
if tableName == "" && columnName == "" {
return schema != nil, phrase, err
} else if err != nil {
if err != nil {
return false, phrase, fmt.Errorf("Unable to obtain %s: %s", phrase, err)
}
table := schema.Table(tableName)
if columnName == "" {
return table != nil, phrase, err
View
@@ -146,14 +146,15 @@ func generateTargetsForDir(dir *Dir, targetsByInstance TargetGroupMap, firstOnly
targetsByInstance.AddInstanceError(inst, dir, err)
continue
}
schemasByName, err := inst.SchemasByName()
if len(schemaNames) > 1 && firstOnly {
schemaNames = schemaNames[0:1]
}
schemasByName, err := inst.SchemasByName(schemaNames...)
if err != nil {
targetsByInstance.AddInstanceError(inst, dir, err)
continue
}
if len(schemaNames) > 1 && firstOnly {
schemaNames = schemaNames[0:1]
}
for _, schemaName := range schemaNames {
// Copy the template into a new Target. Using inst, set its Instance and
// SchemaFromInstance accordingly. Set its SchemaFromDir to a copy of the
@@ -213,6 +214,12 @@ func generateTargetsForDir(dir *Dir, targetsByInstance TargetGroupMap, firstOnly
// bring a table from the version in SchemaFromInstance to the version in
// SchemaFromDir.
func (t *Target) verifyDiff(diff *tengo.SchemaDiff) (err error) {
// If the schema is being newly created on the instance, we know there are
// no alters and therefore nothing to verify
if t.SchemaFromInstance == nil {
return nil
}
// Populate the temp schema with a copy of the tables from SchemaFromInstance,
// the "before" state of the tables
tempSchemaName := t.Dir.Config.Get("temp-schema")

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 32618e4

Please sign in to comment.