github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/alter_backup_schedule.go (about)

     1  // Copyright 2022 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package tree
    12  
    13  import "strconv"
    14  
    15  // AlterBackupSchedule represents an ALTER BACKUP SCHEDULE statement.
    16  type AlterBackupSchedule struct {
    17  	ScheduleID uint64
    18  	Cmds       AlterBackupScheduleCmds
    19  }
    20  
    21  var _ Statement = &AlterBackupSchedule{}
    22  
    23  // Format implements the NodeFormatter interface.
    24  func (node *AlterBackupSchedule) Format(ctx *FmtCtx) {
    25  	ctx.WriteString(`ALTER BACKUP SCHEDULE `)
    26  	if ctx.HasFlags(FmtHideConstants) || ctx.HasFlags(FmtAnonymize) {
    27  		ctx.WriteString("123")
    28  	} else {
    29  		ctx.WriteString(strconv.FormatUint(node.ScheduleID, 10))
    30  	}
    31  	ctx.WriteByte(' ')
    32  	ctx.FormatNode(&node.Cmds)
    33  }
    34  
    35  // AlterBackupScheduleCmds represents a list of changefeed alterations
    36  type AlterBackupScheduleCmds []AlterBackupScheduleCmd
    37  
    38  // Format implements the NodeFormatter interface.
    39  func (node *AlterBackupScheduleCmds) Format(ctx *FmtCtx) {
    40  	for i, n := range *node {
    41  		if i > 0 {
    42  			ctx.WriteString(", ")
    43  		}
    44  		ctx.FormatNode(n)
    45  	}
    46  }
    47  
    48  // AlterBackupScheduleCmd represents a changefeed modification operation.
    49  type AlterBackupScheduleCmd interface {
    50  	NodeFormatter
    51  	// Placeholder function to ensure that only desired types
    52  	// (AlterBackupSchedule*) conform to the AlterBackupScheduleCmd interface.
    53  	alterBackupScheduleCmd()
    54  }
    55  
    56  func (*AlterBackupScheduleSetLabel) alterBackupScheduleCmd()          {}
    57  func (*AlterBackupScheduleSetInto) alterBackupScheduleCmd()           {}
    58  func (*AlterBackupScheduleSetWith) alterBackupScheduleCmd()           {}
    59  func (*AlterBackupScheduleSetRecurring) alterBackupScheduleCmd()      {}
    60  func (*AlterBackupScheduleSetFullBackup) alterBackupScheduleCmd()     {}
    61  func (*AlterBackupScheduleSetScheduleOption) alterBackupScheduleCmd() {}
    62  
    63  var _ AlterBackupScheduleCmd = &AlterBackupScheduleSetLabel{}
    64  var _ AlterBackupScheduleCmd = &AlterBackupScheduleSetInto{}
    65  var _ AlterBackupScheduleCmd = &AlterBackupScheduleSetWith{}
    66  var _ AlterBackupScheduleCmd = &AlterBackupScheduleSetRecurring{}
    67  var _ AlterBackupScheduleCmd = &AlterBackupScheduleSetFullBackup{}
    68  var _ AlterBackupScheduleCmd = &AlterBackupScheduleSetScheduleOption{}
    69  
    70  // AlterBackupScheduleSetLabel represents an ADD <label> command
    71  type AlterBackupScheduleSetLabel struct {
    72  	Label Expr
    73  }
    74  
    75  // Format implements the NodeFormatter interface.
    76  func (node *AlterBackupScheduleSetLabel) Format(ctx *FmtCtx) {
    77  	ctx.WriteString("SET LABEL ")
    78  	ctx.FormatNode(node.Label)
    79  }
    80  
    81  // AlterBackupScheduleSetInto represents a SET <destinations> command
    82  type AlterBackupScheduleSetInto struct {
    83  	Into StringOrPlaceholderOptList
    84  }
    85  
    86  // Format implements the NodeFormatter interface.
    87  func (node *AlterBackupScheduleSetInto) Format(ctx *FmtCtx) {
    88  	ctx.WriteString("SET INTO ")
    89  	ctx.FormatNode(&node.Into)
    90  }
    91  
    92  // AlterBackupScheduleSetWith represents an SET <options> command
    93  type AlterBackupScheduleSetWith struct {
    94  	With *BackupOptions
    95  }
    96  
    97  // Format implements the NodeFormatter interface.
    98  func (node *AlterBackupScheduleSetWith) Format(ctx *FmtCtx) {
    99  	ctx.WriteString("SET WITH ")
   100  	ctx.FormatNode(node.With)
   101  }
   102  
   103  // AlterBackupScheduleSetRecurring represents an SET RECURRING <recurrence> command
   104  type AlterBackupScheduleSetRecurring struct {
   105  	Recurrence Expr
   106  }
   107  
   108  // Format implements the NodeFormatter interface.
   109  func (node *AlterBackupScheduleSetRecurring) Format(ctx *FmtCtx) {
   110  	ctx.WriteString("SET RECURRING ")
   111  	if node.Recurrence == nil {
   112  		ctx.WriteString("NEVER")
   113  	} else {
   114  		ctx.FormatNode(node.Recurrence)
   115  	}
   116  }
   117  
   118  // AlterBackupScheduleSetFullBackup represents an SET FULL BACKUP <recurrence> command
   119  type AlterBackupScheduleSetFullBackup struct {
   120  	FullBackup FullBackupClause
   121  }
   122  
   123  // Format implements the NodeFormatter interface.
   124  func (node *AlterBackupScheduleSetFullBackup) Format(ctx *FmtCtx) {
   125  	ctx.WriteString("SET FULL BACKUP ")
   126  	if node.FullBackup.AlwaysFull {
   127  		ctx.WriteString("ALWAYS")
   128  	} else {
   129  		ctx.FormatNode(node.FullBackup.Recurrence)
   130  	}
   131  }
   132  
   133  // AlterBackupScheduleSetScheduleOption represents an SET SCHEDULE OPTION <kv_options> command
   134  type AlterBackupScheduleSetScheduleOption struct {
   135  	Option KVOption
   136  }
   137  
   138  // Format implements the NodeFormatter interface.
   139  func (node *AlterBackupScheduleSetScheduleOption) Format(ctx *FmtCtx) {
   140  	ctx.WriteString("SET SCHEDULE OPTION ")
   141  
   142  	// KVOption Key values never contain PII and should be distinguished
   143  	// for feature tracking purposes.
   144  	o := node.Option
   145  	ctx.WithFlags(ctx.flags&^FmtMarkRedactionNode, func() {
   146  		ctx.FormatNode(&o.Key)
   147  	})
   148  	if o.Value != nil {
   149  		ctx.WriteString(` = `)
   150  		ctx.FormatNode(o.Value)
   151  	}
   152  }