github.com/matcornic/migrate@v3.3.2-0.20180717234201-feea45c20506+incompatible/database/util.go (about)

     1  package database
     2  
     3  import (
     4  	"fmt"
     5  	"hash/crc32"
     6  )
     7  
     8  const advisoryLockIdSalt uint = 1486364155
     9  
    10  // inspired by rails migrations, see https://goo.gl/8o9bCT
    11  func GenerateAdvisoryLockId(databaseName string) (string, error) {
    12  	sum := crc32.ChecksumIEEE([]byte(databaseName))
    13  	sum = sum * uint32(advisoryLockIdSalt)
    14  	return fmt.Sprintf("%v", sum), nil
    15  }