initprovider: check if the provider is already initialized

exit with code 0 if no initialization is required
This commit is contained in:
Nicola Murino
2020-08-30 13:50:43 +02:00
parent 2746c0b0f1
commit 600a107699
9 changed files with 22 additions and 15 deletions

View File

@@ -194,6 +194,10 @@ func (p SQLiteProvider) reloadConfig() error {
// initializeDatabase creates the initial database structure
func (p SQLiteProvider) initializeDatabase() error {
dbVersion, err := sqlCommonGetDatabaseVersion(p.dbHandle, false)
if err == nil && dbVersion.Version > 0 {
return ErrNoInitRequired
}
sqlUsers := strings.Replace(sqliteUsersTableSQL, "{{users}}", sqlTableUsers, 1)
tx, err := p.dbHandle.Begin()
if err != nil {
@@ -218,7 +222,7 @@ func (p SQLiteProvider) initializeDatabase() error {
}
func (p SQLiteProvider) migrateDatabase() error {
dbVersion, err := sqlCommonGetDatabaseVersion(p.dbHandle)
dbVersion, err := sqlCommonGetDatabaseVersion(p.dbHandle, true)
if err != nil {
return err
}