github.com/bishtawi/migrate/v4@v4.8.11/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) { // nolint: golint
    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.Sprint(sum), nil
    19  }