Skip to content

Commit

Permalink
cherry pick migration commit and add name fix (#879)
Browse files Browse the repository at this point in the history
* feat: add database migrations up to 1.2.0 (#874)

including database migrations for 0.6.7 (None) -> 0.6.8, 0.6.8 -> 1.0.0, 1.0.0 -> 1.2.0

* fix: preserve name from 0.6.7 -> 0.6.8

* chore: remove unused db in 1.1.x releases
  • Loading branch information
kentbull authored Oct 24, 2024
1 parent 214a89d commit 1d1d76d
Show file tree
Hide file tree
Showing 14 changed files with 630 additions and 172 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
'mnemonic>=0.21',
'PrettyTable>=3.10.0',
'http_sfv>=0.9.9',
'cryptography>=42.0.5'
'cryptography>=42.0.5',
'semver>=3.0.2'
],
extras_require={
},
Expand Down
163 changes: 0 additions & 163 deletions src/keri/app/cli/commands/migrate.py

This file was deleted.

Empty file.
64 changes: 64 additions & 0 deletions src/keri/app/cli/commands/migrate/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- encoding: utf-8 -*-
"""
keri.kli.commands.migrate.list module
"""
import argparse
import logging

from keri import help
from hio.base import doing
from prettytable import PrettyTable

from keri.app.cli.common import existing

logger = help.ogler.getLogger()

def handler(args):
"""
List local LMDB database migrations and their completion status
Args:
args(Namespace): arguments object from command line
"""
lister = ListDoer(args)
return [lister]


parser = argparse.ArgumentParser(description='Lists the local LMDB migrations and their completion status')
parser.set_defaults(handler=handler,
transferable=True)

# Parameters for basic structure of database
parser.add_argument('--name', '-n', help='keystore name and file location of KERI keystore', required=True)
parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore',
required=False, default="")
parser.add_argument('--temp', '-t', help='create a temporary keystore, used for testing', default=False)

# Parameters for Manager creation
# passcode => bran
parser.add_argument('--passcode', '-p', help='21 character encryption passcode for keystore (is not saved)',
dest="bran", default=None)


class ListDoer(doing.Doer):

def __init__(self, args):
self.args = args
super(ListDoer, self).__init__()

def recur(self, tyme):
tab = PrettyTable()
tab.field_names = ["Num", "Name", "Date Completed"]
tab.align["Name"] = "l"

hby = existing.setupHby(name=self.args.name, base=self.args.base,
bran=self.args.bran if self.args.bran else None, temp=self.args.temp)

for idx, (name, dater) in enumerate(hby.db.complete()):
print(name, dater)
date = dater.datetime.strftime("%Y-%m-%d %H:%M") if dater is not None else "Not Run"
tab.add_row((f"{idx + 1}", f"{name}", date))

print(tab)
return True
67 changes: 67 additions & 0 deletions src/keri/app/cli/commands/migrate/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- encoding: utf-8 -*-
"""
keri.kli.commands.migrate.run module
"""
import argparse

from hio.base import doing

from keri import help
from keri import kering
from keri.db import basing

logger = help.ogler.getLogger("keri")

def handler(args):
"""
Launch KERI database migrator
Args:
args(Namespace): arguments object from command line
"""
migrator = MigrateDoer(args)
return [migrator]


parser = argparse.ArgumentParser(description='Migrates a database and keystore')
parser.set_defaults(handler=handler,
transferable=True)

# Parameters for basic structure of database
parser.add_argument('--name', '-n', help='keystore name and file location of KERI keystore', required=True)
parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore',
required=False, default="")
parser.add_argument('--temp', '-t', help='create a temporary keystore, used for testing', default=False)

# Parameters for Manager creation
# passcode => bran
parser.add_argument('--passcode', '-p', help='21 character encryption passcode for keystore (is not saved)',
dest="bran", default=None)


class MigrateDoer(doing.Doer):

def __init__(self, args):
self.args = args
super(MigrateDoer, self).__init__()

def recur(self, tyme):
name=self.args.name
base=self.args.base
temp=self.args.temp
hab_db = basing.Baser(name=name,
base=base,
temp=temp,
reopen=False)

try:
hab_db.reopen()
except kering.DatabaseError as ex:
pass

print(f"Migrating {name}...")
hab_db.migrate()
print(f"Finished migrating {name}")

return True
59 changes: 59 additions & 0 deletions src/keri/app/cli/commands/migrate/show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- encoding: utf-8 -*-
"""
keri.kli.commands module
"""
import argparse

from hio import help
from hio.base import doing

from keri.app.cli.common import existing

logger = help.ogler.getLogger()

def handler(args):
"""
Launch KERI database initialization
Args:
args(Namespace): arguments object from command line
"""
clean = CleanDoer(args)
return [clean]


parser = argparse.ArgumentParser(description='Cleans and migrates a database and keystore')
parser.set_defaults(handler=handler,
transferable=True)

# Parameters for basic structure of database
parser.add_argument('--name', '-n', help='keystore name and file location of KERI keystore', required=True)
parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore',
required=False, default="")
parser.add_argument('--temp', '-t', help='create a temporary keystore, used for testing', default=False)
parser.add_argument('--migration', '-m', help='migration name', required=True)


# Parameters for Manager creation
# passcode => bran
parser.add_argument('--passcode', '-p', help='21 character encryption passcode for keystore (is not saved)',
dest="bran", default=None)


class CleanDoer(doing.Doer):

def __init__(self, args):
self.args = args
super(CleanDoer, self).__init__()

def recur(self, tyme):
hby = existing.setupHby(name=self.args.name, base=self.args.base,
bran=self.args.bran, temp=self.args.temp)

[(name, dater)] = hby.db.complete(name=self.args.migration)
date = dater.datetime.strftime("%Y-%m-%d %H:%M") if dater is not None else "Not Run"

print(f"{self.args.migration} -> {date}")

return True
Loading

0 comments on commit 1d1d76d

Please sign in to comment.