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

Function writeUniqueKey

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

Source from the content-addressed store, hash-verified

2103}
2104
2105func writeUniqueKey(out io.Writer, schema string, table string, index *storepb.IndexMetadata) error {
2106 if _, err := io.WriteString(out, `ALTER TABLE ONLY "`); err != nil {
2107 return err
2108 }
2109 if _, err := io.WriteString(out, schema); err != nil {
2110 return err
2111 }
2112 if _, err := io.WriteString(out, `"."`); err != nil {
2113 return err
2114 }
2115 if _, err := io.WriteString(out, table); err != nil {
2116 return err
2117 }
2118 if _, err := io.WriteString(out, `" ADD CONSTRAINT "`); err != nil {
2119 return err
2120 }
2121 if _, err := io.WriteString(out, index.Name); err != nil {
2122 return err
2123 }
2124 if _, err := io.WriteString(out, `" UNIQUE (`); err != nil {
2125 return err
2126 }
2127 for i, expression := range index.Expressions {
2128 if i > 0 {
2129 if _, err := io.WriteString(out, ", "); err != nil {
2130 return err
2131 }
2132 }
2133 if _, err := io.WriteString(out, expression); err != nil {
2134 return err
2135 }
2136 }
2137 if _, err := io.WriteString(out, ");\n\n"); err != nil {
2138 return err
2139 }
2140
2141 if len(index.Comment) > 0 {
2142 if err := writeConstraintComment(out, schema, table, index); err != nil {
2143 return err
2144 }
2145 }
2146
2147 return nil
2148}
2149
2150func writePartitionPrimaryKey(out io.Writer, schema string, partition *storepb.TablePartitionMetadata) error {
2151 for _, index := range partition.Indexes {

Callers 5

writeAlterTableDiffFunction · 0.85
writeCreateIndexDiffFunction · 0.85
writeTableFunction · 0.85
writePartitionUniqueKeyFunction · 0.85

Calls 1

writeConstraintCommentFunction · 0.85

Tested by

no test coverage detected