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

Exposing the ability to pull CQL changesets #5047

Merged
merged 6 commits into from
Dec 13, 2022
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
36 changes: 18 additions & 18 deletions tools/common/schema/updatetask.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ type (
md5 string
}

// changeSet represents all the changes
// ChangeSet represents all the changes
// corresponding to a single schema version
changeSet struct {
version string
ChangeSet struct {
Version string
manifest *manifest
cqlStmts []string
CqlStmts []string
}

// byVersion is a comparator type
Expand Down Expand Up @@ -104,7 +104,7 @@ func (task *UpdateTask) Run() error {
return fmt.Errorf("error reading current schema version:%v", err.Error())
}

updates, err := task.buildChangeSet(currVer)
updates, err := task.BuildChangeSet(currVer)
if err != nil {
return err
}
Expand All @@ -115,8 +115,8 @@ func (task *UpdateTask) Run() error {
log.Println("Found zero updates to run")
}
for _, upd := range updates {
log.Printf("DryRun of updating to version: %s, manifest: %s \n", upd.version, upd.manifest)
for _, stmt := range upd.cqlStmts {
log.Printf("DryRun of updating to version: %s, manifest: %s \n", upd.Version, upd.manifest)
for _, stmt := range upd.CqlStmts {
log.Printf("DryRun query:%s \n", stmt)
}
}
Expand All @@ -131,7 +131,7 @@ func (task *UpdateTask) Run() error {
return nil
}

func (task *UpdateTask) executeUpdates(currVer string, updates []changeSet) error {
func (task *UpdateTask) executeUpdates(currVer string, updates []ChangeSet) error {

if len(updates) == 0 {
log.Printf("found zero updates from current version %v", currVer)
Expand All @@ -141,7 +141,7 @@ func (task *UpdateTask) executeUpdates(currVer string, updates []changeSet) erro
for _, cs := range updates {
csStart := time.Now()

err := task.execCQLStmts(cs.version, cs.cqlStmts)
err := task.execCQLStmts(cs.Version, cs.CqlStmts)
if err != nil {
return err
}
Expand All @@ -150,8 +150,8 @@ func (task *UpdateTask) executeUpdates(currVer string, updates []changeSet) erro
return err
}

log.Printf("Schema updated from %v to %v, elapsed %v\n", currVer, cs.version, time.Since(csStart))
currVer = cs.version
log.Printf("Schema updated from %v to %v, elapsed %v\n", currVer, cs.Version, time.Since(csStart))
currVer = cs.Version
}

log.Printf("All schema changes completed in %v\n", time.Since(updStart))
Expand All @@ -172,9 +172,9 @@ func (task *UpdateTask) execCQLStmts(ver string, stmts []string) error {
return nil
}

func (task *UpdateTask) updateSchemaVersion(oldVer string, cs *changeSet) error {
func (task *UpdateTask) updateSchemaVersion(oldVer string, cs *ChangeSet) error {

err := task.db.UpdateSchemaVersion(cs.version, cs.manifest.MinCompatibleVersion)
err := task.db.UpdateSchemaVersion(cs.Version, cs.manifest.MinCompatibleVersion)
if err != nil {
return fmt.Errorf("failed to update schema_version table, err=%v", err.Error())
}
Expand All @@ -187,7 +187,7 @@ func (task *UpdateTask) updateSchemaVersion(oldVer string, cs *changeSet) error
return nil
}

func (task *UpdateTask) buildChangeSet(currVer string) ([]changeSet, error) {
func (task *UpdateTask) BuildChangeSet(currVer string) ([]ChangeSet, error) {

config := task.config

Expand All @@ -196,7 +196,7 @@ func (task *UpdateTask) buildChangeSet(currVer string) ([]changeSet, error) {
return nil, fmt.Errorf("error listing schema dir:%v", err.Error())
}

var result []changeSet
var result []ChangeSet

for _, vd := range verDirs {

Expand Down Expand Up @@ -226,10 +226,10 @@ func (task *UpdateTask) buildChangeSet(currVer string) ([]changeSet, error) {
return nil, fmt.Errorf("error processing version %v:%v", vd, e.Error())
}

cs := changeSet{}
cs := ChangeSet{}
cs.manifest = m
cs.cqlStmts = stmts
cs.version = m.CurrVersion
cs.CqlStmts = stmts
cs.Version = m.CurrVersion
result = append(result, cs)
}

Expand Down