writeColumnSDL writes a single column definition to the output writer This function is extracted from writeCreateTableSDL to enable code reuse sequences parameter is optional and used to find identity sequences for the column tableName is used to verify sequence ownership for serial column detection
(out io.Writer, column *storepb.ColumnMetadata, tableName string, sequences []*storepb.SequenceMetadata)
| 3060 | // sequences parameter is optional and used to find identity sequences for the column |
| 3061 | // tableName is used to verify sequence ownership for serial column detection |
| 3062 | func writeColumnSDL(out io.Writer, column *storepb.ColumnMetadata, tableName string, sequences []*storepb.SequenceMetadata) error { |
| 3063 | if _, err := io.WriteString(out, `"`); err != nil { |
| 3064 | return err |
| 3065 | } |
| 3066 | |
| 3067 | if _, err := io.WriteString(out, column.Name); err != nil { |
| 3068 | return err |
| 3069 | } |
| 3070 | |
| 3071 | if _, err := io.WriteString(out, `" `); err != nil { |
| 3072 | return err |
| 3073 | } |
| 3074 | |
| 3075 | // Check if this is an identity column |
| 3076 | if isIdentityColumn(column) { |
| 3077 | // Find the sequence for this identity column |
| 3078 | var identitySequence *storepb.SequenceMetadata |
| 3079 | for _, seq := range sequences { |
| 3080 | if seq.OwnerColumn == column.Name { |
| 3081 | identitySequence = seq |
| 3082 | break |
| 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | // Write type |
| 3087 | if _, err := io.WriteString(out, column.Type); err != nil { |
| 3088 | return err |
| 3089 | } |
| 3090 | |
| 3091 | // Write GENERATED ... AS IDENTITY |
| 3092 | if _, err := io.WriteString(out, " GENERATED "); err != nil { |
| 3093 | return err |
| 3094 | } |
| 3095 | if column.IdentityGeneration == storepb.ColumnMetadata_ALWAYS { |
| 3096 | if _, err := io.WriteString(out, "ALWAYS"); err != nil { |
| 3097 | return err |
| 3098 | } |
| 3099 | } else { |
| 3100 | if _, err := io.WriteString(out, "BY DEFAULT"); err != nil { |
| 3101 | return err |
| 3102 | } |
| 3103 | } |
| 3104 | if _, err := io.WriteString(out, " AS IDENTITY"); err != nil { |
| 3105 | return err |
| 3106 | } |
| 3107 | |
| 3108 | // Write identity options if we have the sequence |
| 3109 | if identitySequence != nil { |
| 3110 | hasOptions := false |
| 3111 | // Check if we need to write options (non-default values) |
| 3112 | if identitySequence.Start != "" && identitySequence.Start != "1" { |
| 3113 | hasOptions = true |
| 3114 | } |
| 3115 | if identitySequence.Increment != "" && identitySequence.Increment != "1" { |
| 3116 | hasOptions = true |
| 3117 | } |
| 3118 | |
| 3119 | if hasOptions { |
no test coverage detected