Support restore operation

This commit is contained in:
WQY\qiong
2022-11-25 23:52:18 +08:00
parent e13bb53b98
commit 008cd2b3a2
7 changed files with 25 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ from .operation import ChangeSet
from .operation import get_current_operation from .operation import get_current_operation
from .operation import execute_undo, execute_redo from .operation import execute_undo, execute_redo
from .operation import have_snapshot, take_snapshot, pick_snapshot from .operation import have_snapshot, take_snapshot, pick_snapshot
from .operation import pick_operation, sync_with_server from .operation import pick_operation, sync_with_server, get_restore_operation
from .command import execute_batch_command, execute_batch_commands from .command import execute_batch_command, execute_batch_commands

View File

@@ -307,3 +307,7 @@ def sync_with_server(name: str, operation: int) -> ChangeSet:
index -= 1 index -= 1
return change.compress() return change.compress()
def get_restore_operation(name: str) -> int:
return read(name, f'select * from restore_operation')['id']

View File

@@ -221,7 +221,9 @@ def read_inp(project: str, inp: str):
create_project(project) create_project(project)
open_project(project) open_project(project)
execute_batch_command(project, _read_inp(inp)) execute_batch_commands(project, _read_inp(inp))
op = get_current_operation(project)
write(project, f'update restore_operation set id = {op}')
def dump_inp(project: str, inp: str): def dump_inp(project: str, inp: str):

View File

@@ -4,7 +4,7 @@ files = [
'bwsn', 'bwsn',
'exnet', 'exnet',
'fengxian', 'fengxian',
#'jbh', # too big sql to compress 'jbh',
'nanjing', 'nanjing',
'net3', 'net3',
'zj', 'zj',
@@ -19,7 +19,5 @@ def db2inp():
dump_inp(file, f'db_{file}.inp') dump_inp(file, f'db_{file}.inp')
if __name__ == '__main__': if __name__ == '__main__':
#inp2db() inp2db()
#db2inp() db2inp()
print(run_project('net3'))
pass

View File

@@ -1,6 +1,6 @@
create table operation create table operation
( (
id serial primary key id bigserial primary key
, redo text not null , redo text not null
, undo text not null , undo text not null
, parent integer references operation(id) on delete cascade , parent integer references operation(id) on delete cascade
@@ -13,13 +13,20 @@ insert into operation (id, redo, undo, redo_cs, undo_cs) values (0, '', '', '',
create table current_operation create table current_operation
( (
id integer primary key references operation(id) -- must update before delete id bigint primary key references operation(id) -- must update before delete
); );
insert into current_operation (id) values (0); insert into current_operation (id) values (0);
create table snapshot_operation create table snapshot_operation
( (
id integer primary key references operation(id) on delete cascade id bigint primary key references operation(id) on delete cascade
, tag text not null unique , tag text not null unique
); );
create table restore_operation
(
id bigint primary key references operation(id) -- set after reading inp
);
insert into restore_operation (id) values (0);

View File

@@ -1,4 +1,4 @@
drop table if exists transaction_operation; drop table if exists restore_operation;
drop table if exists snapshot_operation; drop table if exists snapshot_operation;

View File

@@ -179,6 +179,9 @@ def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet:
def execute_batch_commands(name: str, cs: ChangeSet) -> ChangeSet: def execute_batch_commands(name: str, cs: ChangeSet) -> ChangeSet:
return api.execute_batch_commands(name, cs) return api.execute_batch_commands(name, cs)
def get_restore_operation(name: str) -> int:
return api.get_restore_operation(name)
############################################################ ############################################################
# type # type