Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ar_mysql_jsonb_support.rb « initializers « config - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 63a0b05119a17ec55da36e3a6d3388c6ad27c6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require 'active_record/connection_adapters/abstract_mysql_adapter'
require 'active_record/connection_adapters/mysql/schema_definitions'

# MySQL (5.6) and MariaDB (10.1) are currently supported versions within GitLab,
# Since they do not support native `json` datatype we force to emulate it as `text`

if Gitlab::Database.mysql?
  module ActiveRecord
    module ConnectionAdapters
      class AbstractMysqlAdapter
        JSON_DATASIZE = 1.megabyte

        NATIVE_DATABASE_TYPES.merge!(
          json: { name: "text", limit: JSON_DATASIZE },
          jsonb: { name: "text", limit: JSON_DATASIZE }
        )
      end

      module MySQL
        module ColumnMethods
          # We add `jsonb` helper, as `json` is already defined for `MySQL` since Rails 5
          def jsonb(*args, **options)
            args.each { |name| column(name, :json, options) }
          end
        end
      end
    end
  end
end