Skip to content

Commit

Permalink
Merge pull request NoBrainerORM#284 from caspiano/fix/ensure-fix-tabl…
Browse files Browse the repository at this point in the history
…e-duplicate

Fix duplicate table create
  • Loading branch information
zedtux authored Mar 21, 2022
2 parents 78dd906 + 151b051 commit 1153e04
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/no_brainer/query_runner/table_on_demand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ def auto_create_table(env, db_name, table_name)
env[:last_auto_create_table] = [db_name, table_name]

create_options = model.table_create_options

NoBrainer.run(:db => db_name) do |r|
r.table_create(table_name, create_options.reject { |k,_| k.in? [:name, :write_acks] })
begin
NoBrainer.run(:db => db_name) do |r|
r.table_create(table_name, create_options.reject { |k,_| k.in? [:name, :write_acks] })
end
rescue RuntimeError => e
# We might have raced with another table create
raise unless e.message =~ /Table `#{db_name}\.#{table_name}` already exists/
end

# Prevent duplicate table errors on a cluster.
Expand All @@ -49,8 +53,5 @@ def auto_create_table(env, db_name, table_name)
r.table(table_name).config().update(:write_acks => create_options[:write_acks])
end
end
rescue RuntimeError => e
# We might have raced with another table create
raise unless e.message =~ /Table `#{db_name}\.#{table_name}` already exists/
end
end

0 comments on commit 1153e04

Please sign in to comment.