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


##########
scripts/mysql/upgrade-1.3.0-to-2.0.0-mysql.sql:
##########
@@ -121,14 +468,21 @@ ALTER TABLE `function_version_info` RENAME INDEX 
`idx_sid` TO `function_version_
 --   SELECT COUNT(*) FROM `table_version_info`
 --    WHERE `version` IS NULL OR `deleted_at` IS NULL;
 -- The statement below fails rather than silently coercing NULL to 0.
-ALTER TABLE `table_version_info`
-    MODIFY COLUMN `version` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table 
current version',
-    MODIFY COLUMN `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 
'table deletion timestamp, 0 means not deleted',
-    DROP INDEX `uk_table_id_version_deleted_at`,
-    ADD PRIMARY KEY (`table_id`, `version`, `deleted_at`);
+SET @ddl = IF(EXISTS(SELECT 1 FROM information_schema.statistics
+    WHERE table_schema = DATABASE() AND table_name = 'table_version_info' AND 
index_name = 'PRIMARY'),
+    'SELECT 1',
+    'ALTER TABLE `table_version_info` MODIFY COLUMN `version` BIGINT(20) 
UNSIGNED NOT NULL COMMENT ''table current version'', MODIFY COLUMN `deleted_at` 
BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT ''table deletion timestamp, 0 
means not deleted'', DROP INDEX `uk_table_id_version_deleted_at`, ADD PRIMARY 
KEY (`table_id`, `version`, `deleted_at`)');

Review Comment:
   This guard accepts any primary key as a completed conversion. On a drifted 
1.3 database with `PRIMARY KEY (table_id)`, it skips the ALTER while `version` 
and `deleted_at` remain nullable and the old unique index remains. The upgrade 
then succeeds without installing the required composite key. Skip only when the 
primary key has exactly the target columns in order and the old unique index is 
gone; otherwise let the ALTER report the unexpected schema. Add a regression 
test with an unrelated primary key.



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