We use below way to generate SQL from GORM:
https://stackoverflow.com/questions/66238657/how-can-i-generate-sql-code-from-gorm-struct-model
But the problem is the GORM generated SQL not stable, like below:
CREATE TABLE `components` (
`id` bigint AUTO_INCREMENT,`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,
`deleted_at` datetime(3) NULL,`tenant_id` bigint,`name` varchar(30),`version` varchar(24),
`spec` longtext,`has_archive` boolean,PRIMARY KEY (`id`),
INDEX `idx_components_tenant_id` (`tenant_id`),
INDEX `idx_components_created_at` (`created_at`),
INDEX `idx_components_deleted_at` (`deleted_at`));
But sometimes will generated below:
CREATE TABLE `components` (`id` bigint AUTO_INCREMENT,`created_at` datetime(3) NULL,
`updated_at` datetime(3) NULL,`deleted_at` datetime(3) NULL,`tenant_id` bigint,
`name` varchar(30),`version` varchar(24),`spec` longtext,`has_archive` boolean,PRIMARY KEY (`id`),
INDEX `idx_components_created_at` (`created_at`),
INDEX `idx_components_deleted_at` (`deleted_at`),
INDEX `idx_components_tenant_id` (`tenant_id`));
Can see the difference: idx_components_tenant_id and other position changed. And I found the order will be very random between runs.
Can the SQL statement generated from GORM keep consistent between runs?
Comment From: github-actions[bot]
This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days
Comment From: forderation
+1 i have same issue
Comment From: forderation
@jinzhu