diff options
Diffstat (limited to 'lib/gitlab/database/schema_helpers.rb')
-rw-r--r-- | lib/gitlab/database/schema_helpers.rb | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/gitlab/database/schema_helpers.rb b/lib/gitlab/database/schema_helpers.rb index f8d01c78ae8..8e544307d81 100644 --- a/lib/gitlab/database/schema_helpers.rb +++ b/lib/gitlab/database/schema_helpers.rb @@ -16,12 +16,12 @@ module Gitlab SQL end - def create_function_trigger(name, fn_name, fires: nil) + def create_trigger(name, function_name, fires: nil) execute(<<~SQL) CREATE TRIGGER #{name} #{fires} FOR EACH ROW - EXECUTE PROCEDURE #{fn_name}() + EXECUTE PROCEDURE #{function_name}() SQL end @@ -35,6 +35,16 @@ module Gitlab execute("DROP TRIGGER #{exists_clause} #{name} ON #{table_name}") end + def create_comment(type, name, text) + execute("COMMENT ON #{type} #{name} IS '#{text}'") + end + + def tmp_table_name(base) + hashed_base = Digest::SHA256.hexdigest(base).first(10) + + "#{base}_#{hashed_base}" + end + def object_name(table, type) identifier = "#{table}_#{type}" hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10) @@ -42,8 +52,30 @@ module Gitlab "#{type}_#{hashed_identifier}" end + def with_lock_retries(&block) + Gitlab::Database::WithLockRetries.new({ + klass: self.class, + logger: Gitlab::BackgroundMigration::Logger + }).run(&block) + end + + def assert_not_in_transaction_block(scope:) + return unless transaction_open? + + raise "#{scope} operations can not be run inside a transaction block, " \ + "you can disable transaction blocks by calling disable_ddl_transaction! " \ + "in the body of your migration class" + end + private + def create_range_partition(partition_name, table_name, lower_bound, upper_bound) + execute(<<~SQL) + CREATE TABLE #{partition_name} PARTITION OF #{table_name} + FOR VALUES FROM (#{lower_bound}) TO (#{upper_bound}) + SQL + end + def optional_clause(flag, clause) flag ? clause : "" end |