{ "(hooks)": { "(hooks)#0": [ {"sql":"create table lines (id integer generated always as identity primary key, folder_id integer not null, position integer not null, body text not null,\n unique (folder_id, position)); create index on lines (folder_id, position); create index on lines (position);","result":[{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]}]} ] }, "the batch move > saves while the moved record and the records it passes were edited since, and writes only what changes": { "(hooks)#0": [ {"sql":"truncate lines restart identity;\n insert into lines (folder_id, position, body) values (1, 1, 'a'), (1, 2, 'b'), (1, 3, 'c'), (1, 4, 'd'), (2, 1, 'x');","result":[{"command":"TRUNCATE","rowCount":null,"columns":[],"rows":[]},{"command":"INSERT","rowCount":5,"columns":[],"rows":[]}]}, {"sql":"update lines set body = upper(body) where id in (2, 4)","result":{"command":"UPDATE","rowCount":2,"columns":[],"rows":[]}}, {"sql":"select relkind from pg_class where oid = to_regclass($1)","params":["\"lines\""],"result":{"command":"SELECT","rowCount":1,"columns":[["relkind",18]],"rows":[["r"]]}}, {"sql":"\n select ic.relname as name, am.amname as method, (i.indpred is not null) as partial, a.attname::text as column,\n pg_get_indexdef(i.indexrelid, k.ord::int, true) as definition, oc.opcname::text as opclass\n from pg_index i\n join pg_class ic on ic.oid = i.indexrelid\n join pg_am am on am.oid = ic.relam\n cross join lateral unnest(i.indkey::int2[], i.indclass::oid[]) with ordinality k(attnum, opclass, ord)\n left join pg_attribute a on a.attrelid = i.indrelid and a.attnum = k.attnum and k.attnum > 0\n join pg_opclass oc on oc.oid = k.opclass\n where i.indrelid = to_regclass($1) and i.indisvalid and i.indisready and k.ord <= i.indnkeyatts\n order by ic.relname, k.ord\n ","params":["\"lines\""],"result":{"command":"SELECT","rowCount":6,"columns":[["name",19],["method",19],["partial",16],["column",25],["definition",25],["opclass",25]],"rows":[ ["lines_folder_id_position_idx","btree","f","folder_id","folder_id","int4_ops"], ["lines_folder_id_position_idx","btree","f","position","\"position\"","int4_ops"], ["lines_folder_id_position_key","btree","f","folder_id","folder_id","int4_ops"], ["lines_folder_id_position_key","btree","f","position","\"position\"","int4_ops"], ["lines_pkey","btree","f","id","id","int4_ops"], ["lines_position_idx","btree","f","position","\"position\"","int4_ops"] ]}}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select set_config($1, $2, true), pg_logical_emit_message(true, $3, $4::text) is not null","params":["statement_timeout","1000","protobase_actor","{\"id\":\"tester\",\"roles\":[\"admin\"]}"],"result":{"command":"SELECT","rowCount":1,"columns":[["set_config",25],["?column?",16]],"rows":[["1s","t"]]}}, {"sql":"select pg_advisory_xact_lock(hashtextextended($1, 0))","params":["move:.lines.position"],"result":{"command":"SELECT","rowCount":1,"columns":[["pg_advisory_xact_lock",2278]],"rows":[[""]]}}, {"sql":"select \"t\".\"id\" as \"id\", \"t\".\"position\" as \"position\", \"t\".\"position\"::text as \"__pb_key0\", \"t\".\"id\"::text as \"__pb_key1\" from \"lines\" as \"t\" where \"t\".\"folder_id\" = $1 order by \"t\".\"position\" asc, \"t\".\"id\" asc limit $2","params":["1","501"],"result":{"command":"SELECT","rowCount":4,"columns":[["id",23],["position",23],["__pb_key0",25],["__pb_key1",25]],"rows":[ ["1","1","1","1"], ["2","2","2","2"], ["3","3","3","3"], ["4","4","4","4"] ]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["4"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","4","D"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["2"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","2","B"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["3"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["3","1","3","c"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["4"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","4","D"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["2"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","2","B"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["3"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["3","1","3","c"]]}}, {"sql":"select max(\"position\") as high, min(\"position\") as low from \"lines\" as t","result":{"command":"SELECT","rowCount":1,"columns":[["high",23],["low",23]],"rows":[["4","1"]]}}, {"sql":"savepoint reorder_aside","result":{"command":"SAVEPOINT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"lines\" as t set \"position\" = $1::bigint + $2::bigint * (case when (\"id\") = ($3) then $4::bigint when (\"id\") = ($5) then $6::bigint when (\"id\") = ($7) then $8::bigint end) where (\"id\") in (($9), ($10), ($11))","params":["5","1","4","0","2","1","3","2","4","2","3"],"result":{"command":"UPDATE","rowCount":3,"columns":[],"rows":[]}}, {"sql":"release savepoint reorder_aside","result":{"command":"RELEASE","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["2","4"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","2","D"]]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["3","2"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","3","B"]]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["4","3"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["3","1","4","c"]]}}, {"sql":"commit","result":{"command":"COMMIT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select body from lines where folder_id = 1 order by position","result":{"command":"SELECT","rowCount":4,"columns":[["body",25]],"rows":[ ["a"], ["D"], ["B"], ["c"] ]}}, {"sql":"select position from lines where folder_id = 2","result":{"command":"SELECT","rowCount":1,"columns":[["position",23]],"rows":[["1"]]}} ] }, "the batch move > saves while records were added or removed elsewhere in the list": { "(hooks)#0": [ {"sql":"truncate lines restart identity;\n insert into lines (folder_id, position, body) values (1, 1, 'a'), (1, 2, 'b'), (1, 3, 'c'), (1, 4, 'd'), (2, 1, 'x');","result":[{"command":"TRUNCATE","rowCount":null,"columns":[],"rows":[]},{"command":"INSERT","rowCount":5,"columns":[],"rows":[]}]}, {"sql":"delete from lines where id = 3; insert into lines (folder_id, position, body) values (1, 9, 'e')","result":[{"command":"DELETE","rowCount":1,"columns":[],"rows":[]},{"command":"INSERT","rowCount":1,"columns":[],"rows":[]}]}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select set_config($1, $2, true), pg_logical_emit_message(true, $3, $4::text) is not null","params":["statement_timeout","1000","protobase_actor","{\"id\":\"tester\",\"roles\":[\"admin\"]}"],"result":{"command":"SELECT","rowCount":1,"columns":[["set_config",25],["?column?",16]],"rows":[["1s","t"]]}}, {"sql":"select pg_advisory_xact_lock(hashtextextended($1, 0))","params":["move:.lines.position"],"result":{"command":"SELECT","rowCount":1,"columns":[["pg_advisory_xact_lock",2278]],"rows":[[""]]}}, {"sql":"select \"t\".\"id\" as \"id\", \"t\".\"position\" as \"position\", \"t\".\"position\"::text as \"__pb_key0\", \"t\".\"id\"::text as \"__pb_key1\" from \"lines\" as \"t\" where \"t\".\"folder_id\" = $1 order by \"t\".\"position\" asc, \"t\".\"id\" asc limit $2","params":["1","501"],"result":{"command":"SELECT","rowCount":4,"columns":[["id",23],["position",23],["__pb_key0",25],["__pb_key1",25]],"rows":[ ["1","1","1","1"], ["2","2","2","2"], ["4","4","4","4"], ["6","9","9","6"] ]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["2"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","2","b"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["4"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","4","d"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["1"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["1","1","1","a"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["2"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","2","b"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["4"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","4","d"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["1"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["1","1","1","a"]]}}, {"sql":"select max(\"position\") as high, min(\"position\") as low from \"lines\" as t","result":{"command":"SELECT","rowCount":1,"columns":[["high",23],["low",23]],"rows":[["9","1"]]}}, {"sql":"savepoint reorder_aside","result":{"command":"SAVEPOINT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"lines\" as t set \"position\" = $1::bigint + $2::bigint * (case when (\"id\") = ($3) then $4::bigint when (\"id\") = ($5) then $6::bigint when (\"id\") = ($7) then $8::bigint end) where (\"id\") in (($9), ($10), ($11))","params":["10","1","2","0","4","1","1","2","2","4","1"],"result":{"command":"UPDATE","rowCount":3,"columns":[],"rows":[]}}, {"sql":"release savepoint reorder_aside","result":{"command":"RELEASE","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["1","2"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","1","b"]]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["2","4"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","2","d"]]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["3","1"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["1","1","3","a"]]}}, {"sql":"commit","result":{"command":"COMMIT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select body from lines where folder_id = 1 order by position","result":{"command":"SELECT","rowCount":4,"columns":[["body",25]],"rows":[ ["b"], ["d"], ["a"], ["e"] ]}} ] }, "the batch move > is refused with 412 when another record now follows the anchor, and writes nothing": { "(hooks)#0": [ {"sql":"truncate lines restart identity;\n insert into lines (folder_id, position, body) values (1, 1, 'a'), (1, 2, 'b'), (1, 3, 'c'), (1, 4, 'd'), (2, 1, 'x');","result":[{"command":"TRUNCATE","rowCount":null,"columns":[],"rows":[]},{"command":"INSERT","rowCount":5,"columns":[],"rows":[]}]}, {"sql":"update lines set position = 0 where id = 3; update lines set position = 3 where id = 2; update lines set position = 2 where id = 3","result":[{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]},{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]},{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}]}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select set_config($1, $2, true), pg_logical_emit_message(true, $3, $4::text) is not null","params":["statement_timeout","1000","protobase_actor","{\"id\":\"tester\",\"roles\":[\"admin\"]}"],"result":{"command":"SELECT","rowCount":1,"columns":[["set_config",25],["?column?",16]],"rows":[["1s","t"]]}}, {"sql":"select pg_advisory_xact_lock(hashtextextended($1, 0))","params":["move:.lines.position"],"result":{"command":"SELECT","rowCount":1,"columns":[["pg_advisory_xact_lock",2278]],"rows":[[""]]}}, {"sql":"select \"t\".\"id\" as \"id\", \"t\".\"position\" as \"position\", \"t\".\"position\"::text as \"__pb_key0\", \"t\".\"id\"::text as \"__pb_key1\" from \"lines\" as \"t\" where \"t\".\"folder_id\" = $1 order by \"t\".\"position\" asc, \"t\".\"id\" asc limit $2","params":["1","501"],"result":{"command":"SELECT","rowCount":4,"columns":[["id",23],["position",23],["__pb_key0",25],["__pb_key1",25]],"rows":[ ["1","1","1","1"], ["3","2","2","3"], ["2","3","3","2"], ["4","4","4","4"] ]}}, {"sql":"rollback","result":{"command":"ROLLBACK","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select body from lines where folder_id = 1 order by position","result":{"command":"SELECT","rowCount":4,"columns":[["body",25]],"rows":[ ["a"], ["c"], ["b"], ["d"] ]}}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select set_config($1, $2, true), pg_logical_emit_message(true, $3, $4::text) is not null","params":["statement_timeout","1000","protobase_actor","{\"id\":\"tester\",\"roles\":[\"admin\"]}"],"result":{"command":"SELECT","rowCount":1,"columns":[["set_config",25],["?column?",16]],"rows":[["1s","t"]]}}, {"sql":"select pg_advisory_xact_lock(hashtextextended($1, 0))","params":["move:.lines.position"],"result":{"command":"SELECT","rowCount":1,"columns":[["pg_advisory_xact_lock",2278]],"rows":[[""]]}}, {"sql":"select \"t\".\"id\" as \"id\", \"t\".\"position\" as \"position\", \"t\".\"position\"::text as \"__pb_key0\", \"t\".\"id\"::text as \"__pb_key1\" from \"lines\" as \"t\" where \"t\".\"folder_id\" = $1 order by \"t\".\"position\" asc, \"t\".\"id\" asc limit $2","params":["1","501"],"result":{"command":"SELECT","rowCount":4,"columns":[["id",23],["position",23],["__pb_key0",25],["__pb_key1",25]],"rows":[ ["1","1","1","1"], ["3","2","2","3"], ["2","3","3","2"], ["4","4","4","4"] ]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["4"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","4","d"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["3"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["3","1","2","c"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["2"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","3","b"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["4"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","4","d"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["3"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["3","1","2","c"]]}}, {"sql":"select \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\" from \"lines\" as t where \"id\" = $1 limit 1 for update","params":["2"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","3","b"]]}}, {"sql":"select max(\"position\") as high, min(\"position\") as low from \"lines\" as t","result":{"command":"SELECT","rowCount":1,"columns":[["high",23],["low",23]],"rows":[["4","1"]]}}, {"sql":"savepoint reorder_aside","result":{"command":"SAVEPOINT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"lines\" as t set \"position\" = $1::bigint + $2::bigint * (case when (\"id\") = ($3) then $4::bigint when (\"id\") = ($5) then $6::bigint when (\"id\") = ($7) then $8::bigint end) where (\"id\") in (($9), ($10), ($11))","params":["5","1","4","0","3","1","2","2","4","3","2"],"result":{"command":"UPDATE","rowCount":3,"columns":[],"rows":[]}}, {"sql":"release savepoint reorder_aside","result":{"command":"RELEASE","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["2","4"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["4","1","2","d"]]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["3","3"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["3","1","3","c"]]}}, {"sql":"update \"lines\" as t set \"position\" = $1 where \"id\" = $2 returning \"id\" as \"id\", \"folder_id\" as \"folderId\", \"position\" as \"position\", \"body\" as \"body\"","params":["4","2"],"result":{"command":"UPDATE","rowCount":1,"columns":[["id",23],["folderId",23],["position",23],["body",25]],"rows":[["2","1","4","b"]]}}, {"sql":"commit","result":{"command":"COMMIT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select body from lines where folder_id = 1 order by position","result":{"command":"SELECT","rowCount":4,"columns":[["body",25]],"rows":[ ["a"], ["d"], ["c"], ["b"] ]}} ] } }