Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #281 from ashoda/support_multiple_statements
Browse files Browse the repository at this point in the history
(Spanner) Add support for multiple statements in one migration step
  • Loading branch information
mattes authored Oct 9, 2017
2 parents be1b075 + 28cb030 commit 5b98c13
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions database/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ func (s *Spanner) Run(migration io.Reader) error {
}

// run migration
stmt := string(migr[:])
stmts := migrationStatements(migr)
ctx := context.Background()

op, err := s.db.admin.UpdateDatabaseDdl(ctx, &adminpb.UpdateDatabaseDdlRequest{
Database: s.config.DatabaseName,
Statements: []string{stmt},
Statements: stmts,
})

if err != nil {
Expand Down Expand Up @@ -282,3 +282,13 @@ func (s *Spanner) ensureVersionTable() error {

return nil
}

func migrationStatements(migration []byte) []string {
regex := regexp.MustCompile(";$")
migrationString := string(migration[:])
migrationString = strings.TrimSpace(migrationString)
migrationString = regex.ReplaceAllString(migrationString, "")

statements := strings.Split(migrationString, ";")
return statements
}

0 comments on commit 5b98c13

Please sign in to comment.