github.com/mrqzzz/migrate@v5.1.7+incompatible/database/util.go (about) 1 package database 2 3 import ( 4 "fmt" 5 "hash/crc32" 6 "strings" 7 ) 8 9 const advisoryLockIdSalt uint = 1486364155 10 11 // GenerateAdvisoryLockId inspired by rails migrations, see https://goo.gl/8o9bCT 12 func GenerateAdvisoryLockId(databaseName string, additionalNames ...string) (string, error) { 13 if len(additionalNames) > 0 { 14 databaseName = strings.Join(append(additionalNames, databaseName), "\x00") 15 } 16 sum := crc32.ChecksumIEEE([]byte(databaseName)) 17 sum = sum * uint32(advisoryLockIdSalt) 18 return fmt.Sprintf("%v", sum), nil 19 }