3434 * codecs, and different default types.
3535 */
3636public final class ChColumn extends AbstractColumn {
37-
3837 private String defaultType ;
3938
4039 private String ttl ;
@@ -48,6 +47,7 @@ public final class ChColumn extends AbstractColumn {
4847 */
4948 public ChColumn (String name ) {
5049 super (name );
50+ setNotNull (true );
5151 }
5252
5353 public void setDefaultType (String defaultType ) {
@@ -75,12 +75,7 @@ public String getFullDefinition() {
7575 var sb = new StringBuilder ();
7676 sb .append (ChDiffUtils .quoteName (name ));
7777
78- if (type != null ) {
79- sb .append (' ' ).append (type );
80- if (notNull ) {
81- sb .append (" NOT NULL" );
82- }
83- }
78+ appendType (sb );
8479 appendColumnOptions (sb );
8580 return sb .toString ();
8681 }
@@ -92,13 +87,24 @@ public void getCreationSQL(SQLScript script) {
9287 appendIfNotExists (sb , script .getSettings ());
9388 sb .append (ChDiffUtils .quoteName (name ));
9489
95- if (type != null ) {
96- sb .append (' ' ).append (type );
97- }
90+ appendType (sb );
9891 appendColumnOptions (sb );
9992 script .addStatement (sb );
10093 }
10194
95+ private void appendType (StringBuilder sb ) {
96+ if (type == null ) {
97+ return ;
98+ }
99+
100+ sb .append (' ' );
101+ if (notNull ) {
102+ sb .append (type );
103+ } else {
104+ sb .append ("Nullable(" ).append (type ).append (")" );
105+ }
106+ }
107+
102108 private void appendColumnOptions (StringBuilder sb ) {
103109 if (defaultType != null ) {
104110 sb .append (' ' ).append (defaultType );
@@ -135,7 +141,7 @@ public ObjectState appendAlterSQL(PgStatement newCondition, SQLScript script) {
135141 int startSize = script .getSize ();
136142 ChColumn newColumn = (ChColumn ) newCondition ;
137143
138- compareTypes (newColumn . type , script );
144+ compareTypes (newColumn , script );
139145 compareDefaults (newColumn , script );
140146 compareCodecs (newColumn .codecs , script );
141147 compareTtl (newColumn .ttl , newColumn .type , script );
@@ -154,13 +160,14 @@ public void getDropSQL(SQLScript script, boolean optionExists) {
154160 script .addStatement (sb );
155161 }
156162
157- private void compareTypes (String newType , SQLScript script ) {
158- if (type .equals (newType ) ) {
163+ private void compareTypes (ChColumn newColumn , SQLScript script ) {
164+ if (Objects .equals (type , newColumn . type ) && notNull == newColumn . notNull ) {
159165 return ;
160166 }
167+
161168 StringBuilder sb = new StringBuilder ();
162169 appendAlterColumn (sb , script .getSettings ());
163- sb . append ( ' ' ). append ( newType );
170+ newColumn . appendType ( sb );
164171 script .addStatement (sb );
165172 }
166173
0 commit comments