Skip to content

Commit

Permalink
Disable testing partitioning and warn that it's not fully implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
williammoran committed May 3, 2024
1 parent bcfa34e commit f86e123
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions example/someapp_v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
</database>
<schema name="public" owner="ROLE_OWNER">
<table name="sql_user" owner="ROLE_OWNER" primaryKey="user_id" slonyId="10" description="user table comment">
<!--
<tablePartition type="MODULO">
<tablePartitionOption name="number" value="4" />
<tablePartitionOption name="column" value="user_id" />
<tablePartitionOption name="firstSlonyId" value="347" />
<tablePartitionOption name="lastSlonyId" value="350" />
</tablePartition>
-->
<column name="user_id" type="bigserial" slonyId="10" />
<column name="user_name" type="character varying(40)" />
<column name="password" type="text" />
Expand Down
2 changes: 2 additions & 0 deletions example/someapp_v2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
</database>
<schema name="public" owner="ROLE_OWNER">
<table name="sql_user" owner="ROLE_OWNER" primaryKey="user_id" slonyId="10">
<!--
<tablePartition type="MODULO">
<tablePartitionOption name="number" value="4" />
<tablePartitionOption name="column" value="user_id" />
<tablePartitionOption name="firstSlonyId" value="347" />
<tablePartitionOption name="lastSlonyId" value="350" />
</tablePartition>
-->
<column name="user_id" type="bigserial" slonyId="10" />
<column name="user_name" type="character varying(40)" />
<column name="password" type="text" />
Expand Down
25 changes: 18 additions & 7 deletions lib/format/pgsql8/xml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pgsql8

import (
"fmt"
"log/slog"
"strconv"

"github.com/dbsteward/dbsteward/lib"
Expand All @@ -11,6 +12,7 @@ import (
)

type XmlParser struct {
logger *slog.Logger
}

type slonyRange struct {
Expand All @@ -35,7 +37,7 @@ func tryNewSlonyRange(firstStr, lastStr string, parts int) (*slonyRange, error)
lib.GlobalDBSteward.FatalIfError(err, "tablePartitionOption 'lastSlonyId' must be a number")
allocated := lastTmp - first + 1
if allocated != parts {
return nil, fmt.Errorf("Requested %d partitions but provided %d slony IDs", parts, allocated)
return nil, fmt.Errorf("requested %d partitions but provided %d slony IDs", parts, allocated)
}
last = lastTmp
}
Expand All @@ -47,30 +49,39 @@ func NewXmlParser() *XmlParser {
return &XmlParser{}
}

func (self *XmlParser) Process(doc *ir.Definition) error {
// @hack until we get proper instantiation ordering (i.e. remove all globals)
func (parser *XmlParser) Logger() *slog.Logger {
if parser.logger == nil {
parser.logger = lib.GlobalDBSteward.Logger()
}
return parser.logger
}

func (parser *XmlParser) Process(doc *ir.Definition) error {
for _, schema := range doc.Schemas {
for _, table := range schema.Tables {
if table.Partitioning != nil {
return self.expandPartitionedTable(doc, schema, table)
parser.Logger().Warn(fmt.Sprintf("Table %s.%s definies partition which is only partially supported at this time", schema.Name, table.Name))
return parser.expandPartitionedTable(doc, schema, table)
}
}
}
return nil
}

func (self *XmlParser) expandPartitionedTable(doc *ir.Definition, schema *ir.Schema, table *ir.Table) error {
func (parser *XmlParser) expandPartitionedTable(doc *ir.Definition, schema *ir.Schema, table *ir.Table) error {
util.Assert(table.Partitioning != nil, "Table.Partitioning must not be nil")
// TODO(feat) hash partitions
// TODO(feat) native partitioning in recent postgres

if table.Partitioning.Type.Equals(ir.TablePartitionTypeModulo) {
return self.expandModuloParitionedTable(doc, schema, table)
return parser.expandModuloParitionedTable(doc, schema, table)
}

return fmt.Errorf("invalid partition type: %s", table.Partitioning.Type)
}

func (self *XmlParser) CheckPartitionChange(oldSchema *ir.Schema, oldTable *ir.Table, newSchema *ir.Schema, newTable *ir.Table) error {
func (parser *XmlParser) CheckPartitionChange(oldSchema *ir.Schema, oldTable *ir.Table, newSchema *ir.Schema, newTable *ir.Table) error {
util.Assert(oldTable.Partitioning != nil, "oldTable.Partitioning must not be nil")
util.Assert(newTable.Partitioning != nil, "newTable.Partitioning must not be nil")

Expand All @@ -83,7 +94,7 @@ func (self *XmlParser) CheckPartitionChange(oldSchema *ir.Schema, oldTable *ir.T
}

if newTable.Partitioning.Type.Equals(ir.TablePartitionTypeModulo) {
return self.checkModuloPartitionChange(oldSchema, oldTable, newSchema, newTable)
return parser.checkModuloPartitionChange(oldSchema, oldTable, newSchema, newTable)
}

return errors.Errorf("Invalid partition type: %s", newTable.Partitioning.Type)
Expand Down

0 comments on commit f86e123

Please sign in to comment.