Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: sheet blob (#14405)

p0nyc5cc79c2d812
diff --git a/backend/migrator/migration/prod/3.1/0000##sheet_blob.sql b/backend/migrator/migration/prod/3.1/0000##sheet_blob.sql
index ca859dc9b0..f83df486c7 100644
--- a/backend/migrator/migration/prod/3.1/0000##sheet_blob.sql
+++ b/backend/migrator/migration/prod/3.1/0000##sheet_blob.sql
@@ -1,7 +1,8 @@
ALTER TABLE sheet ADD COLUMN IF NOT EXISTS sha256 BYTEA;
UPDATE sheet
-SET sha256 = sha256(convert_to(sheet.statement, 'utf8'));
+SET sha256 = sha256(convert_to(sheet.statement, 'utf8'))
+WHERE statement IS NOT NULL;
ALTER TABLE sheet ALTER COLUMN sha256 SET NOT NULL;
@@ -17,7 +18,8 @@ INSERT INTO sheet_blob (
sheet.sha256,
sheet.statement
FROM sheet
+WHERE sheet.statement IS NOT NULL
ON CONFLICT DO NOTHING;
-ALTER TABLE sheet DROP COLUMN IF EXISTS statement;
ALTER TABLE sheet DROP COLUMN IF EXISTS database_id;
+ALTER TABLE sheet ALTER COLUMN statement DROP NOT NULL;
diff --git a/backend/migrator/migrator.go b/backend/migrator/migrator.go
index 5cab643e50..161110c0ba 100644
--- a/backend/migrator/migrator.go
+++ b/backend/migrator/migrator.go
@@ -679,7 +679,7 @@ func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, s
func BeginMigration(ctx context.Context, stores *store.Store, m *dbdriver.MigrationInfo, prevSchema, statement string, sheetID *int) (string, error) {
// Phase 1 - Pre-check before executing migration
// Check if the same migration version has already been applied.
- if list, err := stores.ListInstanceChangeHistory(ctx, &store.FindInstanceChangeHistoryMessage{
+ if list, err := stores.ListInstanceChangeHistoryForMigrator(ctx, &store.FindInstanceChangeHistoryMessage{
InstanceID: m.InstanceID,
DatabaseID: m.DatabaseID,
Version: &m.Version,