From 0b51ad6081be06bf8869b949aa5aa5d7fbe32d9a Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Fri, 21 Jun 2024 22:13:50 +0400 Subject: [PATCH] take only sequences which have values --- model/lantern/lantern_resource.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/model/lantern/lantern_resource.rb b/model/lantern/lantern_resource.rb index 8aff07c22..c6fc64df6 100644 --- a/model/lantern/lantern_resource.rb +++ b/model/lantern/lantern_resource.rb @@ -150,15 +150,16 @@ def create_publication(name) def sync_sequences_with_parent representative_server.list_all_databases.each do |db| - res = parent.representative_server.run_query("SELECT sequence_schema, sequence_name, last_value + res = parent.representative_server.run_query(" + SELECT sequence_schema, sequence_name, last_value FROM information_schema.sequences JOIN pg_sequences ON (information_schema.sequences.sequence_schema = pg_sequences.schemaname - AND information_schema.sequences.sequence_name = pg_sequences.sequencename);", db: db) + AND information_schema.sequences.sequence_name = pg_sequences.sequencename) + WHERE last_value > 0;", db: db) statements = res.chomp.strip.split("\n").map do |row| values = row.split(",") - {schema: values[0], sequence: values[1], last_value: values[2]} "SELECT setval('#{values[0]}.#{values[1]}', #{values[2]});" end