@@ -243,9 +243,18 @@ func GetMigrationContext() *MigrationContext {
243243 return context
244244}
245245
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+
246255// GetGhostTableName generates the name of ghost table, based on original table name
247256func (this * MigrationContext ) GetGhostTableName () string {
248- return fmt . Sprintf ( "_%s_gho" , this .OriginalTableName )
257+ return getSafeTableName ( this .OriginalTableName , "gho" )
249258}
250259
251260// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
@@ -255,14 +264,14 @@ func (this *MigrationContext) GetOldTableName() string {
255264 timestamp := fmt .Sprintf ("%d%02d%02d%02d%02d%02d" ,
256265 t .Year (), t .Month (), t .Day (),
257266 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 ) )
259268 }
260- return fmt . Sprintf ( "_%s_del" , this .OriginalTableName )
269+ return getSafeTableName ( this .OriginalTableName , "del" )
261270}
262271
263272// GetChangelogTableName generates the name of changelog table, based on original table name
264273func (this * MigrationContext ) GetChangelogTableName () string {
265- return fmt . Sprintf ( "_%s_ghc" , this .OriginalTableName )
274+ return getSafeTableName ( this .OriginalTableName , "ghc" )
266275}
267276
268277// GetVoluntaryLockName returns a name of a voluntary lock to be used throughout
0 commit comments