MCPcopy Create free account
hub / github.com/bytebase/bytebase / writeIndexKeyList

Function writeIndexKeyList

backend/plugin/schema/pg/get_database_definition.go:2013–2057  ·  view source on GitHub ↗
(out io.Writer, index *storepb.IndexMetadata)

Source from the content-addressed store, hash-verified

2011}
2012
2013func writeIndexKeyList(out io.Writer, index *storepb.IndexMetadata) error {
2014 if _, err := io.WriteString(out, `(`); err != nil {
2015 return err
2016 }
2017
2018 for i, expression := range index.Expressions {
2019 if i > 0 {
2020 if _, err := io.WriteString(out, ", "); err != nil {
2021 return err
2022 }
2023 }
2024
2025 // expression is expected to be in canonical pg_get_indexdef form —
2026 // see IndexMetadata.expressions in proto/store/store/database.proto.
2027 // normalizeLegacyMetadata (called at the top of GetDatabaseDefinition)
2028 // repairs historical rows that pre-date the contract.
2029 if _, err := io.WriteString(out, expression); err != nil {
2030 return err
2031 }
2032
2033 // Add opclass if it's not the default
2034 if i < len(index.OpclassNames) && i < len(index.OpclassDefaults) {
2035 if !index.OpclassDefaults[i] && index.OpclassNames[i] != "" {
2036 if _, err := io.WriteString(out, " "); err != nil {
2037 return err
2038 }
2039 if _, err := io.WriteString(out, index.OpclassNames[i]); err != nil {
2040 return err
2041 }
2042 }
2043 }
2044
2045 // Add DESC if this column is marked as descending
2046 if i < len(index.Descending) && index.Descending[i] {
2047 if _, err := io.WriteString(out, " DESC"); err != nil {
2048 return err
2049 }
2050 }
2051 // Note: NULLS ordering information is not available in IndexMetadata
2052 // so we omit it in the generated DDL
2053 }
2054
2055 _, err := io.WriteString(out, ")")
2056 return err
2057}
2058
2059func writeIndexComment(out io.Writer, schema string, index *storepb.IndexMetadata) error {
2060 if _, err := io.WriteString(out, `COMMENT ON INDEX "`); err != nil {

Callers 1

writeIndexInternalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected