Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: implement pg backup v2 (#15171)

rebelice31b2ad6dded1
diff --git a/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go
index f96cfb92ab..6b7687981d 100644
--- a/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go
@@ -4,18 +4,25 @@ package pg
import (
"fmt"
+ "log/slog"
"strings"
+ "github.com/antlr4-go/antlr/v4"
"github.com/pkg/errors"
- pgquery "github.com/pganalyze/pg_query_go/v5"
+ parser "github.com/bytebase/postgresql-parser"
+ "github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/advisor"
+ "github.com/bytebase/bytebase/backend/plugin/parser/pg"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
- pgrawparser "github.com/bytebase/bytebase/backend/plugin/parser/sql/engine/pg"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
+const (
+ defaultSchema = "public"
+)
+
var (
_ advisor.Advisor = (*BuiltinPriorBackupCheckAdvisor)(nil)
)
@@ -24,10 +31,6 @@ func init() {
advisor.Register(storepb.Engine_POSTGRES, advisor.PostgreSQLBuiltinPriorBackupCheck, &BuiltinPriorBackupCheckAdvisor{})
}
-const (
- maxMixedDMLCount = 5
-)
-
// BuiltinPriorBackupCheckAdvisor is the advisor checking for disallow mix DDL and DML.
type BuiltinPriorBackupCheckAdvisor struct {
}
@@ -49,11 +52,8 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*
}
title := string(ctx.Rule.Type)
- var needBackup []ast.Node
-
for _, stmt := range stmtList {
- switch stmt.(type) {
- case ast.DDLNode:
+ if _, ok := stmt.(ast.DDLNode); ok {
adviceList = append(adviceList, &storepb.Advice{
Status: level,
Title: title,
@@ -63,8 +63,6 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*
Line: int32(stmt.LastLine()),
},
})
- case *ast.UpdateStmt, *ast.DeleteStmt:
- needBackup = append(needBackup, stmt)
}
}
@@ -81,168 +79,170 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*
})
}
- if len(needBackup) > maxMixedDMLCount && !updateForOneTableWithUnique(ctx.DBSchema, needBackup) {
- adviceList = append(adviceList, &storepb.Advice{
- Status: level,
- Title: title,
- Content: fmt.Sprintf("Prior backup is feasible only with up to %d statements that are either UPDATE or DELETE, or if all UPDATEs target the same table with a PRIMARY or UNIQUE KEY in the WHERE clause", maxMixedDMLCount),
- Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: &storepb.Position{
- Line: 0,
- },
- })
+ statementInfoList, err := prepareTransformation(ctx.Statements)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to prepare transformation")
}
- return adviceList, nil
-}
+ groupByTable := make(map[string][]statementInfo)
+ for _, item := range statementInfoList {
+ key := fmt.Sprintf("%s.%s", item.table.Schema, item.table.Table)
+ groupByTable[key] = append(groupByTable[key], item)
+ }
-func updateForOneTableWithUnique(dbSchema *storepb.DatabaseSchemaMetadata, stmtList []ast.Node) bool {
- var table *ast.TableDef
- for _, stmt := range stmtList {
- update, ok := stmt.(*ast.UpdateStmt)
- if !ok {
- return false
- }
- if table == nil {
- table = update.Table
- } else if !equalTable(table, update.Table) {
- return false
- }
- node := update.GetOriginalNode()
- if !hasUniqueInWhereClause(dbSchema, table, node) {
- return false
+ // Check if the statement type is the same for all statements on the same table.
+ for key, list := range groupByTable {
+ statementType := StatementTypeUnknown
+ for _, item := range list {
+ if statementType == StatementTypeUnknown {
+ statementType = item.table.StatementType
+ }
+ if statementType != item.table.StatementType {
+ adviceList = append(adviceList, &storepb.Advice{
+ Status: level,
+ Title: title,
+ Content: fmt.Sprintf("The statement type is not the same for all statements on the same table %q", key),
+ Code: advisor.BuiltinPriorBackupCheck.Int32(),
+ StartPosition: &storepb.Position{
+ Line: 1,
+ },
+ })
+ break
+ }
}
}
- return true
+ return adviceList, nil
}
-func hasUniqueInWhereClause(dbSchema *storepb.DatabaseSchemaMetadata, table *ast.TableDef, node *pgquery.Node_UpdateStmt) bool {
- list := extractColumnsInEqualCondition(table, node.UpdateStmt.WhereClause)
- columnMap := make(map[string]bool)
- for _, column := range list {
- columnMap[column] = true
- }
+type StatementType int
- if dbSchema == nil {
- return false
- }
+const (
+ StatementTypeUnknown StatementType = iota
+ StatementTypeUpdate
+ StatementTypeInsert
+ StatementTypeDelete
+)
- for _, schema := range dbSchema.Schemas {
- if schema.Name == table.Schema || (schema.Name == "public" && table.Schema == "") {
- for _, t := range schema.Tables {
- if t.Name == table.Name {
- for _, index := range t.Indexes {
- if index.Unique || index.Primary {
- exists := true
- for _, column := range index.Expressions {
- if !columnMap[column] {
- exists = false
- break
- }
- }
- if exists {
- return true
- }
- }
- }
- }
- }
- }
- }
+type TableReference struct {
+ Database string
+ Schema string
+ Table string
+ Alias string
+ StatementType StatementType
+}
- return false
+type statementInfo struct {
+ offset int
+ statement string
+ tree antlr.ParserRuleContext
+ table *TableReference
}
-func extractColumnsInEqualCondition(table *ast.TableDef, node *pgquery.Node) []string {
- if node == nil {
- return nil
+func prepareTransformation(statement string) ([]statementInfo, error) {
+ tree, err := pg.ParsePostgreSQL(statement)
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to parse statement")
}
- switch n := node.Node.(type) {
- case *pgquery.Node_BoolExpr:
- if n.BoolExpr.Boolop != pgquery.BoolExprType_AND_EXPR {
- return nil
- }
- var result []string
- for _, arg := range n.BoolExpr.Args {
- result = append(result, extractColumnsInEqualCondition(table, arg)...)
- }
- return result
- case *pgquery.Node_AExpr:
- if len(n.AExpr.Name) != 1 {
- return nil
- }
- op, ok := n.AExpr.Name[0].Node.(*pgquery.Node_String_)
- if !ok {
- return nil
- }
- if op.String_.Sval != "=" {
- return nil
- }
- if isConst(n.AExpr.Lexpr) {
- column, err := extractColumn(table, n.AExpr.Rexpr)
- if err == nil && column != "" {
- return []string{column}
- }
- } else if isConst(n.AExpr.Rexpr) {
- column, err := extractColumn(table, n.AExpr.Lexpr)
- if err == nil && column != "" {
- return []string{column}
- }
- }
- }
- return nil
+ extractor := &dmlExtractor{}
+ antlr.ParseTreeWalkerDefault.Walk(extractor, tree.Tree)
+ return extractor.dmls, nil
}
-func isConst(node *pgquery.Node) bool {
- switch node.Node.(type) {
- case *pgquery.Node_AConst:
+type dmlExtractor struct {
+ *parser.BasePostgreSQLParserListener
+
+ dmls []statementInfo
+ offset int
+}
+
+func isTopLevel(ctx antlr.Tree) bool {
+ if ctx == nil {
return true
+ }
+
+ switch ctx := ctx.(type) {
+ case *parser.RootContext, *parser.StmtblockContext:
+ return true
+ case *parser.StmtmultiContext, *parser.StmtContext:
+ return isTopLevel(ctx.GetParent())
default:
return false
}
}
-func extractColumn(table *ast.TableDef, node *pgquery.Node) (string, error) {
- switch n := node.Node.(type) {
- case *pgquery.Node_ColumnRef:
- columnNameDef, err := pgrawparser.ConvertNodeListToColumnNameDef(n.ColumnRef.Fields)
- if err != nil {
- return "", err
- }
- if columnNameDef.Table != nil {
- if columnNameDef.Table.Schema != "" && columnNameDef.Table.Schema != table.Schema {
- return "", nil
- }
- if columnNameDef.Table.Name != "" && columnNameDef.Table.Name != table.Name {
- return "", nil
- }
+func (e *dmlExtractor) ExitStmt(ctx *parser.StmtContext) {
+ if isTopLevel(ctx) {
+ e.offset++
+ }
+}
+
+func (e *dmlExtractor) EnterUpdatestmt(ctx *parser.UpdatestmtContext) {
+ if isTopLevel(ctx.GetParent()) {
+ table := extractTableReference(ctx.Relation_expr_opt_alias())
+ if table == nil {
+ return
}
- return columnNameDef.ColumnName, nil
- default:
- return "", nil
+ table.StatementType = StatementTypeUpdate
+ e.dmls = append(e.dmls, statementInfo{
+ offset: e.offset,
+ statement: ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx),
+ tree: ctx,
+ table: table,
+ })
}
}
-func equalTable(a, b *ast.TableDef) bool {
- if a == nil || b == nil {
- return false
+func (e *dmlExtractor) EnterDeletestmt(ctx *parser.DeletestmtContext) {
+ if isTopLevel(ctx.GetParent()) {
+ table := extractTableReference(ctx.Relation_expr_opt_alias())
+ if table == nil {
+ return
+ }
+ table.StatementType = StatementTypeDelete
+ e.dmls = append(e.dmls, statementInfo{
+ offset: e.offset,
+ statement: ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx),
+ tree: ctx,
+ table: table,
+ })
}
+}
- if a.Schema == "" && b.Schema != "" && b.Schema != "public" {
- return false
+func extractTableReference(ctx parser.IRelation_expr_opt_aliasContext) *TableReference {
+ if ctx == nil {
+ return nil
}
- if a.Schema != "" && a.Schema != "public" && b.Schema == "" {
- return false
+ table := TableReference{}
+
+ relationExpr := ctx.Relation_expr()
+ if relationExpr == nil {
+ return nil
}
- if a.Schema != b.Schema {
- return false
+ list := pg.NormalizePostgreSQLQualifiedName(relationExpr.Qualified_name())
+ switch len(list) {
+ case 3:
+ table.Database = list[0]
+ table.Schema = list[1]
+ table.Table = list[2]
+ case 2:
+ table.Schema = list[0]
+ table.Table = list[1]
+ case 1:
+ table.Schema = defaultSchema
+ table.Table = list[0]
+ default:
+ slog.Debug("Invalid table name", log.BBError(errors.Errorf("Invalid table name: %v", list)))
+ return nil
}
- return a.Name == b.Name
+ if ctx.Colid() != nil {
+ table.Alias = pg.NormalizePostgreSQLColid(ctx.Colid())
+ }
+ return &table
}
func extractDatabaseName(databaseUID string) string {
diff --git a/backend/plugin/advisor/pg/test/builtin_prior_backup_check.yaml b/backend/plugin/advisor/pg/test/builtin_prior_backup_check.yaml
index ca1ed63e69..0ece15a37d 100644
--- a/backend/plugin/advisor/pg/test/builtin_prior_backup_check.yaml
+++ b/backend/plugin/advisor/pg/test/builtin_prior_backup_check.yaml
@@ -6,16 +6,6 @@
UPDATE tech_book SET id = 4 WHERE id = 4 and name = 'test';
UPDATE abc SET id = 4 WHERE id = 4 and name = 'test';
changeType: 2
- want:
- - status: 2
- code: 2001
- title: builtin.prior-backup-check
- content: Prior backup is feasible only with up to 5 statements that are either UPDATE or DELETE, or if all UPDATEs target the same table with a PRIMARY or UNIQUE KEY in the WHERE clause
- detail: ""
- startposition:
- line: 0
- column: 0
- endposition: null
- statement: |-
UPDATE tech_book SET id = 1 WHERE id = 1 and name = 'test';
UPDATE tech_book SET id = 2 WHERE id = 2 and name = 'test';
@@ -34,16 +24,6 @@
UPDATE tech_book SET id = 6 WHERE id = 6;
UPDATE tech_book SET id = 7 WHERE id = 7;
changeType: 2
- want:
- - status: 2
- code: 2001
- title: builtin.prior-backup-check
- content: Prior backup is feasible only with up to 5 statements that are either UPDATE or DELETE, or if all UPDATEs target the same table with a PRIMARY or UNIQUE KEY in the WHERE clause
- detail: ""
- startposition:
- line: 0
- column: 0
- endposition: null
- statement: DELETE FROM tech_book WHERE a > 1;
changeType: 2
- statement: UPDATE tech_book SET id = 1;
@@ -55,7 +35,6 @@
code: 2001
title: builtin.prior-backup-check
content: Data change can only run DML, "CREATE TABLE t_test_backup(a int);" is not DML
- detail: ""
startposition:
line: 1
column: 0
diff --git a/backend/plugin/parser/pg/backup.go b/backend/plugin/parser/pg/backup.go
index 184123f6ac..7a40a4a5c9 100644
--- a/backend/plugin/parser/pg/backup.go
+++ b/backend/plugin/parser/pg/backup.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
+ "sort"
"strings"
"github.com/antlr4-go/antlr/v4"
@@ -18,15 +19,25 @@ import (
)
const (
+ defaultSchema = "public"
maxTableNameLength = 63
- maxMixedDMLCount = 5
+)
+
+type StatementType int
+
+const (
+ StatementTypeUnknown StatementType = iota
+ StatementTypeUpdate
+ StatementTypeInsert
+ StatementTypeDelete
)
type TableReference struct {
- Database string
- Schema string
- Table string
- Alias string
+ Database string
+ Schema string
+ Table string
+ Alias string
+ StatementType StatementType
}
func (t *TableReference) String() string {
@@ -62,22 +73,51 @@ func TransformDMLToSelect(_ context.Context, _ base.TransformContext, statement
}
func generateSQL(statementInfoList []statementInfo, targetSchema string, tablePrefix string) ([]base.BackupStatement, error) {
- if len(statementInfoList) <= maxMixedDMLCount {
- return generateSQLMixedDML(statementInfoList, targetSchema, tablePrefix)
+ groupByTable := make(map[string][]statementInfo)
+ for _, item := range statementInfoList {
+ key := fmt.Sprintf("%s.%s", item.table.Schema, item.table.Table)
+ groupByTable[key] = append(groupByTable[key], item)
}
- return generateSQLInOneTable(statementInfoList, targetSchema, tablePrefix)
-}
-func generateSQLInOneTable(statementInfoList []statementInfo, targetSchema string, tablePrefix string) ([]base.BackupStatement, error) {
- table := statementInfoList[0].table
+ // Check if the statement type is the same for all statements on the same table.
+ for key, list := range groupByTable {
+ statementType := StatementTypeUnknown
+ for _, item := range list {
+ if statementType == StatementTypeUnknown {
+ statementType = item.table.StatementType
+ }
+ if statementType != item.table.StatementType {
+ return nil, errors.Errorf("The statement type is not the same for all statements on the same table %q", key)
+ }
+ }
+ }
- for _, item := range statementInfoList {
- if !equalTable(item.table, table) {
- return nil, errors.Errorf("prior backup cannot handle statements on different tables more than %d", maxMixedDMLCount)
+ var result []base.BackupStatement
+ for key, list := range groupByTable {
+ backupStatement, err := generateSQLForTable(list, targetSchema, tablePrefix)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to generate SQL for table %q", key)
}
+ result = append(result, *backupStatement)
}
- targetTable := fmt.Sprintf("%s_%s", tablePrefix, table.Table)
+ sort.Slice(result, func(i, j int) bool {
+ if result[i].StartPosition.Line != result[j].StartPosition.Line {
+ return result[i].StartPosition.Line < result[j].StartPosition.Line
+ }
+ if result[i].StartPosition.Column != result[j].StartPosition.Column {
+ return result[i].StartPosition.Column < result[j].StartPosition.Column
+ }
+ return result[i].SourceTableName < result[j].SourceTableName
+ })
+
+ return result, nil
+}
+
+func generateSQLForTable(statementInfoList []statementInfo, targetSchema string, tablePrefix string) (*base.BackupStatement, error) {
+ table := statementInfoList[0].table
+
+ targetTable := fmt.Sprintf("%s_%s_%s", tablePrefix, table.Table, table.Schema)
targetTable, _ = common.TruncateString(targetTable, maxTableNameLength)
var buf strings.Builder
if _, err := fmt.Fprintf(&buf, `CREATE TABLE "%s"."%s" AS`+"\n", targetSchema, targetTable); err != nil {
@@ -86,7 +126,7 @@ func generateSQLInOneTable(statementInfoList []statementInfo, targetSchema strin
for i, item := range statementInfoList {
if i != 0 {
- if _, err := buf.WriteString("\n UNION ALL\n"); err != nil {
+ if _, err := buf.WriteString("\n UNION\n"); err != nil {
return nil, errors.Wrap(err, "failed to write to buffer")
}
}
@@ -109,90 +149,22 @@ func generateSQLInOneTable(statementInfoList []statementInfo, targetSchema strin
return nil, errors.Wrap(err, "failed to write to buffer")
}
- return []base.BackupStatement{
- {
- Statement: buf.String(),
- SourceSchema: table.Schema,
- SourceTableName: table.Table,
- TargetTableName: targetTable,
- StartPosition: &storebp.Position{
- Line: int32(statementInfoList[0].tree.GetStart().GetLine()),
- Column: int32(statementInfoList[0].tree.GetStart().GetColumn()),
- },
- EndPosition: &storebp.Position{
- Line: int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetLine()),
- Column: int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetColumn()),
- },
+ return &base.BackupStatement{
+ Statement: buf.String(),
+ SourceSchema: table.Schema,
+ SourceTableName: table.Table,
+ TargetTableName: targetTable,
+ StartPosition: &storebp.Position{
+ Line: int32(statementInfoList[0].tree.GetStart().GetLine()),
+ Column: int32(statementInfoList[0].tree.GetStart().GetColumn()),
+ },
+ EndPosition: &storebp.Position{
+ Line: int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetLine()),
+ Column: int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetColumn()),
},
}, nil
}
-func equalTable(a, b *TableReference) bool {
- if a == nil || b == nil {
- return false
- }
-
- if a.Database != "" && b.Database != "" && a.Database != b.Database {
- return false
- }
- if a.Schema != "" && b.Schema != "" && a.Schema != b.Schema {
- return false
- }
- return a.Table == b.Table
-}
-
-func generateSQLMixedDML(statementInfoList []statementInfo, targetSchema string, tablePrefix string) ([]base.BackupStatement, error) {
- var result []base.BackupStatement
- offsetLength := 1
- if len(statementInfoList) > 1 {
- offsetLength = base.GetOffsetLength(statementInfoList[len(statementInfoList)-1].offset)
- }
-
- for _, info := range statementInfoList {
- table := info.table
- targetTable := fmt.Sprintf("%s_%0*d_%s", tablePrefix, offsetLength, info.offset, table.Table)
- targetTable, _ = common.TruncateString(targetTable, maxTableNameLength)
- var buf strings.Builder
- if _, err := fmt.Fprintf(&buf, `CREATE TABLE "%s"."%s" AS SELECT `, targetSchema, targetTable); err != nil {
- return nil, errors.Wrap(err, "failed to write to buffer")
- }
- if table.Alias != "" {
- if _, err := fmt.Fprintf(&buf, `"%s".* `, table.Alias); err != nil {
- return nil, errors.Wrap(err, "failed to write to buffer")
- }
- } else {
- if _, err := fmt.Fprintf(&buf, `%s.* `, table.String()); err != nil {
- return nil, errors.Wrap(err, "failed to write to buffer")
- }
- }
-
- if err := writeSuffixSelectClause(&buf, info.tree); err != nil {
- return nil, errors.Wrap(err, "failed to write suffix select clause")
- }
-
- if _, err := buf.WriteString(";"); err != nil {
- return nil, errors.Wrap(err, "failed to write to buffer")
- }
-
- result = append(result, base.BackupStatement{
- Statement: buf.String(),
- SourceSchema: table.Schema,
- SourceTableName: table.Table,
- TargetTableName: targetTable,
- StartPosition: &storebp.Position{
- Line: int32(info.tree.GetStart().GetLine()),
- Column: int32(info.tree.GetStart().GetColumn()),
- },
- EndPosition: &storebp.Position{
- Line: int32(info.tree.GetStop().GetLine()),
- Column: int32(info.tree.GetStop().GetColumn()),
- },
- })
- }
-
- return result, nil
-}
-
func writeSuffixSelectClause(buf *strings.Builder, tree antlr.Tree) error {
extractor := &suffixSelectClauseExtractor{
buf: buf,
@@ -297,7 +269,7 @@ func (e *dmlExtractor) EnterUpdatestmt(ctx *parser.UpdatestmtContext) {
if table == nil {
return
}
-
+ table.StatementType = StatementTypeUpdate
e.dmls = append(e.dmls, statementInfo{
offset: e.offset,
statement: ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx),
@@ -313,7 +285,7 @@ func (e *dmlExtractor) EnterDeletestmt(ctx *parser.DeletestmtContext) {
if table == nil {
return
}
-
+ table.StatementType = StatementTypeDelete
e.dmls = append(e.dmls, statementInfo{
offset: e.offset,
statement: ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx),
@@ -345,6 +317,7 @@ func extractTableReference(ctx parser.IRelation_expr_opt_aliasContext) *TableRef
table.Schema = list[0]
table.Table = list[1]
case 1:
+ table.Schema = defaultSchema
table.Table = list[0]
default:
slog.Debug("Invalid table name", log.BBError(errors.Errorf("Invalid table name: %v", list)))
diff --git a/backend/plugin/parser/pg/test-data/test_backup.yaml b/backend/plugin/parser/pg/test-data/test_backup.yaml
index 31810a03c1..27921b71fc 100644
--- a/backend/plugin/parser/pg/test-data/test_backup.yaml
+++ b/backend/plugin/parser/pg/test-data/test_backup.yaml
@@ -8,23 +8,23 @@
UPDATE test SET test.c1 = 7 WHERE test.b1 = 7;
result:
- statement: |-
- CREATE TABLE "backupSchema"."rollback_test" AS
- SELECT "test".* FROM test WHERE test.b1 = 1
- UNION ALL
- SELECT "test".* FROM test WHERE test.b1 = 2
- UNION ALL
- SELECT "test".* FROM test WHERE test.b1 = 3
- UNION ALL
- SELECT "test".* FROM test WHERE test.b1 = 4
- UNION ALL
- SELECT "test".* FROM test WHERE test.b1 = 5
- UNION ALL
- SELECT "test".* FROM test WHERE test.b1 = 6
- UNION ALL
- SELECT "test".* FROM test WHERE test.b1 = 7;
- sourceschema: ""
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test WHERE test.b1 = 1
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.b1 = 2
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.b1 = 3
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.b1 = 4
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.b1 = 5
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.b1 = 6
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.b1 = 7;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_test
+ targettablename: rollback_test_public
startposition:
line: 1
column: 0
@@ -36,10 +36,12 @@
USING test
WHERE t.c1 = 1 and t.a1 = test.a1;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_t" AS SELECT "t".* FROM t, test WHERE t.c1 = 1 and t.a1 = test.a1;
- sourceschema: ""
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_t_public" AS
+ SELECT "public"."t".* FROM t, test WHERE t.c1 = 1 and t.a1 = test.a1;
+ sourceschema: public
sourcetablename: t
- targettablename: rollback_0_t
+ targettablename: rollback_t_public
startposition:
line: 1
column: 0
@@ -51,10 +53,12 @@
USING test2
WHERE test.c1 = 1 and test.c1 = test2.c1;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_test" AS SELECT "test".* FROM test, test2 WHERE test.c1 = 1 and test.c1 = test2.c1;
- sourceschema: ""
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test, test2 WHERE test.c1 = 1 and test.c1 = test2.c1;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_0_test
+ targettablename: rollback_test_public
startposition:
line: 1
column: 0
@@ -67,10 +71,12 @@
FROM test2
WHERE test.c1 = 1 and test.c1 = test2.c1;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_test" AS SELECT "test".* FROM test, test2 WHERE test.c1 = 1 and test.c1 = test2.c1;
- sourceschema: ""
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test, test2 WHERE test.c1 = 1 and test.c1 = test2.c1;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_0_test
+ targettablename: rollback_test_public
startposition:
line: 1
column: 0
@@ -78,23 +84,27 @@
line: 4
column: 38
- input: |-
- DELETE FROM test WHERE c1 = 1;
+ DELETE FROM test1 WHERE c1 = 1;
UPDATE test SET test.c1 = 2 WHERE test.c1 = 1;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_test" AS SELECT "test".* FROM test WHERE c1 = 1;
- sourceschema: ""
- sourcetablename: test
- targettablename: rollback_0_test
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test1_public" AS
+ SELECT "public"."test1".* FROM test1 WHERE c1 = 1;
+ sourceschema: public
+ sourcetablename: test1
+ targettablename: rollback_test1_public
startposition:
line: 1
column: 0
endposition:
line: 1
- column: 28
- - statement: CREATE TABLE "backupSchema"."rollback_1_test" AS SELECT "test".* FROM test WHERE test.c1 = 1;
- sourceschema: ""
+ column: 29
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test WHERE test.c1 = 1;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_1_test
+ targettablename: rollback_test_public
startposition:
line: 2
column: 0
@@ -103,10 +113,12 @@
column: 44
- input: DELETE FROM test WHERE c1 = 1;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_test" AS SELECT "test".* FROM test WHERE c1 = 1;
- sourceschema: ""
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test WHERE c1 = 1;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_0_test
+ targettablename: rollback_test_public
startposition:
line: 1
column: 0
@@ -115,10 +127,12 @@
column: 28
- input: UPDATE test SET c1 = 1 WHERE c1=2;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_test" AS SELECT "test".* FROM test WHERE c1=2;
- sourceschema: ""
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test WHERE c1=2;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_0_test
+ targettablename: rollback_test_public
startposition:
line: 1
column: 0
@@ -129,23 +143,17 @@
UPDATE test SET test.c1 = 2 WHERE test.c1 = 1 ;
UPDATE test SET test.c1 = 3 WHERE test.c1 = 5 ;
result:
- - statement: CREATE TABLE "backupSchema"."rollback_0_test" AS SELECT "test".* FROM test WHERE test.c1 = 1;
- sourceschema: ""
+ - statement: |-
+ CREATE TABLE "backupSchema"."rollback_test_public" AS
+ SELECT "public"."test".* FROM test WHERE test.c1 = 1
+ UNION
+ SELECT "public"."test".* FROM test WHERE test.c1 = 5;
+ sourceschema: public
sourcetablename: test
- targettablename: rollback_0_test
+ targettablename: rollback_test_public
startposition:
line: 1
column: 0
- endposition:
- line: 1
- column: 44
- - statement: CREATE TABLE "backupSchema"."rollback_1_test" AS SELECT "test".* FROM test WHERE test.c1 = 5;
- sourceschema: ""
- sourcetablename: test
- targettablename: rollback_1_test
- startposition:
- line: 2
- column: 0
endposition:
line: 2
column: 44