Skip to content

Commit 63f78df

Browse files
committed
Merge branch 'main' into zachmu/sql-driver-tests
2 parents 7f634e7 + 5bf6ad6 commit 63f78df

182 files changed

Lines changed: 3466 additions & 1005 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/sequences/collection.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ const (
5050

5151
// Sequence represents a single sequence within the pg_sequence table.
5252
type Sequence struct {
53-
Id id.Sequence
54-
DataTypeID id.Type
55-
Persistence Persistence
56-
Start int64
57-
Current int64
58-
Increment int64
59-
Minimum int64
60-
Maximum int64
61-
Cache int64
62-
Cycle bool
63-
IsAtEnd bool
64-
OwnerTable id.Table
65-
OwnerColumn string
53+
Id id.Sequence
54+
DataTypeID id.Type
55+
Persistence Persistence
56+
Start int64
57+
Current int64
58+
Increment int64
59+
Minimum int64
60+
Maximum int64
61+
Cache int64
62+
Cycle bool
63+
IsAtEnd bool
64+
HasBeenCalled bool
65+
OwnerTable id.Table
66+
OwnerColumn string
6667
}
6768

6869
var _ objinterface.Collection = (*Collection)(nil)
@@ -297,6 +298,7 @@ func (pgs *Collection) SetVal(ctx context.Context, name id.Sequence, newValue in
297298
}
298299
seq.Current = newValue
299300
seq.IsAtEnd = false
301+
seq.HasBeenCalled = false
300302
if autoAdvance {
301303
_, err := seq.nextValForSequence()
302304
return err
@@ -450,6 +452,7 @@ func (sequence *Sequence) nextValForSequence() (int64, error) {
450452
}
451453
}
452454
// We'll return the current value, so everything after this sets the value for the next call
455+
sequence.HasBeenCalled = true
453456
valueToReturn := sequence.Current
454457
// Increment the current value
455458
if sequence.Increment > 0 {

core/sequences/collection_funcs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func (*Collection) HandleMerge(ctx context.Context, mro merge.MergeRootObject) (
102102
return ourCurrent
103103
}
104104
})
105+
mergedSeq.HasBeenCalled = merge2.ResolveMergeValues(ourSeq.HasBeenCalled, theirSeq.HasBeenCalled, ancSeq.HasBeenCalled, hasAncestor, func(ourcalled, theirCalled bool) bool {
106+
return ourcalled || theirCalled
107+
})
105108
return &mergedSeq, &merge.MergeStats{
106109
Operation: merge.TableModified,
107110
Adds: 0,

core/sequences/root_object.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ import (
2727
)
2828

2929
const (
30-
FIELD_NAME_DATA_TYPE = "data_type"
31-
FIELD_NAME_PERSISTENCE = "persistence"
32-
FIELD_NAME_START = "start"
33-
FIELD_NAME_CURRENT = "current"
34-
FIELD_NAME_INCREMENT = "increment"
35-
FIELD_NAME_MINIMUM = "minimum"
36-
FIELD_NAME_MAXIMUM = "maximum"
37-
FIELD_NAME_CACHE = "cache"
38-
FIELD_NAME_CYCLE = "cycle"
39-
FIELD_NAME_IS_AT_END = "is_at_end"
40-
FIELD_NAME_OWNER_TABLE = "owner_table"
41-
FIELD_NAME_OWNER_COLUMN = "owner_column"
30+
FIELD_NAME_DATA_TYPE = "data_type"
31+
FIELD_NAME_PERSISTENCE = "persistence"
32+
FIELD_NAME_START = "start"
33+
FIELD_NAME_CURRENT = "current"
34+
FIELD_NAME_INCREMENT = "increment"
35+
FIELD_NAME_MINIMUM = "minimum"
36+
FIELD_NAME_MAXIMUM = "maximum"
37+
FIELD_NAME_CACHE = "cache"
38+
FIELD_NAME_CYCLE = "cycle"
39+
FIELD_NAME_IS_AT_END = "is_at_end"
40+
FIELD_NAME_HAS_BEEN_CALLED = "has_been_called"
41+
FIELD_NAME_OWNER_TABLE = "owner_table"
42+
FIELD_NAME_OWNER_COLUMN = "owner_column"
4243
)
4344

4445
// DeserializeRootObject implements the interface objinterface.Collection.
@@ -109,6 +110,18 @@ func (pgs *Collection) DiffRootObjects(ctx context.Context, fromHash string, o o
109110
ours.Current = diff.OurValue.(int64)
110111
}
111112
}
113+
if ours.HasBeenCalled != theirs.HasBeenCalled {
114+
diff := objinterface.RootObjectDiff{
115+
Type: pgtypes.Bool,
116+
FromHash: fromHash,
117+
FieldName: FIELD_NAME_HAS_BEEN_CALLED,
118+
}
119+
if pgmerge.DiffValues(&diff, ours.HasBeenCalled, theirs.HasBeenCalled, ancestor.HasBeenCalled, hasAncestor) {
120+
diffs = append(diffs, diff)
121+
} else {
122+
ours.HasBeenCalled = diff.OurValue.(bool)
123+
}
124+
}
112125
if ours.Increment != theirs.Increment {
113126
diff := objinterface.RootObjectDiff{
114127
Type: pgtypes.Int64,
@@ -239,6 +252,8 @@ func (pgs *Collection) GetFieldType(ctx context.Context, fieldName string) *pgty
239252
return pgtypes.Bool
240253
case FIELD_NAME_IS_AT_END:
241254
return pgtypes.Bool
255+
case FIELD_NAME_HAS_BEEN_CALLED:
256+
return pgtypes.Bool
242257
case FIELD_NAME_OWNER_TABLE:
243258
return pgtypes.Text
244259
case FIELD_NAME_OWNER_COLUMN:

core/sequences/serialization.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (sequence *Sequence) Serialize(ctx context.Context) ([]byte, error) {
3131

3232
// Create the writer
3333
writer := utils.NewWriter(256)
34-
writer.VariableUint(0) // Version
34+
writer.VariableUint(1) // Version
3535
// Write the sequence data
3636
writer.Id(sequence.Id.AsId())
3737
writer.Id(sequence.DataTypeID.AsId())
@@ -44,6 +44,7 @@ func (sequence *Sequence) Serialize(ctx context.Context) ([]byte, error) {
4444
writer.Int64(sequence.Cache)
4545
writer.Bool(sequence.Cycle)
4646
writer.Bool(sequence.IsAtEnd)
47+
writer.Bool(sequence.HasBeenCalled)
4748
writer.Id(sequence.OwnerTable.AsId())
4849
writer.String(sequence.OwnerColumn)
4950
// Returns the data
@@ -52,13 +53,13 @@ func (sequence *Sequence) Serialize(ctx context.Context) ([]byte, error) {
5253

5354
// DeserializeSequence returns the Sequence that was serialized in the byte slice. Returns an empty Sequence if data is
5455
// nil or empty.
55-
func DeserializeSequence(ctx context.Context, data []byte) (*Sequence, error) {
56+
func DeserializeSequence(_ context.Context, data []byte) (*Sequence, error) {
5657
if len(data) == 0 {
5758
return nil, nil
5859
}
5960
reader := utils.NewReader(data)
6061
version := reader.VariableUint()
61-
if version != 0 {
62+
if version > 1 {
6263
return nil, errors.Errorf("version %d of sequences is not supported, please upgrade the server", version)
6364
}
6465

@@ -75,6 +76,9 @@ func DeserializeSequence(ctx context.Context, data []byte) (*Sequence, error) {
7576
sequence.Cache = reader.Int64()
7677
sequence.Cycle = reader.Bool()
7778
sequence.IsAtEnd = reader.Bool()
79+
if version >= 1 {
80+
sequence.HasBeenCalled = reader.Bool()
81+
}
7882
sequence.OwnerTable = id.Table(reader.Id())
7983
sequence.OwnerColumn = reader.String()
8084
if !reader.IsEmpty() {

go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v3 v3.2.3
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20260603172609-0adf0e2d0069
9+
github.com/dolthub/dolt/go v0.40.5-0.20260605000101-c6f847cb5242
1010
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
12-
github.com/dolthub/go-mysql-server v0.20.1-0.20260603165028-b60521c3724e
12+
github.com/dolthub/go-mysql-server v0.20.1-0.20260604232018-6a9dd7b59c86
1313
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1
1414
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
15-
github.com/dolthub/vitess v0.0.0-20260528164423-e3f9fa81284c
15+
github.com/dolthub/vitess v0.0.0-20260604210335-0893abc80542
1616
github.com/fatih/color v1.13.0
1717
github.com/goccy/go-json v0.10.2
1818
github.com/gogo/protobuf v1.3.2
@@ -23,7 +23,7 @@ require (
2323
github.com/jackc/pglogrepl v0.0.0-20240307033717-828fbfe908e9
2424
github.com/jackc/pgtype v1.14.0
2525
github.com/jackc/pgx/v4 v4.18.2
26-
github.com/jackc/pgx/v5 v5.6.1-0.20240826124046-97d20ccfadaa
26+
github.com/jackc/pgx/v5 v5.9.2
2727
github.com/lib/pq v1.10.9
2828
github.com/madflojo/testcerts v1.1.1
2929
github.com/mitchellh/go-ps v1.0.0
@@ -41,7 +41,7 @@ require (
4141
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
4242
golang.org/x/net v0.50.0
4343
golang.org/x/sync v0.20.0
44-
golang.org/x/sys v0.42.0
44+
golang.org/x/sys v0.45.0
4545
golang.org/x/text v0.35.0
4646
gopkg.in/src-d/go-errors.v1 v1.0.0
4747
gopkg.in/yaml.v2 v2.4.0
@@ -104,7 +104,7 @@ require (
104104
github.com/denisbrodbeck/machineid v1.0.1 // indirect
105105
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 // indirect
106106
github.com/dolthub/dolt-mcp v0.3.4 // indirect
107-
github.com/dolthub/fslock v0.0.4 // indirect
107+
github.com/dolthub/fslock v0.0.5 // indirect
108108
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866 // indirect
109109
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 // indirect
110110
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 // indirect
@@ -142,6 +142,7 @@ require (
142142
github.com/jackc/pgpassfile v1.0.0 // indirect
143143
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
144144
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
145+
github.com/jackc/puddle/v2 v2.2.2 // indirect
145146
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d // indirect
146147
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6 // indirect
147148
github.com/klauspost/compress v1.18.0 // indirect

go.sum

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,18 @@ github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:I
246246
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo=
247247
github.com/dolthub/dolt-mcp v0.3.4 h1:AyG5cw+fNWXDHXujtQnqUPZrpWtPg6FN6yYtjv1pP44=
248248
github.com/dolthub/dolt-mcp v0.3.4/go.mod h1:bCZ7KHvDYs+M0e+ySgmGiNvLhcwsN7bbf5YCyillLrk=
249-
github.com/dolthub/dolt/go v0.40.5-0.20260603172609-0adf0e2d0069 h1:tsedds8wbL0CnHNYSH0bL9jXArGVdtlpx5ProefkB40=
250-
github.com/dolthub/dolt/go v0.40.5-0.20260603172609-0adf0e2d0069/go.mod h1:TJo9UN4IiXL4sx6NHVxWntKmpMKx4Cng31lqxtZxZlw=
249+
github.com/dolthub/dolt/go v0.40.5-0.20260605000101-c6f847cb5242 h1:nx7bb7QFGHvZgCDjTDFQgU3IwdyKs0GI3fT9HqdnB1w=
250+
github.com/dolthub/dolt/go v0.40.5-0.20260605000101-c6f847cb5242/go.mod h1:VQdcfyqjyhjVDZSBagYjimKXfTQNYGtWA0MHx1fIGDU=
251251
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69 h1:JShhbqMw26nKx3pqqu/cFxOpzBkN+4elVhzuUfgDw2k=
252252
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69/go.mod h1:SSLraQS/jGLYFgff3vuZ+JbVUct6vyEeMzjLBqWqoyM=
253253
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
254254
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2/go.mod h1:mIEZOHnFx4ZMQeawhw9rhsj+0zwQj7adVsnBX7t+eKY=
255-
github.com/dolthub/fslock v0.0.4 h1:p0FcUPu81bO53349qPT1im7XyGu3CwZDsB0PEVdFcaE=
256-
github.com/dolthub/fslock v0.0.4/go.mod h1:895XJNoMTlL5N1TjOJbd9Pnpjtv1DW/Ddw9qShcAYsM=
255+
github.com/dolthub/fslock v0.0.5 h1:QoXhBhgY1oumHE26qyE7tgmXUT8qjJwxsIzo54O/B/k=
256+
github.com/dolthub/fslock v0.0.5/go.mod h1:sdofYYqE0D79zNZyB4/kmlnsQOVap1C2yByjGKSirEM=
257257
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866 h1:U6gSf5I0e6h6GP1/5Sa7D2lWW1CWfcVPtY5wkyHq6jY=
258258
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
259-
github.com/dolthub/go-mysql-server v0.20.1-0.20260603165028-b60521c3724e h1:rqmQ4Jm9lSZKbeFNZBvjZmPrfauN3ZYosfajkE5hlRM=
260-
github.com/dolthub/go-mysql-server v0.20.1-0.20260603165028-b60521c3724e/go.mod h1:UTL4UvG/y8PMBcI8I60gf0DH4YPBALW/8UQCcvft95Y=
259+
github.com/dolthub/go-mysql-server v0.20.1-0.20260604232018-6a9dd7b59c86 h1:V5tdwzJZOzaRHq7TpCP12/rHztVl7m3YKGZd8ej4h+E=
260+
github.com/dolthub/go-mysql-server v0.20.1-0.20260604232018-6a9dd7b59c86/go.mod h1:A3nEC4RgBm9UzuQCGhQhJDQAiFMPsZU3NPKbGhEd8R4=
261261
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
262262
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
263263
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 h1:oIW9HwuWrhxv+4HZxA+QQSKHLqWFyXZ2FmNjUYwkdiM=
@@ -268,8 +268,8 @@ github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1 h1:GY17cGA4
268268
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1/go.mod h1:qnrZP3/1slFl2Bq5yw38HLOsArZareGwdpEceriblLc=
269269
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4EHUcEVQCMRBej8DYxjYjRz/9MdF/NNQh0o70=
270270
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
271-
github.com/dolthub/vitess v0.0.0-20260528164423-e3f9fa81284c h1:DRmvqtt1OCIdtFAg8daaaIOGEe6gVWiSlhABDi+lNIg=
272-
github.com/dolthub/vitess v0.0.0-20260528164423-e3f9fa81284c/go.mod h1:dKAkzdfRkAudpc0g8JOQ0eiEjV83TYIFz/yNIEdcjXM=
271+
github.com/dolthub/vitess v0.0.0-20260604210335-0893abc80542 h1:0A5Y1IP9ribdYzzWDZwN/NM+oxCfmYh7NuM2xIIrEag=
272+
github.com/dolthub/vitess v0.0.0-20260604210335-0893abc80542/go.mod h1:dKAkzdfRkAudpc0g8JOQ0eiEjV83TYIFz/yNIEdcjXM=
273273
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
274274
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
275275
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
@@ -515,14 +515,13 @@ github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQ
515515
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
516516
github.com/jackc/pgx/v4 v4.18.2 h1:xVpYkNR5pk5bMCZGfClbO962UIqVABcAGt7ha1s/FeU=
517517
github.com/jackc/pgx/v4 v4.18.2/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw=
518-
github.com/jackc/pgx/v5 v5.6.1-0.20240826124046-97d20ccfadaa h1:IIbDgou/DST5BTnRceegoZORXtRgthC3VR1TKIrsrns=
519-
github.com/jackc/pgx/v5 v5.6.1-0.20240826124046-97d20ccfadaa/go.mod h1:awP1KNnjylvpxHuHP63gzjhnGkI1iw+PMoIwvoleN/8=
518+
github.com/jackc/pgx/v5 v5.9.2 h1:3ZhOzMWnR4yJ+RW1XImIPsD1aNSz4T4fyP7zlQb56hw=
519+
github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
520520
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
521521
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
522522
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
523-
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
524-
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
525-
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
523+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
524+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
526525
github.com/jcmturner/gofork v0.0.0-20180107083740-2aebee971930/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
527526
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
528527
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
@@ -1036,8 +1035,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
10361035
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10371036
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10381037
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1039-
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
1040-
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
1038+
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
1039+
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
10411040
golang.org/x/telemetry v0.0.0-20260209163413-e7419c687ee4 h1:bTLqdHv7xrGlFbvf5/TXNxy/iUwwdkjhqQTJDjW7aj0=
10421041
golang.org/x/telemetry v0.0.0-20260209163413-e7419c687ee4/go.mod h1:g5NllXBEermZrmR51cJDQxmJUHUOfRAaNyWBM+R+548=
10431042
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=

server/ast/alter_table.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/sirupsen/logrus"
2323

2424
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
25+
pgnodes "github.com/dolthub/doltgresql/server/node"
2526
pgtypes "github.com/dolthub/doltgresql/server/types"
2627
)
2728

@@ -44,6 +45,16 @@ func nodeAlterTable(ctx *Context, node *tree.AlterTable) (vitess.Statement, erro
4445
if ok {
4546
return nodeAlterTableComputed(ctx, treeTableName, cmd)
4647
}
48+
if vcmd, ok := node.Cmds[0].(*tree.AlterTableValidateConstraint); ok {
49+
return vitess.InjectedStatement{
50+
Statement: pgnodes.NewValidateConstraint(
51+
tableName.SchemaQualifier.String(),
52+
tableName.Name.String(),
53+
bareIdentifier(vcmd.Constraint),
54+
),
55+
Children: nil,
56+
}, nil
57+
}
4758
}
4859
statements, noOps, err := nodeAlterTableCmds(ctx, node.Cmds, tableName, node.IfExists)
4960
if err != nil {
@@ -184,18 +195,20 @@ func nodeAlterTableAddConstraint(
184195
tableName vitess.TableName,
185196
ifExists bool) (*vitess.DDL, error) {
186197

187-
if node.ValidationBehavior == tree.ValidationSkip {
188-
// currently only allowed for foreign key and CHECK constraints
189-
return nil, errors.Errorf("NOT VALID is not supported yet")
198+
notValid := node.ValidationBehavior == tree.ValidationSkip
199+
if notValid {
200+
if _, ok := node.ConstraintDef.(*tree.UniqueConstraintTableDef); ok {
201+
return nil, errors.Errorf("NOT VALID is not applicable to UNIQUE or PRIMARY KEY constraints")
202+
}
190203
}
191204

192205
switch constraintDef := node.ConstraintDef.(type) {
193206
case *tree.CheckConstraintTableDef:
194-
return nodeCheckConstraintTableDef(ctx, constraintDef, tableName, ifExists)
207+
return nodeCheckConstraintTableDef(ctx, constraintDef, tableName, ifExists, notValid)
195208
case *tree.UniqueConstraintTableDef:
196209
return nodeUniqueConstraintTableDef(ctx, constraintDef, tableName, ifExists)
197210
case *tree.ForeignKeyConstraintTableDef:
198-
foreignKeyDefinition, err := nodeForeignKeyConstraintTableDef(ctx, constraintDef)
211+
foreignKeyDefinition, err := nodeForeignKeyConstraintTableDef(ctx, constraintDef, notValid)
199212
if err != nil {
200213
return nil, err
201214
}

server/ast/constraint_table_def.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import (
2525
// nodeCheckConstraintTableDef converts a tree.CheckConstraintTableDef instance
2626
// into a vitess.DDL instance that can be executed by GMS. |tableName| identifies
2727
// the table being altered, and |ifExists| indicates whether the IF EXISTS clause
28-
// was specified.
28+
// was specified. |notValid| reflects whether the NOT VALID clause was present.
2929
func nodeCheckConstraintTableDef(
3030
ctx *Context,
3131
node *tree.CheckConstraintTableDef,
3232
tableName vitess.TableName,
33-
ifExists bool) (*vitess.DDL, error) {
33+
ifExists bool,
34+
notValid bool) (*vitess.DDL, error) {
3435

3536
if node.NoInherit {
3637
return nil, errors.Errorf("NO INHERIT is not yet supported for check constraints")
@@ -53,6 +54,7 @@ func nodeCheckConstraintTableDef(
5354
Details: &vitess.CheckConstraintDefinition{
5455
Expr: expr,
5556
Enforced: true,
57+
NotValid: notValid,
5658
},
5759
},
5860
},

server/ast/convert.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import (
2323
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
2424
)
2525

26+
// UnknownColSentinelPrefix is prepended to the index position of unaliased string literals in a
27+
// SELECT clause. This gives GMS a unique per-position alias so its alias scope map can distinguish
28+
// multiple unnamed columns in the same SELECT. schemaToFieldDescriptions in doltgres_handler.go
29+
// strips this prefix and returns Postgres's "?column?" placeholder on the wire.
30+
const UnknownColSentinelPrefix = "__?column?__"
31+
2632
// Convert converts a Postgres AST into a Vitess AST.
2733
func Convert(postgresStmt parser.Statement) (vitess.Statement, error) {
2834
ctx := NewContext(postgresStmt)

server/ast/foreign_key_constraint_table_def.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ import (
2323
)
2424

2525
// nodeForeignKeyConstraintTableDef handles *tree.ForeignKeyConstraintTableDef nodes.
26-
func nodeForeignKeyConstraintTableDef(ctx *Context, node *tree.ForeignKeyConstraintTableDef) (*vitess.ForeignKeyDefinition, error) {
26+
func nodeForeignKeyConstraintTableDef(ctx *Context, node *tree.ForeignKeyConstraintTableDef, notValid bool) (*vitess.ForeignKeyDefinition, error) {
2727
if node == nil {
2828
return nil, nil
2929
}
30+
var matchType vitess.ForeignKeyMatchType
3031
switch node.Match {
3132
case tree.MatchSimple:
32-
// This is the default behavior
33+
matchType = vitess.MatchSimple
3334
case tree.MatchFull:
34-
return nil, errors.Errorf("MATCH FULL is not yet supported")
35+
matchType = vitess.MatchFull
3536
case tree.MatchPartial:
3637
return nil, errors.Errorf("MATCH PARTIAL is not yet supported")
3738
default:
@@ -78,5 +79,7 @@ func nodeForeignKeyConstraintTableDef(ctx *Context, node *tree.ForeignKeyConstra
7879
ReferencedColumns: toCols,
7980
OnDelete: refActions[0],
8081
OnUpdate: refActions[1],
82+
NotValid: notValid,
83+
MatchType: matchType,
8184
}, nil
8285
}

0 commit comments

Comments
 (0)