Skip to content

Commit 328e5de

Browse files
Added restart flag
1 parent c421b2f commit 328e5de

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

mytonctrl/migrate.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ def migrate_to_version_1(local: MyPyClass, ton: MyTonCore):
2222

2323

2424
def migrate(version: 0, local: MyPyClass, ton: MyTonCore):
25+
restart = False
2526
if version < 1:
2627
local.add_log(f'Running migration {version} -> 1', 'info')
27-
migrate_to_version_1(local, ton)
28-
return 1
28+
restart_required = migrate_to_version_1(local, ton)
29+
restart = restart or restart_required
30+
return 1, restart
2931

3032

3133
def run_migrations(local: Optional[MyPyClass]=None, ton: Optional[MyTonCore]=None):
@@ -34,20 +36,18 @@ def run_migrations(local: Optional[MyPyClass]=None, ton: Optional[MyTonCore]=Non
3436
if ton is None:
3537
ton = MyTonCore(MyPyClass('mytoncore.py'))
3638

37-
# migrations
38-
local.add_log('Running MyTonCtrl migrations', 'info')
39+
# migrations
40+
version = 0
3941

4042
workdir = local.buffer.my_work_dir
41-
local.add_log(f"Workdir: {workdir}", 'info')
42-
43-
version = 0
4443
version_file_path = os.path.join(workdir, 'VERSION')
4544
if os.path.exists(version_file_path):
4645
with open(version_file_path, 'r') as f:
4746
version = int(f.read())
48-
local.add_log(f'Current version: {version}', 'info')
4947

50-
new_version = migrate(version, local, ton)
48+
new_version, restart = migrate(version, local, ton)
49+
5150
with open(version_file_path, 'w') as f:
5251
f.write(f'{new_version}')
52+
return restart
5353
#end define

mytonctrl/mytonctrl.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ def inject_globals(func):
168168
def PreUp(local, ton):
169169
CheckMytonctrlUpdate(local)
170170
check_vport(local, ton)
171-
172-
run_migrations(local, ton)
173171
# CheckTonUpdate()
174172
#end define
175173

@@ -1420,6 +1418,10 @@ def mytonctrl():
14201418
ton = MyTonCore(mytoncore_local)
14211419
console = MyPyConsole()
14221420

1423-
Init(local, ton, console, sys.argv[1:])
1424-
console.Run()
1421+
# migrations
1422+
restart = run_migrations(local, ton)
1423+
1424+
if not restart:
1425+
Init(local, ton, console, sys.argv[1:])
1426+
console.Run()
14251427
#end define

0 commit comments

Comments
 (0)