badalprasadsingh commented on code in PR #1244:
URL: https://github.com/apache/iceberg-go/pull/1244#discussion_r3530871923


##########
catalog/sql/sql.go:
##########
@@ -247,12 +286,141 @@ func (c *Catalog) DropSQLTables(ctx context.Context) 
error {
 }
 
 func (c *Catalog) ensureTablesExist() error {
-       return c.CreateSQLTables(context.Background())
+       ctx := context.Background()
+       if err := c.CreateSQLTables(ctx); err != nil {
+               return err
+       }
+
+       return c.migrateV0Schema(ctx)
+}
+
+func (c *Catalog) detectSchemaVersion(ctx context.Context) error {
+       hasCol, err := c.icebergTypeColumnExists(ctx)
+       if err != nil {
+               return fmt.Errorf("detecting catalog schema version: %w", err)
+       }
+
+       if hasCol {
+               c.schemaVersion = schemaV1
+       } else {
+               c.schemaVersion = schemaV0
+       }
+
+       return nil
+}
+
+func (c *Catalog) migrateV0Schema(ctx context.Context) error {
+       hasCol, err := c.icebergTypeColumnExists(ctx)
+       if err != nil {
+               return fmt.Errorf("V0 schema migration: column probe failed: 
%w", err)
+       }
+       if hasCol {
+               c.schemaVersion = schemaV1
+
+               return nil
+       }
+
+       if !strings.EqualFold(c.props.Get(SchemaVersionKey, ""), 
SchemaVersionV1) {

Review Comment:
   Well
   
   I checked, Iceberg-java makes it case-insensititve in case update Schema is 
required. Please check 
[here](https://github.com/apache/iceberg/blob/04a35e412d2f37bb03e0cc68d56111be5d8dbb5b/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L250).
 Happy to know in case we want to case-sensitive.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to