feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var controlTable = regexp.MustCompile(`^CREATE TABLE ([a-z_]+) \(`)
|
||||
var controlAdd = regexp.MustCompile(`^ALTER TABLE ([a-z_]+) ADD (COLUMN|CONSTRAINT|UNIQUE KEY|KEY) ([a-z_]+)\b`)
|
||||
var controlDrop = regexp.MustCompile(`^ALTER TABLE ([a-z_]+) DROP INDEX ([a-z_]+)$`)
|
||||
|
||||
// Migration 012 contains many autocommitting DDL statements. Inspect the actual
|
||||
// schema before each one so a timeout, restart or response loss can resume it.
|
||||
// Its data backfills are deliberately idempotent as well (see the SQL source).
|
||||
func (s *Store) applyControlNodeStatement(ctx context.Context, statement string) error {
|
||||
var query string
|
||||
var args []any
|
||||
if match := controlTable.FindStringSubmatch(statement); match != nil {
|
||||
query = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name=?"
|
||||
args = []any{match[1]}
|
||||
} else if match := controlAdd.FindStringSubmatch(statement); match != nil {
|
||||
switch match[2] {
|
||||
case "COLUMN":
|
||||
query = "SELECT COUNT(*) FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name=? AND column_name=?"
|
||||
case "CONSTRAINT":
|
||||
query = "SELECT COUNT(*) FROM information_schema.table_constraints WHERE constraint_schema=DATABASE() AND table_name=? AND constraint_name=?"
|
||||
case "UNIQUE KEY", "KEY":
|
||||
query = "SELECT COUNT(*) FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name=? AND index_name=?"
|
||||
}
|
||||
args = []any{match[1], match[3]}
|
||||
} else if match := controlDrop.FindStringSubmatch(statement); match != nil {
|
||||
var count int
|
||||
if err := s.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name=? AND index_name=?", match[1], match[2]).Scan(&count); err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
return nil
|
||||
}
|
||||
} else if strings.HasPrefix(statement, "ALTER TABLE runtime_update_notices DROP PRIMARY KEY") {
|
||||
var columns string
|
||||
if err := s.db.QueryRowContext(ctx, "SELECT COALESCE(GROUP_CONCAT(column_name ORDER BY seq_in_index),'') FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name='runtime_update_notices' AND index_name='PRIMARY'").Scan(&columns); err != nil {
|
||||
return err
|
||||
}
|
||||
if columns == "node_id,release_key" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if query != "" {
|
||||
var count int
|
||||
if err := s.db.QueryRowContext(ctx, query, args...).Scan(&count); err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
_, err := s.db.ExecContext(ctx, statement)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user