Skip to content

Commit 584fc18

Browse files
committed
Add Azure CREATE/ALTER DATABASE options support
- Add SERVICE_OBJECTIVE option parsing for Azure databases - Add ElasticPoolSpecification AST type for elastic pool syntax - Parse ELASTIC_POOL(NAME = poolname) syntax - Support options after AS COPY OF clause - Add marshaling for ElasticPoolSpecification - Enable 2 passing tests
1 parent e1a195c commit 584fc18

5 files changed

Lines changed: 80 additions & 2 deletions

File tree

ast/alter_database_set_statement.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ func (l *LiteralDatabaseOption) node() {}
115115
func (l *LiteralDatabaseOption) databaseOption() {}
116116
func (l *LiteralDatabaseOption) createDatabaseOption() {}
117117

118+
// ElasticPoolSpecification represents SERVICE_OBJECTIVE = ELASTIC_POOL(name = poolname)
119+
type ElasticPoolSpecification struct {
120+
ElasticPoolName *Identifier
121+
OptionKind string // "ServiceObjective"
122+
}
123+
124+
func (e *ElasticPoolSpecification) node() {}
125+
func (e *ElasticPoolSpecification) databaseOption() {}
126+
func (e *ElasticPoolSpecification) createDatabaseOption() {}
127+
118128
// AlterDatabaseAddFileStatement represents ALTER DATABASE ... ADD FILE statement
119129
type AlterDatabaseAddFileStatement struct {
120130
DatabaseName *Identifier

parser/marshal.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,17 @@ func databaseOptionToJSON(opt ast.DatabaseOption) jsonNode {
11421142
node["OptionKind"] = o.OptionKind
11431143
}
11441144
return node
1145+
case *ast.ElasticPoolSpecification:
1146+
node := jsonNode{
1147+
"$type": "ElasticPoolSpecification",
1148+
}
1149+
if o.ElasticPoolName != nil {
1150+
node["ElasticPoolName"] = identifierToJSON(o.ElasticPoolName)
1151+
}
1152+
if o.OptionKind != "" {
1153+
node["OptionKind"] = o.OptionKind
1154+
}
1155+
return node
11451156
case *ast.RemoteDataArchiveDatabaseOption:
11461157
node := jsonNode{
11471158
"$type": "RemoteDataArchiveDatabaseOption",
@@ -15035,6 +15046,17 @@ func createDatabaseOptionToJSON(opt ast.CreateDatabaseOption) jsonNode {
1503515046
node["OptionKind"] = o.OptionKind
1503615047
}
1503715048
return node
15049+
case *ast.ElasticPoolSpecification:
15050+
node := jsonNode{
15051+
"$type": "ElasticPoolSpecification",
15052+
}
15053+
if o.ElasticPoolName != nil {
15054+
node["ElasticPoolName"] = identifierToJSON(o.ElasticPoolName)
15055+
}
15056+
if o.OptionKind != "" {
15057+
node["OptionKind"] = o.OptionKind
15058+
}
15059+
return node
1503815060
case *ast.SimpleDatabaseOption:
1503915061
return jsonNode{
1504015062
"$type": "DatabaseOption",

parser/parse_statements.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9139,6 +9139,19 @@ func (p *Parser) parseCreateDatabaseStatement() (ast.Statement, error) {
91399139
}
91409140
multiPart.Count = len(multiPart.Identifiers)
91419141
stmt.CopyOf = multiPart
9142+
9143+
// Check for Azure-style options after COPY OF
9144+
if p.curTok.Type == TokenLParen {
9145+
p.nextToken() // consume (
9146+
opts, err := p.parseAzureDatabaseOptions()
9147+
if err != nil {
9148+
return nil, err
9149+
}
9150+
stmt.Options = append(stmt.Options, opts...)
9151+
if p.curTok.Type == TokenRParen {
9152+
p.nextToken() // consume )
9153+
}
9154+
}
91429155
}
91439156
}
91449157
}
@@ -9369,6 +9382,39 @@ func (p *Parser) parseAzureDatabaseOptions() ([]ast.CreateDatabaseOption, error)
93699382
}
93709383
options = append(options, opt)
93719384

9385+
case "SERVICE_OBJECTIVE":
9386+
// Check for elastic_pool(name = [epool1]) syntax
9387+
if strings.ToUpper(p.curTok.Literal) == "ELASTIC_POOL" {
9388+
p.nextToken() // consume ELASTIC_POOL
9389+
if p.curTok.Type == TokenLParen {
9390+
p.nextToken() // consume (
9391+
// Parse NAME = [poolname]
9392+
if strings.ToUpper(p.curTok.Literal) == "NAME" {
9393+
p.nextToken() // consume NAME
9394+
if p.curTok.Type == TokenEquals {
9395+
p.nextToken() // consume =
9396+
}
9397+
poolName := p.parseIdentifier()
9398+
opt := &ast.ElasticPoolSpecification{
9399+
OptionKind: "ServiceObjective",
9400+
ElasticPoolName: poolName,
9401+
}
9402+
options = append(options, opt)
9403+
}
9404+
if p.curTok.Type == TokenRParen {
9405+
p.nextToken() // consume )
9406+
}
9407+
}
9408+
} else {
9409+
// Parse service objective value (string literal)
9410+
value, _ := p.parseStringLiteral()
9411+
opt := &ast.LiteralDatabaseOption{
9412+
OptionKind: "ServiceObjective",
9413+
Value: value,
9414+
}
9415+
options = append(options, opt)
9416+
}
9417+
93729418
default:
93739419
// Skip unknown option value
93749420
if p.curTok.Type != TokenComma && p.curTok.Type != TokenRParen {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)