Skip to content

Commit

Permalink
fix: preserve name from 0.6.7 -> 0.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
kentbull committed Oct 14, 2024
1 parent 6ca16b2 commit 535b056
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 115 deletions.
6 changes: 3 additions & 3 deletions src/keri/app/cli/commands/migrate/list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
"""
keri.kli.commands module
keri.kli.commands.migrate.list module
"""
import argparse
Expand All @@ -16,7 +16,7 @@

def handler(args):
"""
Launch KERI database initialization
List local LMDB database migrations and their completion status
Args:
args(Namespace): arguments object from command line
Expand All @@ -25,7 +25,7 @@ def handler(args):
return [lister]


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

Expand Down
18 changes: 7 additions & 11 deletions src/keri/app/cli/commands/migrate/run.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
# -*- encoding: utf-8 -*-
"""
keri.kli.commands module
keri.kli.commands.migrate.run module
"""
import argparse
import logging

import keri
from keri import help
from hio.base import doing
from keri import kering

from keri.app.cli.common import existing
from keri import help
from keri import kering
from keri.db import basing
from keri.vdr import viring

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

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


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

Expand Down
16 changes: 9 additions & 7 deletions src/keri/db/basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@

MIGRATIONS = [
("0.6.8", ["hab_data_rename"]),
("1.0.0", ["add_key_and_reg_state_schemas"]),
("1.2.0", ["rekey_habs"])
("1.0.0", ["add_key_and_reg_state_schemas"])
]


Expand Down Expand Up @@ -1118,7 +1117,7 @@ def reload(self):
for keys in removes: # remove bare .habs records
self.nmsp.rem(keys=keys)

def migrate(self, name, base, temp):
def migrate(self):
""" Run all migrations required
Run all migrations that are required from the current version of database up to the current version
Expand All @@ -1132,7 +1131,7 @@ def migrate(self, name, base, temp):
# Only run migration if current source code version is at or below the migration version
ver = semver.VersionInfo.parse(keri.__version__)
ver_no_prerelease = semver.Version(ver.major, ver.minor, ver.patch)
if self.version is not None and semver.compare(version, ver_no_prerelease) > 0:
if self.version is not None and semver.compare(version, str(ver_no_prerelease)) > 0:
print(f"Skipping migration {version} as higher than the current KERI version {keri.__version__}")
continue
# Check to see if migration version is for an older database version
Expand All @@ -1153,6 +1152,8 @@ def migrate(self, name, base, temp):
return

self.migs.pin(keys=(migration,), val=coring.Dater())

# update database version after successful migration
self.version = version

self.version = keri.__version__
Expand All @@ -1174,7 +1175,7 @@ def current(self):
# If database version is ahead of library version, throw exception
ver = semver.VersionInfo.parse(keri.__version__)
ver_no_prerelease = semver.Version(ver.major, ver.minor, ver.patch)
if self.version is not None and semver.compare(self.version, ver_no_prerelease) == 1:
if self.version is not None and semver.compare(self.version, str(ver_no_prerelease)) == 1:
raise kering.ConfigurationError(
f"Database version={self.version} is ahead of library version={keri.__version__}")

Expand Down Expand Up @@ -1206,8 +1207,9 @@ def complete(self, name=None):
dater = self.migs.get(keys=(mig,))
migrations.append((mig, dater))
else:
if name not in MIGRATIONS or not self.migs.get(keys=(name,)):
raise ValueError(f"No migration named {name}")
for version, migs in MIGRATIONS: # check all migrations for each version
if name not in migs or not self.migs.get(keys=(name,)):
raise ValueError(f"No migration named {name}")
migrations.append((name, self.migs.get(keys=(name,))))

return migrations
Expand Down
6 changes: 3 additions & 3 deletions src/keri/db/migrations/hab_data_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def migrate(db):
sid=None,
watchers=habord_0_6_7.watchers
)
habords[habord_0_6_8.hid] = habord_0_6_8
habords[name] = habord_0_6_8

habs.trim() # remove existing records

# Add in the renamed records
for pre, habord in habords.items():
db.habs.pin(keys=(pre,), val=habord)
for name, habord in habords.items():
db.habs.pin(keys=(name,), val=habord)


91 changes: 0 additions & 91 deletions src/keri/db/migrations/rekey_habs.py

This file was deleted.

0 comments on commit 535b056

Please sign in to comment.