github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/alter_database.go (about) 1 // Copyright 2020 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 "fmt" 14 15 // AlterDatabaseOwner represents a ALTER DATABASE OWNER TO statement. 16 type AlterDatabaseOwner struct { 17 Name Name 18 Owner RoleSpec 19 } 20 21 // Format implements the NodeFormatter interface. 22 func (node *AlterDatabaseOwner) Format(ctx *FmtCtx) { 23 ctx.WriteString("ALTER DATABASE ") 24 ctx.FormatNode(&node.Name) 25 ctx.WriteString(" OWNER TO ") 26 ctx.FormatNode(&node.Owner) 27 } 28 29 // AlterDatabaseAddRegion represents a ALTER DATABASE ADD REGION statement. 30 type AlterDatabaseAddRegion struct { 31 Name Name 32 Region Name 33 IfNotExists bool 34 } 35 36 var _ Statement = &AlterDatabaseAddRegion{} 37 38 // Format implements the NodeFormatter interface. 39 func (node *AlterDatabaseAddRegion) Format(ctx *FmtCtx) { 40 ctx.WriteString("ALTER DATABASE ") 41 ctx.FormatNode(&node.Name) 42 ctx.WriteString(" ADD REGION ") 43 if node.IfNotExists { 44 ctx.WriteString("IF NOT EXISTS ") 45 } 46 ctx.FormatNode(&node.Region) 47 } 48 49 // AlterDatabaseDropRegion represents a ALTER DATABASE DROP REGION statement. 50 type AlterDatabaseDropRegion struct { 51 Name Name 52 Region Name 53 IfExists bool 54 } 55 56 var _ Statement = &AlterDatabaseDropRegion{} 57 58 // Format implements the NodeFormatter interface. 59 func (node *AlterDatabaseDropRegion) Format(ctx *FmtCtx) { 60 ctx.WriteString("ALTER DATABASE ") 61 ctx.FormatNode(&node.Name) 62 ctx.WriteString(" DROP REGION ") 63 if node.IfExists { 64 ctx.WriteString("IF EXISTS ") 65 } 66 ctx.FormatNode(&node.Region) 67 } 68 69 // AlterDatabasePrimaryRegion represents a ALTER DATABASE PRIMARY REGION ... statement. 70 type AlterDatabasePrimaryRegion struct { 71 Name Name 72 PrimaryRegion Name 73 } 74 75 var _ Statement = &AlterDatabasePrimaryRegion{} 76 77 // Format implements the NodeFormatter interface. 78 func (node *AlterDatabasePrimaryRegion) Format(ctx *FmtCtx) { 79 ctx.WriteString("ALTER DATABASE ") 80 ctx.FormatNode(&node.Name) 81 ctx.WriteString(" PRIMARY REGION ") 82 node.PrimaryRegion.Format(ctx) 83 } 84 85 // AlterDatabaseSurvivalGoal represents a ALTER DATABASE SURVIVE ... statement. 86 type AlterDatabaseSurvivalGoal struct { 87 Name Name 88 SurvivalGoal SurvivalGoal 89 } 90 91 var _ Statement = &AlterDatabaseSurvivalGoal{} 92 93 // Format implements the NodeFormatter interface. 94 func (node *AlterDatabaseSurvivalGoal) Format(ctx *FmtCtx) { 95 ctx.WriteString("ALTER DATABASE ") 96 ctx.FormatNode(&node.Name) 97 ctx.WriteString(" ") 98 node.SurvivalGoal.Format(ctx) 99 } 100 101 // AlterDatabasePlacement represents a ALTER DATABASE PLACEMENT statement. 102 type AlterDatabasePlacement struct { 103 Name Name 104 Placement DataPlacement 105 } 106 107 var _ Statement = &AlterDatabasePlacement{} 108 109 // Format implements the NodeFormatter interface. 110 func (node *AlterDatabasePlacement) Format(ctx *FmtCtx) { 111 ctx.WriteString("ALTER DATABASE ") 112 ctx.FormatNode(&node.Name) 113 ctx.WriteString(" ") 114 node.Placement.Format(ctx) 115 } 116 117 // AlterDatabaseAddSuperRegion represents a 118 // ALTER DATABASE ADD SUPER REGION ... statement. 119 type AlterDatabaseAddSuperRegion struct { 120 DatabaseName Name 121 SuperRegionName Name 122 Regions []Name 123 } 124 125 var _ Statement = &AlterDatabaseAddSuperRegion{} 126 127 // Format implements the NodeFormatter interface. 128 func (node *AlterDatabaseAddSuperRegion) Format(ctx *FmtCtx) { 129 ctx.WriteString("ALTER DATABASE ") 130 ctx.FormatNode(&node.DatabaseName) 131 ctx.WriteString(" ADD SUPER REGION ") 132 ctx.FormatNode(&node.SuperRegionName) 133 ctx.WriteString(" VALUES ") 134 for i := range node.Regions { 135 if i != 0 { 136 ctx.WriteString(",") 137 } 138 ctx.FormatNode(&node.Regions[i]) 139 } 140 } 141 142 // AlterDatabaseDropSuperRegion represents a 143 // ALTER DATABASE DROP SUPER REGION ... statement. 144 type AlterDatabaseDropSuperRegion struct { 145 DatabaseName Name 146 SuperRegionName Name 147 } 148 149 var _ Statement = &AlterDatabaseDropSuperRegion{} 150 151 // Format implements the NodeFormatter interface. 152 func (node *AlterDatabaseDropSuperRegion) Format(ctx *FmtCtx) { 153 ctx.WriteString("ALTER DATABASE ") 154 ctx.FormatNode(&node.DatabaseName) 155 ctx.WriteString(" DROP SUPER REGION ") 156 ctx.FormatNode(&node.SuperRegionName) 157 } 158 159 // AlterDatabaseAlterSuperRegion represents a 160 // ALTER DATABASE ADD SUPER REGION ... statement. 161 type AlterDatabaseAlterSuperRegion struct { 162 DatabaseName Name 163 SuperRegionName Name 164 Regions []Name 165 } 166 167 var _ Statement = &AlterDatabaseAlterSuperRegion{} 168 169 // Format implements the NodeFormatter interface. 170 func (node *AlterDatabaseAlterSuperRegion) Format(ctx *FmtCtx) { 171 ctx.WriteString("ALTER DATABASE ") 172 ctx.FormatNode(&node.DatabaseName) 173 ctx.WriteString(" ALTER SUPER REGION ") 174 ctx.FormatNode(&node.SuperRegionName) 175 ctx.WriteString(" VALUES ") 176 for i := range node.Regions { 177 if i != 0 { 178 ctx.WriteString(",") 179 } 180 ctx.FormatNode(&node.Regions[i]) 181 } 182 } 183 184 // AlterDatabaseSecondaryRegion represents a 185 // ALTER DATABASE SET SECONDARY REGION ... statement. 186 type AlterDatabaseSecondaryRegion struct { 187 DatabaseName Name 188 SecondaryRegion Name 189 } 190 191 var _ Statement = &AlterDatabaseSecondaryRegion{} 192 193 // Format implements the NodeFormatter interface. 194 func (node *AlterDatabaseSecondaryRegion) Format(ctx *FmtCtx) { 195 ctx.WriteString("ALTER DATABASE ") 196 ctx.FormatNode(&node.DatabaseName) 197 ctx.WriteString(" SET SECONDARY REGION ") 198 node.SecondaryRegion.Format(ctx) 199 } 200 201 // AlterDatabaseDropSecondaryRegion represents a 202 // ALTER DATABASE DROP SECONDARY REGION statement. 203 type AlterDatabaseDropSecondaryRegion struct { 204 DatabaseName Name 205 IfExists bool 206 } 207 208 var _ Statement = &AlterDatabaseDropSecondaryRegion{} 209 210 // Format implements the NodeFormatter interface. 211 func (node *AlterDatabaseDropSecondaryRegion) Format(ctx *FmtCtx) { 212 ctx.WriteString("ALTER DATABASE ") 213 ctx.FormatNode(&node.DatabaseName) 214 ctx.WriteString(" DROP SECONDARY REGION ") 215 if node.IfExists { 216 ctx.WriteString("IF EXISTS ") 217 } 218 } 219 220 // AlterDatabaseSetZoneConfigExtension represents a 221 // ALTER DATABASE ... ALTER LOCALITY ... CONFIGURE ZONE ... statement. 222 type AlterDatabaseSetZoneConfigExtension struct { 223 // ALTER DATABASE ... 224 DatabaseName Name 225 // ALTER LOCALITY ... 226 LocalityLevel LocalityLevel 227 RegionName Name 228 // CONFIGURE ZONE ... 229 ZoneConfigSettings 230 } 231 232 var _ Statement = &AlterDatabaseSetZoneConfigExtension{} 233 234 // Format implements the NodeFormatter interface. 235 func (node *AlterDatabaseSetZoneConfigExtension) Format(ctx *FmtCtx) { 236 ctx.WriteString("ALTER DATABASE ") 237 ctx.FormatNode(&node.DatabaseName) 238 ctx.WriteString(" ALTER LOCALITY") 239 switch node.LocalityLevel { 240 case LocalityLevelGlobal: 241 ctx.WriteString(" GLOBAL") 242 case LocalityLevelTable: 243 ctx.WriteString(" REGIONAL") 244 if node.RegionName != "" { 245 ctx.WriteString(" IN ") 246 ctx.FormatNode(&node.RegionName) 247 } 248 default: 249 panic(fmt.Sprintf("unexpected locality: %#v", node.LocalityLevel)) 250 } 251 ctx.WriteString(" CONFIGURE ZONE ") 252 node.ZoneConfigSettings.Format(ctx) 253 }