@@ -17,7 +17,12 @@ use graph::{
1717} ;
1818use itertools:: Itertools ;
1919
20- use crate :: { catalog, copy:: AdaptiveBatchSize , deployment, relational:: Table } ;
20+ use crate :: {
21+ catalog,
22+ copy:: AdaptiveBatchSize ,
23+ deployment,
24+ relational:: { Table , VID_COLUMN } ,
25+ } ;
2126
2227use super :: { Catalog , Layout , Namespace } ;
2328
@@ -68,6 +73,7 @@ struct TablePair {
6873 // has the same name as `src` but is in a different namespace
6974 dst : Arc < Table > ,
7075 src_nsp : Namespace ,
76+ dst_nsp : Namespace ,
7177}
7278
7379impl TablePair {
@@ -94,7 +100,12 @@ impl TablePair {
94100 }
95101 conn. batch_execute ( & query) ?;
96102
97- Ok ( TablePair { src, dst, src_nsp } )
103+ Ok ( TablePair {
104+ src,
105+ dst,
106+ src_nsp,
107+ dst_nsp,
108+ } )
98109 }
99110
100111 /// Copy all entity versions visible between `earliest_block` and
@@ -228,6 +239,12 @@ impl TablePair {
228239 let src_qname = & self . src . qualified_name ;
229240 let dst_qname = & self . dst . qualified_name ;
230241 let src_nsp = & self . src_nsp ;
242+ let dst_nsp = & self . dst_nsp ;
243+
244+ let vid_seq = format ! ( "{}_{VID_COLUMN}_seq" , self . src. name) ;
245+
246+ let old_vid_form = !self . src . object . new_vid_form ( ) ;
247+
231248 let mut query = String :: new ( ) ;
232249
233250 // What we are about to do would get blocked by autovacuum on our
@@ -237,6 +254,15 @@ impl TablePair {
237254 "src" => src_nsp. as_str( ) , "error" => e. to_string( ) ) ;
238255 }
239256
257+ // Make sure the vid sequence
258+ // continues from where it was
259+ if old_vid_form {
260+ writeln ! (
261+ query,
262+ "select setval('{dst_nsp}.{vid_seq}', nextval('{src_nsp}.{vid_seq}'));"
263+ ) ?;
264+ }
265+
240266 writeln ! ( query, "drop table {src_qname};" ) ?;
241267 writeln ! ( query, "alter table {dst_qname} set schema {src_nsp}" ) ?;
242268 conn. transaction ( |conn| conn. batch_execute ( & query) ) ?;
0 commit comments