Copilot commented on code in PR #10860:
URL: https://github.com/apache/gravitino/pull/10860#discussion_r3136189624


##########
scripts/mysql/upgrade-1.2.0-to-1.3.0-mysql.sql:
##########
@@ -0,0 +1,48 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file--
+--  distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"). You may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--  http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+--
+
+-- using default '{}' to fill in the new column for compatibility
+ALTER TABLE `view_meta`
+    ADD COLUMN `audit_info` MEDIUMTEXT NOT NULL DEFAULT '{}' COMMENT 'view 
audit info' AFTER `schema_id`;
+
+-- remove the default value for audit_info
+ALTER TABLE `view_meta`
+    ALTER COLUMN `audit_info` DROP DEFAULT;

Review Comment:
   MySQL 5.7 does not allow DEFAULT values on TEXT/BLOB types, so adding 
`audit_info` as `MEDIUMTEXT NOT NULL DEFAULT '{}'` will fail on supported MySQL 
5.7 deployments. To keep the column non-null while remaining 5.7-compatible, 
add `audit_info` as nullable (no default), backfill existing rows with an 
UPDATE to `'{}'`, then ALTER/MODIFY the column to `NOT NULL` (and optionally 
add the column comment).
   ```suggestion
   -- add audit_info as nullable first for MySQL 5.7 compatibility
   ALTER TABLE `view_meta`
       ADD COLUMN `audit_info` MEDIUMTEXT COMMENT 'view audit info' AFTER 
`schema_id`;
   
   -- backfill existing rows before enforcing NOT NULL
   UPDATE `view_meta`
       SET `audit_info` = '{}'
       WHERE `audit_info` IS NULL;
   
   ALTER TABLE `view_meta`
       MODIFY COLUMN `audit_info` MEDIUMTEXT NOT NULL COMMENT 'view audit info' 
AFTER `schema_id`;
   ```



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

Reply via email to