Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
pg: add index comment to sync schema.
spinningbot33b96849c410
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.goindex 3e9fc4baf1..1fac327453 100644--- a/plugin/db/pg/pg.go+++ b/plugin/db/pg/pg.go@@ -411,6 +411,7 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchdbIndex.Position = i + 1dbIndex.Type = idx.methodTypedbIndex.Unique = idx.unique+ dbIndex.Comment = idx.commentdbTable.IndexList = append(dbTable.IndexList, dbIndex)}}@@ -991,6 +992,7 @@ type indexSchema struct {// methodType such as btree.methodType stringcolumnExpressions []string+ comment string}// sequencePgSchema describes the schema of a pg sequence.@@ -1483,9 +1485,33 @@ func getIndices(txn *sql.Tx) ([]*indexSchema, error) {indices = append(indices, &idx)}+ for _, idx := range indices {+ if err = getIndex(txn, idx); err != nil {+ return nil, fmt.Errorf("getPgView(%q, %q) got error %v", idx.schemaName, idx.name, err)+ }+ }+return indices, nil}+func getIndex(txn *sql.Tx, idx *indexSchema) error {+ commentQuery := fmt.Sprintf("SELECT obj_description('%s.%s'::regclass);", idx.schemaName, idx.name)+ crows, err := txn.Query(commentQuery)+ if err != nil {+ return err+ }+ defer crows.Close()++ for crows.Next() {+ var comment sql.NullString+ if err := crows.Scan(&comment); err != nil {+ return err+ }+ idx.comment = comment.String+ }+ return nil+}+func getIndexMethodType(stmt string) string {re := regexp.MustCompile(`USING (\w+) `)matches := re.FindStringSubmatch(stmt)diff --git a/server/sql.go b/server/sql.goindex d221486619..a91047ee59 100644--- a/server/sql.go+++ b/server/sql.go@@ -124,6 +124,7 @@ func (s *Server) SyncEngineVersionAndSchema(ctx context.Context, instance *api.I// Sync schemauserList, schemaList, err := driver.SyncSchema(ctx)if err != nil {+ fmt.Printf("sync schema error: %v\n", err)resultSet.Error = err.Error()} else {var createTable = func(database *api.Database, tableCreate *api.TableCreate) (*api.Table, error) {