1515package plan
1616
1717import (
18+ "strings"
19+
1820 "github.com/dolthub/go-mysql-server/sql"
1921 "github.com/dolthub/go-mysql-server/sql/binlogreplication"
2022 "github.com/dolthub/go-mysql-server/sql/types"
@@ -26,16 +28,28 @@ import (
2628// https://dev.mysql.com/doc/refman/8.0/en/show-replica-status.html
2729type ShowReplicaStatus struct {
2830 ReplicaController binlogreplication.BinlogReplicaController
31+ // useDeprecatedColumnNames is used to determine if the column names returned should be the old
32+ // and deprecated master/slave column names, or the new source/replica column names.
33+ useDeprecatedColumnNames bool
2934}
3035
3136var _ sql.Node = (* ShowReplicaStatus )(nil )
3237var _ sql.CollationCoercible = (* ShowReplicaStatus )(nil )
3338var _ BinlogReplicaControllerCommand = (* ShowReplicaStatus )(nil )
3439
40+ // NewShowReplicaStatus creates a new ShowReplicaStatus node.
3541func NewShowReplicaStatus () * ShowReplicaStatus {
3642 return & ShowReplicaStatus {}
3743}
3844
45+ // NewShowSlaveStatus creates a new ShowReplicaStatus node configured to use the old, deprecated
46+ // column names (i.e. master/slave) instead of the new, renamed columns (i.e. source/replica).
47+ func NewShowSlaveStatus () * ShowReplicaStatus {
48+ return & ShowReplicaStatus {
49+ useDeprecatedColumnNames : true ,
50+ }
51+ }
52+
3953// WithBinlogReplicaController implements the BinlogReplicaControllerCommand interface.
4054func (s * ShowReplicaStatus ) WithBinlogReplicaController (controller binlogreplication.BinlogReplicaController ) sql.Node {
4155 nc := * s
@@ -48,11 +62,15 @@ func (s *ShowReplicaStatus) Resolved() bool {
4862}
4963
5064func (s * ShowReplicaStatus ) String () string {
51- return "SHOW REPLICA STATUS"
65+ if s .useDeprecatedColumnNames {
66+ return "SHOW SLAVE STATUS"
67+ } else {
68+ return "SHOW REPLICA STATUS"
69+ }
5270}
5371
5472func (s * ShowReplicaStatus ) Schema () sql.Schema {
55- return sql.Schema {
73+ sch := sql.Schema {
5674 {Name : "Replica_IO_State" , Type : types .MustCreateStringWithDefaults (sqltypes .VarChar , 64 ), Default : nil , Nullable : false },
5775 {Name : "Source_Host" , Type : types .MustCreateStringWithDefaults (sqltypes .VarChar , 255 ), Default : nil , Nullable : false },
5876 {Name : "Source_User" , Type : types .MustCreateStringWithDefaults (sqltypes .VarChar , 64 ), Default : nil , Nullable : false },
@@ -109,6 +127,15 @@ func (s *ShowReplicaStatus) Schema() sql.Schema {
109127 {Name : "Auto_Position" , Type : types .MustCreateStringWithDefaults (sqltypes .VarChar , 64 ), Default : nil , Nullable : false },
110128 {Name : "Replicate_Rewrite_DB" , Type : types .MustCreateStringWithDefaults (sqltypes .VarChar , 64 ), Default : nil , Nullable : false },
111129 }
130+
131+ if s .useDeprecatedColumnNames {
132+ for i := range sch {
133+ sch [i ].Name = strings .ReplaceAll (sch [i ].Name , "Source" , "Master" )
134+ sch [i ].Name = strings .ReplaceAll (sch [i ].Name , "Replica" , "Slave" )
135+ }
136+ }
137+
138+ return sch
112139}
113140
114141func (s * ShowReplicaStatus ) Children () []sql.Node {
0 commit comments