Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny refactor onSchemaCreate function. #471

Merged
Merged
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
23 changes: 10 additions & 13 deletions ddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ func (d *ddl) onSchemaCreate(t *meta.TMeta, job *model.Job) error {
return errors.Trace(err)
}

var dbInfo *model.DBInfo
dbInfo := &model.DBInfo{
ID: schemaID,
Name: name,
State: model.StateNone,
}

dbs, err := t.ListDatabases()
if err != nil {
return errors.Trace(err)
Expand All @@ -54,21 +59,13 @@ func (d *ddl) onSchemaCreate(t *meta.TMeta, job *model.Job) error {
return errors.Trace(err)
}

if dbInfo == nil {
// first create, enter delete only state
dbInfo = &model.DBInfo{
ID: schemaID,
Name: name,
State: model.StateDeleteOnly,
}

switch dbInfo.State {
case model.StateNone:
// none -> delete only
job.SchemaState = model.StateDeleteOnly

dbInfo.State = model.StateDeleteOnly
err = t.CreateDatabase(dbInfo)
return errors.Trace(err)
}

switch dbInfo.State {
case model.StateDeleteOnly:
// delete only -> write only
job.SchemaState = model.StateWriteOnly
Expand Down