Skip to content

Commit

Permalink
Merge pull request #718 from SiaFoundation/chris/longer-object-id
Browse files Browse the repository at this point in the history
Extend object id max length
  • Loading branch information
ChrisSchinnerl committed Nov 7, 2023
2 parents 7a2b452 + 05a5507 commit 655c65c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions stores/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ func performMigrations(db *gorm.DB, logger *zap.SugaredLogger) error {
return performMigration00021_multipartUploadsBucketCascade(tx, logger)
},
},
{
ID: "00022_extendObjectID",
Migrate: func(tx *gorm.DB) error {
return performMigration00022_extendObjectID(tx, logger)
},
},
}
// Create migrator.
m := gormigrate.New(db, gormigrate.DefaultOptions, migrations)
Expand Down Expand Up @@ -303,15 +309,15 @@ func initSchema(tx *gorm.DB) error {

// Change the collation of columns that we need to be case sensitive.
if !isSQLite(tx) {
err = tx.Exec("ALTER TABLE objects MODIFY COLUMN object_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
err = tx.Exec("ALTER TABLE objects MODIFY COLUMN object_id VARCHAR(766) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
if err != nil {
return fmt.Errorf("failed to change object_id collation: %w", err)
}
err = tx.Exec("ALTER TABLE buckets MODIFY COLUMN name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
if err != nil {
return fmt.Errorf("failed to change buckets_name collation: %w", err)
}
err = tx.Exec("ALTER TABLE multipart_uploads MODIFY COLUMN object_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
err = tx.Exec("ALTER TABLE multipart_uploads MODIFY COLUMN object_id VARCHAR(766) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
if err != nil {
return fmt.Errorf("failed to change object_id collation: %w", err)
}
Expand Down Expand Up @@ -973,3 +979,19 @@ func performMigration00021_multipartUploadsBucketCascade(txn *gorm.DB, logger *z
logger.Info("migration 00021_multipoartUploadsBucketCascade complete")
return nil
}

func performMigration00022_extendObjectID(txn *gorm.DB, logger *zap.SugaredLogger) error {
logger.Info("performing migration 00022_extendObjectID")
if !isSQLite(txn) {
err := txn.Exec("ALTER TABLE objects MODIFY COLUMN object_id VARCHAR(766) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
if err != nil {
return fmt.Errorf("failed to change object_id collation: %w", err)
}
err = txn.Exec("ALTER TABLE multipart_uploads MODIFY COLUMN object_id VARCHAR(766) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;").Error
if err != nil {
return fmt.Errorf("failed to change object_id collation: %w", err)
}
}
logger.Info("migration 00022_extendObjectID complete")
return nil
}

0 comments on commit 655c65c

Please sign in to comment.