about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-08-20 05:23:45 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:19 -0500
commit687e8d519407f502c3e62c83219e7ad26304e11c (patch)
treea819ce595a2e09944ffcf3ebdb41d4cdd89496b2 /lib
parentf0c2dcf6175c1aff5e6a21364c21acff71b5df8d (diff)
[Database, Revision] Use CREATE SEQUENCE IF NOT EXISTS instead of exception
Diffstat (limited to 'lib')
-rw-r--r--lib/mastodon/snowflake.rb13
1 files changed, 1 insertions, 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