File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,29 @@ impl TestDatabase {
239
239
) ) ?;
240
240
crate :: db:: migrate ( None , & conn) ?;
241
241
242
+ // Move all sequence start positions 10000 apart to avoid overlapping primary keys
243
+ let query: String = conn
244
+ . query (
245
+ "
246
+ SELECT relname
247
+ FROM pg_class
248
+ INNER JOIN pg_namespace
249
+ ON pg_class.relnamespace = pg_namespace.oid
250
+ WHERE pg_class.relkind = 'S'
251
+ AND pg_namespace.nspname = $1
252
+ " ,
253
+ & [ & schema] ,
254
+ ) ?
255
+ . into_iter ( )
256
+ . map ( |row| row. get ( 0 ) )
257
+ . enumerate ( )
258
+ . map ( |( i, sequence) : ( _ , String ) | {
259
+ let offset = ( i + 1 ) * 10000 ;
260
+ format ! ( r#"ALTER SEQUENCE "{}" RESTART WITH {};"# , sequence, offset)
261
+ } )
262
+ . collect ( ) ;
263
+ conn. batch_execute ( & query) ?;
264
+
242
265
Ok ( TestDatabase {
243
266
pool : Pool :: new_with_schema ( config, & schema) ?,
244
267
schema,
You can’t perform that action at this time.
0 commit comments