Skip to content

Commit

Permalink
take only sequences which have values
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Jun 22, 2024
1 parent 421e018 commit 0b51ad6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0b51ad6

Please sign in to comment.