diff --git a/api/__init__.py b/api/__init__.py index 39de2f4..68ff11a 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -9,7 +9,7 @@ from .operation import ChangeSet from .operation import get_current_operation from .operation import execute_undo, execute_redo 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 diff --git a/api/operation.py b/api/operation.py index b2f6ca1..44cf20e 100644 --- a/api/operation.py +++ b/api/operation.py @@ -307,3 +307,7 @@ def sync_with_server(name: str, operation: int) -> ChangeSet: index -= 1 return change.compress() + + +def get_restore_operation(name: str) -> int: + return read(name, f'select * from restore_operation')['id'] diff --git a/api/parser.py b/api/parser.py index bca8470..f3835f5 100644 --- a/api/parser.py +++ b/api/parser.py @@ -221,7 +221,9 @@ def read_inp(project: str, inp: str): create_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): diff --git a/build_db.py b/build_db.py index 550a692..997f096 100644 --- a/build_db.py +++ b/build_db.py @@ -4,7 +4,7 @@ files = [ 'bwsn', 'exnet', 'fengxian', - #'jbh', # too big sql to compress + 'jbh', 'nanjing', 'net3', 'zj', @@ -19,7 +19,5 @@ def db2inp(): dump_inp(file, f'db_{file}.inp') if __name__ == '__main__': - #inp2db() - #db2inp() - print(run_project('net3')) - pass \ No newline at end of file + inp2db() + db2inp() diff --git a/script/sql/create/operation.sql b/script/sql/create/operation.sql index 05320e2..dc4f220 100644 --- a/script/sql/create/operation.sql +++ b/script/sql/create/operation.sql @@ -1,6 +1,6 @@ create table operation ( - id serial primary key + id bigserial primary key , redo text not null , undo text not null , 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 ( - 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); 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 ); + +create table restore_operation +( + id bigint primary key references operation(id) -- set after reading inp +); + +insert into restore_operation (id) values (0); diff --git a/script/sql/drop/operation.sql b/script/sql/drop/operation.sql index 344215a..06a7765 100644 --- a/script/sql/drop/operation.sql +++ b/script/sql/drop/operation.sql @@ -1,4 +1,4 @@ -drop table if exists transaction_operation; +drop table if exists restore_operation; drop table if exists snapshot_operation; diff --git a/tjnetwork.py b/tjnetwork.py index 91c4dc9..f5bc86c 100644 --- a/tjnetwork.py +++ b/tjnetwork.py @@ -179,6 +179,9 @@ def execute_batch_command(name: str, cs: ChangeSet) -> ChangeSet: def execute_batch_commands(name: str, cs: ChangeSet) -> ChangeSet: return api.execute_batch_commands(name, cs) +def get_restore_operation(name: str) -> int: + return api.get_restore_operation(name) + ############################################################ # type