func createDataDirIfNotExists(dataDir string) {
	if !server.FileExists(dataDir) {
		logger.Printf("%v doesn't exist, so creating it and creating data version file.", dataDir)
		server.Must(os.MkdirAll(dataDir, 0755))
		migrate.WriteDataVersion(dataDir)
	}
}
예제 #2
0
func Migrate(dataDir string) {
	if !server.FileExists(dataDir) {
		logger.Printf("Data directory '%v' doesn't appear to exist, so aborting migration.", dataDir)
		return
	}

	logger.Printf("Migrating data in %v to version %v", dataDir, DATA_VERSION)
	deployedDataVersion := readDataVersion(dataDir)
	if deployedDataVersion == DATA_VERSION {
		logger.Printf("Actually, data format was already up-to-date, so skipping migration.")
		return
	}

	migrateEntityGraph(dataDir, "person")
	migrateEntityGraph(dataDir, "org")
	migrateEntityGraph(dataDir, "place")

	server.Must(os.Remove(filepath.Join(dataDir, "personGraph.dat")))
	server.Must(os.Remove(filepath.Join(dataDir, "orgGraph.dat")))
	server.Must(os.Remove(filepath.Join(dataDir, "placeGraph.dat")))

	server.Must(os.Rename(filepath.Join(dataDir, "personGraph.dat.tmp"), filepath.Join(dataDir, "personGraph.dat")))
	server.Must(os.Rename(filepath.Join(dataDir, "orgGraph.dat.tmp"), filepath.Join(dataDir, "orgGraph.dat")))
	server.Must(os.Rename(filepath.Join(dataDir, "placeGraph.dat.tmp"), filepath.Join(dataDir, "placeGraph.dat")))

	WriteDataVersion(dataDir)

	logger.Printf("Data in %v successfully migrated to version %v", dataDir, DATA_VERSION)
}
예제 #3
0
func WriteDataVersion(dataDir string) {
	server.Must(ioutil.WriteFile(getVersionFilePath(dataDir), []byte(DATA_VERSION), 0644))
}