func Initialize(databasePath string) error {
	dbPath = databasePath

	if err := getDatabaseSchemaVersion(); err != nil {
		return fmt.Errorf("error getting database schema version: %v", err)
	}

	if databaseSchemaVersion == 0 {
		// new database, just run the migrations
		if err := RunMigrations(); err != nil {
			return fmt.Errorf("error running initial schema migrations: %v", err)
		}
		// RunMigrations calls Initialise. Just return
		return nil
	} else {
		if databaseSchemaVersion > appSchemaVersion {
			panic(fmt.Sprintf("Database schema version %d is incompatible with required schema version %d", databaseSchemaVersion, appSchemaVersion))
		}

		// if migration is needed, then don't open the connection
		if NeedsMigration() {
			logger.Warnf("Database schema version %d does not match required schema version %d.", databaseSchemaVersion, appSchemaVersion)
			return nil
		}
	}

	const disableForeignKeys = false
	DB = open(databasePath, disableForeignKeys)

	if err := runCustomMigrations(); err != nil {
		return err
	}

	return nil
}
// Initialize initializes the database. If the database is new, then it
// performs a full migration to the latest schema version. Otherwise, any
// necessary migrations must be run separately using RunMigrations.
// Returns true if the database is new.
Initialize initializes the database. If the database is new, then it
performs a full migration to the latest schema version. Otherwise, any
necessary migrations must be run separately using RunMigrations.
Returns true if the database is new.
// Initialize initializes the database . If the database is new then it // performs a full migration to the latest schema version . Otherwise any // necessary migrations must be run separately using RunMigrations . // Returns true if the database is new .
func Initialize(databasePath string) error {
	dbPath = databasePath
	if err := getDatabaseSchemaVersion(); err != nil {
		return fmt.Errorf("error getting database schema version: %v", err)
	}
	if databaseSchemaVersion == 0 {
		if err := RunMigrations(); err != nil {
			return fmt.Errorf("error running initial schema migrations: %v", err)
		}
		return nil
	} else {
		if databaseSchemaVersion > appSchemaVersion {
			panic(fmt.Sprintf("Database schema version %d is incompatible with required schema version %d", databaseSchemaVersion, appSchemaVersion))
		}
		if NeedsMigration() {
			logger.Warnf("Database schema version %d does not match required schema version %d.", databaseSchemaVersion, appSchemaVersion)
			return nil
		}
	}
	const disableForeignKeys = false
	DB = open(databasePath, disableForeignKeys)
	if err := runCustomMigrations(); err != nil {
		return err
	}
	return nil
}
func Initialize ( databasePath string ) error { dbPath = databasePath if err := getDatabaseSchemaVersion ( ) ; err != nil { return fmt . Errorf ( " " , err ) } if databaseSchemaVersion == 0 { if err := RunMigrations ( ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil } else { if databaseSchemaVersion > appSchemaVersion { panic ( fmt . Sprintf ( " " , databaseSchemaVersion , appSchemaVersion ) ) } if NeedsMigration ( ) { logger . Warnf ( " " , databaseSchemaVersion , appSchemaVersion ) return nil } } const disableForeignKeys = false DB = open ( databasePath , disableForeignKeys ) if err := runCustomMigrations ( ) ; err != nil { return err } return nil }
Initialize initializes the database.
Initialize initializes the database .
// new database, just run the migrations // RunMigrations calls Initialise. Just return // if migration is needed, then don't open the connection