From 687e8d519407f502c3e62c83219e7ad26304e11c Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Thu, 20 Aug 2020 05:23:45 -0500 Subject: [Database, Revision] Use CREATE SEQUENCE IF NOT EXISTS instead of exception --- lib/mastodon/snowflake.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/mastodon/snowflake.rb b/lib/mastodon/snowflake.rb index 9e5bc7383..10ed51f0c 100644 --- a/lib/mastodon/snowflake.rb +++ b/lib/mastodon/snowflake.rb @@ -120,21 +120,10 @@ module Mastodon::Snowflake seq_name = data[:seq_prefix] + '_id_seq' - # If we were on Postgres 9.5+, we could do CREATE SEQUENCE IF - # NOT EXISTS, but we can't depend on that. Instead, catch the - # possible exception and ignore it. # Note that seq_name isn't a column name, but it's a # relation, like a column, and follows the same quoting rules # in Postgres. - connection.execute(<<~SQL) - DO $$ - BEGIN - CREATE SEQUENCE #{connection.quote_column_name(seq_name)}; - EXCEPTION WHEN duplicate_table THEN - -- Do nothing, we have the sequence already. - END - $$ LANGUAGE plpgsql; - SQL + connection.execute("CREATE SEQUENCE IF NOT EXISTS #{connection.quote_column_name(seq_name)};") end end -- cgit