Skip to content

Commit

Permalink
do not automatically delete legacy context files after migration, upd…
Browse files Browse the repository at this point in the history
…ate README.md accordingly
  • Loading branch information
Roxana Meixner committed Nov 21, 2022
1 parent 44cfcf6 commit 901d5c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -959,23 +959,24 @@ with the UBIRCH backend, could be the following:
## Legacy file-based context migration
In version 1 of the client, the context has been stored in files. In order to use a newer version, the context can be
migrated into a database.
Version 1 of the client used a file-based context management. In order to update the client from v1 to a newer version
(>v2) while keeping the existing context, the context can be migrated from the legacy context files into a database.
First, add the new mandatory [configurations](#Configuration) to your existing one.
If you want to use a postgreSQL database, the DSN has to be set in the configuration (json:`postgresDSN` /
env: `UBIRCH_POSTGRES_DSN`).
If no postgres DSN is set, the file-based context will be migrated to a SQLite DB in the mounted volume.
First, add the new mandatory [configurations](#Configuration) to your existing configuration.
To start the migration process, run the client with the command-line flag `--migrate`.
```shell
docker run -v $(pwd):/data --network host ubirch/ubirch-client:v2.x.x /data --migrate
```
After successful migration, the legacy context files will automatically be **deleted** and the process will exit with
status `0`. In case of failed migration, the exit status is set to `1`.
After successful migration, the process will exit with status `0`. In case of failed migration, the exit status is `1`.
Lastly, the legacy context files can be deleted.
```shell
rm -rf keys.json keys.json.bck signatures
```
## Quick Start
Expand Down
24 changes: 0 additions & 24 deletions main/adapters/repository/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"fmt"
"os"
"path/filepath"
"time"

"github.com/ubirch/ubirch-client-go/main/config"
Expand Down Expand Up @@ -69,7 +68,6 @@ func Migrate(c *config.Config, configDir string) error {

log.Infof("successfully migrated file-based context to database")

cleanUpLegacyFiles(configDir)
return nil
}

Expand Down Expand Up @@ -170,25 +168,3 @@ func migrateIdentities(c *config.Config, configDir string, p *ExtendedProtocol)

return tx.Commit()
}

func cleanUpLegacyFiles(configDir string) {
log.Infof("removing legacy context from file system")

keyFile := filepath.Join(configDir, keyFileName)
err := os.Remove(keyFile)
if err != nil {
log.Warnf("could not remove key file %s from file system: %v", keyFile, err)
}

keyFileBck := filepath.Join(configDir, keyFileName+".bck")
err = os.Remove(keyFileBck)
if err != nil && !os.IsNotExist(err) {
log.Warnf("could not remove key backup file %s from file system: %v", keyFileBck, err)
}

signatureDir := filepath.Join(configDir, signatureDirName)
err = os.RemoveAll(signatureDir)
if err != nil {
log.Warnf("could not remove signature directory %s from file system: %v", signatureDir, err)
}
}
16 changes: 8 additions & 8 deletions main/adapters/repository/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ func cleanUpMigrationTest(t *testing.T, c *config.Config, configDir string) {
_, err = os.Stat(filepath.Join(configDir, contextFileName_Legacy+".bck"))
assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", contextFileName_Legacy+".bck")

_, err = os.Stat(filepath.Join(configDir, keyFileName))
assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", keyFileName)

_, err = os.Stat(filepath.Join(configDir, keyFileName+".bck"))
assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", keyFileName+".bck")

_, err = os.Stat(filepath.Join(configDir, signatureDirName))
assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", signatureDirName)
//_, err = os.Stat(filepath.Join(configDir, keyFileName))
//assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", keyFileName)
//
//_, err = os.Stat(filepath.Join(configDir, keyFileName+".bck"))
//assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", keyFileName+".bck")
//
//_, err = os.Stat(filepath.Join(configDir, signatureDirName))
//assert.Truef(t, os.IsNotExist(err), "%s has not been cleaned up after migration", signatureDirName)

ctxManager, err := GetContextManager(c)
require.NoError(t, err)
Expand Down

0 comments on commit 901d5c5

Please sign in to comment.