@@ -243,9 +243,18 @@ func GetMigrationContext() *MigrationContext {
243
243
return context
244
244
}
245
245
246
+ func getSafeTableName (baseName string , suffix string ) string {
247
+ name := fmt .Sprintf ("_%s_%s" , baseName , suffix )
248
+ if len (name ) <= mysql .MaxTableNameLength {
249
+ return name
250
+ }
251
+ extraCharacters := len (name ) - mysql .MaxTableNameLength
252
+ return fmt .Sprintf ("_%s_%s" , baseName [0 :len (baseName )- extraCharacters ], suffix )
253
+ }
254
+
246
255
// GetGhostTableName generates the name of ghost table, based on original table name
247
256
func (this * MigrationContext ) GetGhostTableName () string {
248
- return fmt . Sprintf ( "_%s_gho" , this .OriginalTableName )
257
+ return getSafeTableName ( this .OriginalTableName , "gho" )
249
258
}
250
259
251
260
// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
@@ -255,14 +264,14 @@ func (this *MigrationContext) GetOldTableName() string {
255
264
timestamp := fmt .Sprintf ("%d%02d%02d%02d%02d%02d" ,
256
265
t .Year (), t .Month (), t .Day (),
257
266
t .Hour (), t .Minute (), t .Second ())
258
- return fmt .Sprintf ("_%s_% s_del" , this . OriginalTableName , timestamp )
267
+ return getSafeTableName ( this . OriginalTableName , fmt .Sprintf ("% s_del" , timestamp ) )
259
268
}
260
- return fmt . Sprintf ( "_%s_del" , this .OriginalTableName )
269
+ return getSafeTableName ( this .OriginalTableName , "del" )
261
270
}
262
271
263
272
// GetChangelogTableName generates the name of changelog table, based on original table name
264
273
func (this * MigrationContext ) GetChangelogTableName () string {
265
- return fmt . Sprintf ( "_%s_ghc" , this .OriginalTableName )
274
+ return getSafeTableName ( this .OriginalTableName , "ghc" )
266
275
}
267
276
268
277
// GetVoluntaryLockName returns a name of a voluntary lock to be used throughout
0 commit comments