mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-19 19:21:44 -05:00
Got rid of sql dependency in schema package
This commit is contained in:
@@ -17,7 +17,6 @@ package schema
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"gopkg.in/src-d/go-errors.v1"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
|
||||
@@ -49,7 +48,13 @@ type Schema interface {
|
||||
|
||||
// AddColumn adds a column to this schema in the order given and returns the resulting Schema.
|
||||
// The new column cannot be a primary key. To alter primary keys, create a new schema with those keys.
|
||||
AddColumn(column Column, order *sql.ColumnOrder) (Schema, error)
|
||||
AddColumn(column Column, order *ColumnOrder) (Schema, error)
|
||||
}
|
||||
|
||||
// ColumnOrder is used in ALTER TABLE statements to change the order of inserted / modified columns.
|
||||
type ColumnOrder struct {
|
||||
First bool // True if this column should come first
|
||||
AfterColumn string // Set to the name of the column after which this column should appear
|
||||
}
|
||||
|
||||
// ColFromTag returns a schema.Column from a schema and a tag
|
||||
|
||||
@@ -20,8 +20,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -287,7 +285,7 @@ func (si *schemaImpl) Checks() CheckCollection {
|
||||
return si.checkCollection
|
||||
}
|
||||
|
||||
func (si schemaImpl) AddColumn(newCol Column, order *sql.ColumnOrder) (Schema, error) {
|
||||
func (si schemaImpl) AddColumn(newCol Column, order *ColumnOrder) (Schema, error) {
|
||||
if newCol.IsPartOfPK {
|
||||
return nil, fmt.Errorf("cannot add a column with that is a primary key: %s", newCol.Name)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func addColumnToTable(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newSchema, err := oldSchema.AddColumn(newCol, order)
|
||||
newSchema, err := oldSchema.AddColumn(newCol, orderToOrder(order))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -99,6 +99,16 @@ func addColumnToTable(
|
||||
return newTable.AddColumnToRows(ctx, newColName, newSchema)
|
||||
}
|
||||
|
||||
func orderToOrder(order *sql.ColumnOrder) *schema.ColumnOrder {
|
||||
if order == nil {
|
||||
return nil
|
||||
}
|
||||
return &schema.ColumnOrder{
|
||||
First: order.First,
|
||||
AfterColumn: order.AfterColumn,
|
||||
}
|
||||
}
|
||||
|
||||
func createColumn(nullable Nullable, newColName string, tag uint64, typeInfo typeinfo.TypeInfo, defaultVal, comment string) (schema.Column, error) {
|
||||
if nullable {
|
||||
return schema.NewColumnWithTypeInfo(newColName, tag, typeInfo, false, defaultVal, false, comment)
|
||||
|
||||
Reference in New Issue
Block a user