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


##########
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) {
+               log.Printf("WARNING: iceberg_tables is on the legacy V0 schema 
(no iceberg_type column); "+

Review Comment:
   Done.



-- 
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