mirror of https://github.com/status-im/migrate.git
Merge pull request #281 from ashoda/support_multiple_statements
(Spanner) Add support for multiple statements in one migration step
This commit is contained in:
commit
5b98c13eff
|
@ -137,12 +137,12 @@ func (s *Spanner) Run(migration io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// run migration
|
// run migration
|
||||||
stmt := string(migr[:])
|
stmts := migrationStatements(migr)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
op, err := s.db.admin.UpdateDatabaseDdl(ctx, &adminpb.UpdateDatabaseDdlRequest{
|
op, err := s.db.admin.UpdateDatabaseDdl(ctx, &adminpb.UpdateDatabaseDdlRequest{
|
||||||
Database: s.config.DatabaseName,
|
Database: s.config.DatabaseName,
|
||||||
Statements: []string{stmt},
|
Statements: stmts,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -282,3 +282,13 @@ func (s *Spanner) ensureVersionTable() error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue