Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: sync pg sequence (#14489)

h3n4le55e1516f459
diff --git a/backend/api/v1/database_converter.go b/backend/api/v1/database_converter.go
index de72ab4b5f..f682c2a105 100644
--- a/backend/api/v1/database_converter.go
+++ b/backend/api/v1/database_converter.go
@@ -170,6 +170,24 @@ func convertStoreDatabaseMetadata(ctx context.Context, metadata *storepb.Databas
}
s.Triggers = append(s.Triggers, v1Trigger)
}
+
+ for _, sequence := range schema.Sequences {
+ if sequence == nil {
+ continue
+ }
+ v1Sequence := &v1pb.SequenceMetadata{
+ Name: sequence.Name,
+ DataType: sequence.DataType,
+ Start: sequence.Start,
+ MinValue: sequence.MinValue,
+ MaxValue: sequence.MaxValue,
+ Increment: sequence.Increment,
+ Cycle: sequence.Cycle,
+ CacheSize: sequence.CacheSize,
+ LastValue: sequence.LastValue,
+ }
+ s.Sequences = append(s.Sequences, v1Sequence)
+ }
}
for _, extension := range metadata.Extensions {
if extension == nil {
diff --git a/backend/plugin/db/pg/sync.go b/backend/plugin/db/pg/sync.go
index 24fea49f8f..fb5dcbb110 100644
--- a/backend/plugin/db/pg/sync.go
+++ b/backend/plugin/db/pg/sync.go
@@ -6,6 +6,7 @@ import (
"fmt"
"log/slog"
"regexp"
+ "strconv"
"strings"
"time"
@@ -763,26 +764,54 @@ func getExtensions(txn *sql.Tx) ([]*storepb.ExtensionMetadata, error) {
// getSequences gets all sequences of a database.
func getSequences(txn *sql.Tx) (map[string][]*storepb.SequenceMetadata, error) {
- query := `SELECT sequence_schema, sequence_name, data_type FROM information_schema.sequences;`
+ query := `
+ SELECT
+ schemaname,
+ sequencename,
+ data_type,
+ start_value,
+ min_value,
+ max_value,
+ increment_by,
+ cycle,
+ cache_size,
+ last_value
+ FROM pg_sequences
+ ORDER BY schemaname, sequencename;`
rows, err := txn.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
-
sequenceMap := make(map[string][]*storepb.SequenceMetadata)
for rows.Next() {
- sequence := &storepb.SequenceMetadata{}
- var schemaName string
- if err := rows.Scan(&schemaName, &sequence.Name, &sequence.DataType); err != nil {
+ var schemaName, sequenceName, dataType string
+ var startValue, minValue, maxValue, incrementBy, cacheSize int64
+ var cycle bool
+ var lastValue sql.NullInt64
+ if err := rows.Scan(&schemaName, &sequenceName, &dataType, &startValue, &minValue, &maxValue, &incrementBy, &cycle, &cacheSize, &lastValue); err != nil {
return nil, err
}
+ lastValueStr := ""
+ if lastValue.Valid {
+ lastValueStr = strconv.FormatInt(lastValue.Int64, 10)
+ }
+ sequence := &storepb.SequenceMetadata{
+ Name: sequenceName,
+ DataType: dataType,
+ Start: strconv.FormatInt(startValue, 10),
+ MinValue: strconv.FormatInt(minValue, 10),
+ MaxValue: strconv.FormatInt(maxValue, 10),
+ Increment: strconv.FormatInt(incrementBy, 10),
+ Cycle: cycle,
+ CacheSize: strconv.FormatInt(cacheSize, 10),
+ LastValue: lastValueStr,
+ }
sequenceMap[schemaName] = append(sequenceMap[schemaName], sequence)
}
if err := rows.Err(); err != nil {
return nil, err
}
-
return sequenceMap, nil
}
diff --git a/frontend/src/types/proto/store/database.ts b/frontend/src/types/proto/store/database.ts
index 674a9e9927..58e07ae4e3 100644
--- a/frontend/src/types/proto/store/database.ts
+++ b/frontend/src/types/proto/store/database.ts
@@ -93,7 +93,7 @@ export interface SequenceMetadata {
/** The data type of a sequence. */
dataType: string;
/** The start value of a sequence. */
- start: Long;
+ start: string;
/** The minimum value of a sequence. */
minValue: string;
/** The maximum value of a sequence. */
@@ -1580,7 +1580,7 @@ function createBaseSequenceMetadata(): SequenceMetadata {
return {
name: "",
dataType: "",
- start: Long.ZERO,
+ start: "",
minValue: "",
maxValue: "",
increment: "",
@@ -1598,8 +1598,8 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
if (message.dataType !== "") {
writer.uint32(18).string(message.dataType);
}
- if (!message.start.equals(Long.ZERO)) {
- writer.uint32(24).int64(message.start.toString());
+ if (message.start !== "") {
+ writer.uint32(26).string(message.start);
}
if (message.minValue !== "") {
writer.uint32(34).string(message.minValue);
@@ -1644,11 +1644,11 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
message.dataType = reader.string();
continue;
case 3:
- if (tag !== 24) {
+ if (tag !== 26) {
break;
}
- message.start = Long.fromString(reader.int64().toString());
+ message.start = reader.string();
continue;
case 4:
if (tag !== 34) {
@@ -1705,7 +1705,7 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
return {
name: isSet(object.name) ? globalThis.String(object.name) : "",
dataType: isSet(object.dataType) ? globalThis.String(object.dataType) : "",
- start: isSet(object.start) ? Long.fromValue(object.start) : Long.ZERO,
+ start: isSet(object.start) ? globalThis.String(object.start) : "",
minValue: isSet(object.minValue) ? globalThis.String(object.minValue) : "",
maxValue: isSet(object.maxValue) ? globalThis.String(object.maxValue) : "",
increment: isSet(object.increment) ? globalThis.String(object.increment) : "",
@@ -1723,8 +1723,8 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
if (message.dataType !== "") {
obj.dataType = message.dataType;
}
- if (!message.start.equals(Long.ZERO)) {
- obj.start = (message.start || Long.ZERO).toString();
+ if (message.start !== "") {
+ obj.start = message.start;
}
if (message.minValue !== "") {
obj.minValue = message.minValue;
@@ -1754,7 +1754,7 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
const message = createBaseSequenceMetadata();
message.name = object.name ?? "";
message.dataType = object.dataType ?? "";
- message.start = (object.start !== undefined && object.start !== null) ? Long.fromValue(object.start) : Long.ZERO;
+ message.start = object.start ?? "";
message.minValue = object.minValue ?? "";
message.maxValue = object.maxValue ?? "";
message.increment = object.increment ?? "";
diff --git a/frontend/src/types/proto/v1/database_service.ts b/frontend/src/types/proto/v1/database_service.ts
index 2dee2b9d39..ff1a3bba14 100644
--- a/frontend/src/types/proto/v1/database_service.ts
+++ b/frontend/src/types/proto/v1/database_service.ts
@@ -519,7 +519,7 @@ export interface SequenceMetadata {
/** The data type of a sequence. */
dataType: string;
/** The start value of a sequence. */
- start: Long;
+ start: string;
/** The minimum value of a sequence. */
minValue: string;
/** The maximum value of a sequence. */
@@ -4050,7 +4050,7 @@ function createBaseSequenceMetadata(): SequenceMetadata {
return {
name: "",
dataType: "",
- start: Long.ZERO,
+ start: "",
minValue: "",
maxValue: "",
increment: "",
@@ -4068,8 +4068,8 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
if (message.dataType !== "") {
writer.uint32(18).string(message.dataType);
}
- if (!message.start.equals(Long.ZERO)) {
- writer.uint32(24).int64(message.start.toString());
+ if (message.start !== "") {
+ writer.uint32(26).string(message.start);
}
if (message.minValue !== "") {
writer.uint32(34).string(message.minValue);
@@ -4114,11 +4114,11 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
message.dataType = reader.string();
continue;
case 3:
- if (tag !== 24) {
+ if (tag !== 26) {
break;
}
- message.start = Long.fromString(reader.int64().toString());
+ message.start = reader.string();
continue;
case 4:
if (tag !== 34) {
@@ -4175,7 +4175,7 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
return {
name: isSet(object.name) ? globalThis.String(object.name) : "",
dataType: isSet(object.dataType) ? globalThis.String(object.dataType) : "",
- start: isSet(object.start) ? Long.fromValue(object.start) : Long.ZERO,
+ start: isSet(object.start) ? globalThis.String(object.start) : "",
minValue: isSet(object.minValue) ? globalThis.String(object.minValue) : "",
maxValue: isSet(object.maxValue) ? globalThis.String(object.maxValue) : "",
increment: isSet(object.increment) ? globalThis.String(object.increment) : "",
@@ -4193,8 +4193,8 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
if (message.dataType !== "") {
obj.dataType = message.dataType;
}
- if (!message.start.equals(Long.ZERO)) {
- obj.start = (message.start || Long.ZERO).toString();
+ if (message.start !== "") {
+ obj.start = message.start;
}
if (message.minValue !== "") {
obj.minValue = message.minValue;
@@ -4224,7 +4224,7 @@ export const SequenceMetadata: MessageFns<SequenceMetadata> = {
const message = createBaseSequenceMetadata();
message.name = object.name ?? "";
message.dataType = object.dataType ?? "";
- message.start = (object.start !== undefined && object.start !== null) ? Long.fromValue(object.start) : Long.ZERO;
+ message.start = object.start ?? "";
message.minValue = object.minValue ?? "";
message.maxValue = object.maxValue ?? "";
message.increment = object.increment ?? "";
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index fa04533a39..4fda5ff033 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -1380,7 +1380,7 @@ This is the concept of schema in Postgres, but it&#39;s a no-op for MySQL.
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of a sequence. |
| data_type | [string](#string) | | The data type of a sequence. |
-| start | [int64](#int64) | | The start value of a sequence. |
+| start | [string](#string) | | The start value of a sequence. |
| min_value | [string](#string) | | The minimum value of a sequence. |
| max_value | [string](#string) | | The maximum value of a sequence. |
| increment | [string](#string) | | Increment value of a sequence. |
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index 9f6aa41164..53057e7f70 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -4155,7 +4155,7 @@ table_name, event, timing, action_order. </p></td>
<tr>
<td>start</td>
- <td><a href="#int64">int64</a></td>
+ <td><a href="#string">string</a></td>
<td></td>
<td><p>The start value of a sequence. </p></td>
</tr>
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index eb53ddb86f..c4a2654fdf 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -2785,7 +2785,7 @@ Secret is the secret of the database now.
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of a sequence. |
| data_type | [string](#string) | | The data type of a sequence. |
-| start | [int64](#int64) | | The start value of a sequence. |
+| start | [string](#string) | | The start value of a sequence. |
| min_value | [string](#string) | | The minimum value of a sequence. |
| max_value | [string](#string) | | The maximum value of a sequence. |
| increment | [string](#string) | | Increment value of a sequence. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 9d52ab61a2..7cb2babc50 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -8559,7 +8559,7 @@ instances/{instance}/databases/{database}/secrets/{secret} </p></td>
<tr>
<td>start</td>
- <td><a href="#int64">int64</a></td>
+ <td><a href="#string">string</a></td>
<td></td>
<td><p>The start value of a sequence. </p></td>
</tr>
diff --git a/proto/generated-go/store/database.pb.go b/proto/generated-go/store/database.pb.go
index a1773134d1..d86864dd7d 100644
--- a/proto/generated-go/store/database.pb.go
+++ b/proto/generated-go/store/database.pb.go
@@ -640,7 +640,7 @@ type SequenceMetadata struct {
// The data type of a sequence.
DataType string `protobuf:"bytes,2,opt,name=data_type,json=dataType,proto3" json:"data_type,omitempty"`
// The start value of a sequence.
- Start int64 `protobuf:"varint,3,opt,name=start,proto3" json:"start,omitempty"`
+ Start string `protobuf:"bytes,3,opt,name=start,proto3" json:"start,omitempty"`
// The minimum value of a sequence.
MinValue string `protobuf:"bytes,4,opt,name=min_value,json=minValue,proto3" json:"min_value,omitempty"`
// The maximum value of a sequence.
@@ -699,11 +699,11 @@ func (x *SequenceMetadata) GetDataType() string {
return ""
}
-func (x *SequenceMetadata) GetStart() int64 {
+func (x *SequenceMetadata) GetStart() string {
if x != nil {
return x.Start
}
- return 0
+ return ""
}
func (x *SequenceMetadata) GetMinValue() string {
@@ -3418,7 +3418,7 @@ var file_store_database_proto_rawDesc = []byte{
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74,
0x61, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61,
0x74, 0x61, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18,
- 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x1b, 0x0a, 0x09,
+ 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x1b, 0x0a, 0x09,
0x6d, 0x69, 0x6e, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
0x08, 0x6d, 0x69, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x61, 0x78,
0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x61,
diff --git a/proto/generated-go/v1/database_service.pb.go b/proto/generated-go/v1/database_service.pb.go
index e2b54598b3..0152bf3888 100644
--- a/proto/generated-go/v1/database_service.pb.go
+++ b/proto/generated-go/v1/database_service.pb.go
@@ -1971,7 +1971,7 @@ type SequenceMetadata struct {
// The data type of a sequence.
DataType string `protobuf:"bytes,2,opt,name=data_type,json=dataType,proto3" json:"data_type,omitempty"`
// The start value of a sequence.
- Start int64 `protobuf:"varint,3,opt,name=start,proto3" json:"start,omitempty"`
+ Start string `protobuf:"bytes,3,opt,name=start,proto3" json:"start,omitempty"`
// The minimum value of a sequence.
MinValue string `protobuf:"bytes,4,opt,name=min_value,json=minValue,proto3" json:"min_value,omitempty"`
// The maximum value of a sequence.
@@ -2030,11 +2030,11 @@ func (x *SequenceMetadata) GetDataType() string {
return ""
}
-func (x *SequenceMetadata) GetStart() int64 {
+func (x *SequenceMetadata) GetStart() string {
if x != nil {
return x.Start
}
- return 0
+ return ""
}
func (x *SequenceMetadata) GetMinValue() string {
@@ -7336,7 +7336,7 @@ var file_v1_database_service_proto_rawDesc = []byte{
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61,
0x74, 0x61, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64,
0x61, 0x74, 0x61, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74,
- 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x1b, 0x0a,
+ 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x1b, 0x0a,
0x09, 0x6d, 0x69, 0x6e, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x08, 0x6d, 0x69, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x61,
0x78, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d,
diff --git a/proto/store/database.proto b/proto/store/database.proto
index 0cefc5ed91..cc2e29f935 100644
--- a/proto/store/database.proto
+++ b/proto/store/database.proto
@@ -96,7 +96,7 @@ message SequenceMetadata {
string data_type = 2;
// The start value of a sequence.
- int64 start = 3;
+ string start = 3;
// The minimum value of a sequence.
string min_value = 4;
diff --git a/proto/v1/database_service.proto b/proto/v1/database_service.proto
index 36906d2084..5a6f5e5b1f 100644
--- a/proto/v1/database_service.proto
+++ b/proto/v1/database_service.proto
@@ -522,7 +522,7 @@ message SequenceMetadata {
string data_type = 2;
// The start value of a sequence.
- int64 start = 3;
+ string start = 3;
// The minimum value of a sequence.
string min_value = 4;