diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 160e76631fed4eee9b3db9e41d0adf244f2090a8..b62b0c79da0fb93538078a72e804933f28dbf5bb 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -630,7 +630,7 @@ def self.kroki_formats_attributes :users_get_by_id_limit end - attribute :resource_usage_limits, :ind_jsonb, default: -> { {} } + attribute :resource_usage_limits, ::Gitlab::Database::Type::IndifferentJsonb.new, default: -> { {} } validates :resource_usage_limits, json_schema: { filename: 'resource_usage_limits' } jsonb_accessor :rate_limits, diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb index f10ad5feda6f8c8ab0829af5485a16d2d62115cc..f7030ae6c7efb07165c4d0469d9a5827ce6de32e 100644 --- a/app/models/ci/build_metadata.rb +++ b/app/models/ci/build_metadata.rb @@ -30,9 +30,9 @@ class BuildMetadata < Ci::ApplicationRecord validates :id_tokens, json_schema: { filename: 'build_metadata_id_tokens' } validates :secrets, json_schema: { filename: 'build_metadata_secrets' } - attribute :config_options, :sym_jsonb - attribute :config_variables, :sym_jsonb - attribute :runtime_runner_features, :sym_jsonb + attribute :config_options, ::Gitlab::Database::Type::SymbolizedJsonb.new + attribute :config_variables, ::Gitlab::Database::Type::SymbolizedJsonb.new + attribute :runtime_runner_features, ::Gitlab::Database::Type::SymbolizedJsonb.new chronic_duration_attr_reader :timeout_human_readable, :timeout diff --git a/app/models/ci/secure_file.rb b/app/models/ci/secure_file.rb index e91cf2d5e1b8e10b619061764ff31d24d43bdd3d..d718df27c51b446c3c253f6ca12d2f0e28dc790f 100644 --- a/app/models/ci/secure_file.rb +++ b/app/models/ci/secure_file.rb @@ -18,7 +18,7 @@ class SecureFile < Ci::ApplicationRecord validates :checksum, :file_store, :name, :project_id, presence: true validates :name, uniqueness: { scope: :project } - attribute :metadata, :ind_jsonb + attribute :metadata, ::Gitlab::Database::Type::IndifferentJsonb.new validates :metadata, json_schema: { filename: "ci_secure_file_metadata" }, allow_nil: true attribute :file_store, default: -> { Ci::SecureFileUploader.default_store } diff --git a/app/models/import/source_user_placeholder_reference.rb b/app/models/import/source_user_placeholder_reference.rb index e73b402b3f90e308852681053f88ca8875e03184..07ff1096bebc4470817144b7c44343bcdfe2c317 100644 --- a/app/models/import/source_user_placeholder_reference.rb +++ b/app/models/import/source_user_placeholder_reference.rb @@ -18,7 +18,7 @@ class SourceUserPlaceholderReference < ApplicationRecord validate :validate_numeric_or_composite_key_present validate :validate_model_is_not_member - attribute :composite_key, :ind_jsonb + attribute :composite_key, ::Gitlab::Database::Type::IndifferentJsonb.new scope :model_groups_for_source_user, ->(source_user) do where(source_user: source_user) diff --git a/app/models/merge_request_context_commit.rb b/app/models/merge_request_context_commit.rb index 0389dd5a9d574f57f0745e2972321857e39489f8..7de6a4ffe4719c76a1f7f1d13f598a557697eddf 100644 --- a/app/models/merge_request_context_commit.rb +++ b/app/models/merge_request_context_commit.rb @@ -12,7 +12,7 @@ class MergeRequestContextCommit < ApplicationRecord validates :sha, presence: true validates :sha, uniqueness: { message: 'has already been added' } - attribute :trailers, :ind_jsonb + attribute :trailers, ::Gitlab::Database::Type::IndifferentJsonb.new validates :trailers, json_schema: { filename: 'git_trailers' } validates :merge_request_id, presence: true diff --git a/app/models/merge_request_diff_commit.rb b/app/models/merge_request_diff_commit.rb index 287e9d2cf025de1be84c71aee3d124e92adeab87..15b00beeac4c6b90b4e9db18495b70d2324333b1 100644 --- a/app/models/merge_request_diff_commit.rb +++ b/app/models/merge_request_diff_commit.rb @@ -29,7 +29,7 @@ class MergeRequestDiffCommit < ApplicationRecord sha_attribute :sha - attribute :trailers, :ind_jsonb + attribute :trailers, ::Gitlab::Database::Type::IndifferentJsonb.new validates :trailers, json_schema: { filename: 'git_trailers' } # A list of keys of which their values need to be trimmed before they can be diff --git a/app/models/plan_limits.rb b/app/models/plan_limits.rb index 113db140e873ac2625d86309273e6f222c2c8f36..f86107f5ecfd6d00f87d853d2d894553033f96bf 100644 --- a/app/models/plan_limits.rb +++ b/app/models/plan_limits.rb @@ -10,7 +10,7 @@ class PlanLimits < ApplicationRecord ignore_column :ci_max_artifact_size_running_container_scanning, remove_with: '14.3', remove_after: '2021-08-22' - attribute :limits_history, :ind_jsonb, default: -> { {} } + attribute :limits_history, ::Gitlab::Database::Type::IndifferentJsonb.new, default: -> { {} } validates :limits_history, json_schema: { filename: 'plan_limits_history' } LimitUndefinedError = Class.new(StandardError) diff --git a/app/models/vulnerability.rb b/app/models/vulnerability.rb index 99c62a844c3bfb48413dca7e56685c470cb6abd8..82023930f498d76271a4dd04a4e0fba07e03e9bb 100644 --- a/app/models/vulnerability.rb +++ b/app/models/vulnerability.rb @@ -9,7 +9,7 @@ class Vulnerability < Gitlab::Database::SecApplicationRecord scope :with_projects, -> { preload(:project) } validates :cvss, json_schema: { filename: "vulnerability_cvss_vectors", draft: 7 } - attribute :cvss, :ind_jsonb + attribute :cvss, ::Gitlab::Database::Type::IndifferentJsonb.new def self.link_reference_pattern nil diff --git a/app/models/work_items/widget_definition.rb b/app/models/work_items/widget_definition.rb index 366c93afb4c7ba6a51d53a2edc7d654e20e135c1..db435a95f10d1dd713aa10f5cf86f49f22981019 100644 --- a/app/models/work_items/widget_definition.rb +++ b/app/models/work_items/widget_definition.rb @@ -45,7 +45,7 @@ class WidgetDefinition < ApplicationRecord email_participants: 25 } - attribute :widget_options, :ind_jsonb + attribute :widget_options, ::Gitlab::Database::Type::IndifferentJsonb.new def self.available_widgets enabled.filter_map(&:widget_class).uniq diff --git a/config/initializers/1_active_record_data_types.rb b/config/initializers/1_active_record_data_types.rb index 5c0671f2ca3a4f61e0a93815f156ce3e2b40b773..b8dbea475cc91de876cec58dd57202b32721a369 100644 --- a/config/initializers/1_active_record_data_types.rb +++ b/config/initializers/1_active_record_data_types.rb @@ -5,9 +5,6 @@ require 'active_record/connection_adapters/postgresql_adapter' -ActiveRecord::Type.register(:ind_jsonb, Gitlab::Database::Type::IndifferentJsonb) -ActiveRecord::Type.register(:sym_jsonb, Gitlab::Database::Type::SymbolizedJsonb) - module ActiveRecord::ConnectionAdapters::PostgreSQL::OID # rubocop:disable Style/ClassAndModuleChildren # Add the class `DateTimeWithTimeZone` so we can map `timestamptz` to it. class DateTimeWithTimeZone < DateTime diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index ab7151fe66d4f85493f36e610534efb6d485f395..d01e1cceb5de488f3822ea47cb0042711a758a11 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -1243,7 +1243,7 @@ By default hash keys will be strings. Optionally you can add a custom data type ```ruby class BuildMetadata - attribute :config_options, :ind_jsonb # for indifferent accesss or :sym_jsonb if you need symbols only as keys. + attribute :config_options, ::Gitlab::Database::Type::IndifferentJsonb.new # for indifferent accesss or ::Gitlab::Database::Type::SymbolizedJsonb.new if you need symbols only as keys. end ``` diff --git a/ee/app/models/dast/profile_schedule.rb b/ee/app/models/dast/profile_schedule.rb index 2c6e7a903c4c05bd5a50ab3e9baf9b3b469eaee4..fe2bb5285d51ecaa38988865c39f082bd8cc6d05 100644 --- a/ee/app/models/dast/profile_schedule.rb +++ b/ee/app/models/dast/profile_schedule.rb @@ -20,7 +20,7 @@ class Dast::ProfileSchedule < ::Gitlab::Database::SecApplicationRecord validates :starts_at, presence: true validates :dast_profile_id, uniqueness: true - attribute :cadence, :ind_jsonb + attribute :cadence, ::Gitlab::Database::Type::IndifferentJsonb.new validates :cadence, json_schema: { filename: 'dast_profile_schedule_cadence', draft: 7 } validate :validate_plan_limit_not_exceeded_while_activating, if: :will_save_change_to_active? diff --git a/ee/app/models/ee/user_detail.rb b/ee/app/models/ee/user_detail.rb index 65dc86b1fd00d0cf59d0618babec501d0a166dc4..a76470b5ecafb4b30a485e3eb21b4448608471fb 100644 --- a/ee/app/models/ee/user_detail.rb +++ b/ee/app/models/ee/user_detail.rb @@ -10,7 +10,7 @@ module UserDetail scope :with_enterprise_group, -> { where.not(enterprise_group_id: nil) } - attribute :onboarding_status, :ind_jsonb + attribute :onboarding_status, ::Gitlab::Database::Type::IndifferentJsonb.new store_accessor( :onboarding_status, :step_url, :email_opt_in, :initial_registration_type, :registration_type, :glm_content, :glm_source, prefix: true diff --git a/ee/app/models/search/elastic/reindexing_task.rb b/ee/app/models/search/elastic/reindexing_task.rb index 9ed97bec5d6b2694542a1ed5755464d500ba4326..08747d72bd2855aafbce4e0b8ef34000028bd74d 100644 --- a/ee/app/models/search/elastic/reindexing_task.rb +++ b/ee/app/models/search/elastic/reindexing_task.rb @@ -11,7 +11,7 @@ class ReindexingTask < ApplicationRecord validates :slice_multiplier, presence: true validates :options, json_schema: { filename: 'elastic_reindexing_task_options' } - attribute :options, :ind_jsonb # for indifferent access + attribute :options, ::Gitlab::Database::Type::IndifferentJsonb.new # for indifferent access has_many :subtasks, class_name: 'Search::Elastic::ReindexingSubtask', foreign_key: :elastic_reindexing_task_id, inverse_of: :elastic_reindexing_task diff --git a/ee/app/models/search/zoekt/node.rb b/ee/app/models/search/zoekt/node.rb index 1b632783b62e3ed27fbc6f6ea9f991762f4ea61c..3f28ccb4a542e2ea81b28439eb855e01d2373ae5 100644 --- a/ee/app/models/search/zoekt/node.rb +++ b/ee/app/models/search/zoekt/node.rb @@ -33,7 +33,7 @@ class Node < ApplicationRecord validates :total_bytes, presence: true validates :metadata, json_schema: { filename: 'zoekt_node_metadata' } - attribute :metadata, :ind_jsonb # for indifferent access + attribute :metadata, ::Gitlab::Database::Type::IndifferentJsonb.new # for indifferent access scope :by_name, ->(*names) { where("metadata->>'name' IN (?)", names) } scope :lost, -> { where(last_seen_at: ..LOST_DURATION_THRESHOLD.ago) } diff --git a/ee/app/models/vulnerabilities/finding.rb b/ee/app/models/vulnerabilities/finding.rb index 0bfdc32490d7b791960261a870e4fbe021682c54..4bcf6ec26f277b8ee3aaf22d28e0b1010deb5ea4 100644 --- a/ee/app/models/vulnerabilities/finding.rb +++ b/ee/app/models/vulnerabilities/finding.rb @@ -110,7 +110,7 @@ class Finding < Gitlab::Database::SecApplicationRecord foreign_key: :uuid, inverse_of: :vulnerability_finding - attribute :config_options, :ind_jsonb + attribute :config_options, ::Gitlab::Database::Type::IndifferentJsonb.new attr_writer :sha attr_accessor :scan, :found_by_pipeline diff --git a/lib/gitlab/database/type/indifferent_jsonb.rb b/lib/gitlab/database/type/indifferent_jsonb.rb index 69bbcb383bae81802fd327cb55788a4b977fd721..66a3c7bb599d344e169bab362954796312de51ec 100644 --- a/lib/gitlab/database/type/indifferent_jsonb.rb +++ b/lib/gitlab/database/type/indifferent_jsonb.rb @@ -9,7 +9,7 @@ module Type # # class SomeModel < ApplicationRecord # # some_model.a_field is of type `jsonb` - # attribute :a_field, :ind_jsonb + # attribute :a_field, ::Gitlab::Database::Type::IndifferentJsonb.new # end class IndifferentJsonb < ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb def type diff --git a/lib/gitlab/database/type/symbolized_jsonb.rb b/lib/gitlab/database/type/symbolized_jsonb.rb index 5bec738ec9c7ef0e723beef44f3e8add740676ed..563100dfe33664b40c9ed416638fc1d1ac372dd2 100644 --- a/lib/gitlab/database/type/symbolized_jsonb.rb +++ b/lib/gitlab/database/type/symbolized_jsonb.rb @@ -9,7 +9,7 @@ module Type # # class SomeModel < ApplicationRecord # # some_model.a_field is of type `jsonb` - # attribute :a_field, :sym_jsonb + # attribute :a_field, ::Gitlab::Database::Type::SymbolizedJsonb.new # end class SymbolizedJsonb < ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb def type diff --git a/spec/lib/gitlab/database/type/indifferent_jsonb_spec.rb b/spec/lib/gitlab/database/type/indifferent_jsonb_spec.rb index 6d27cbe180d38ae1f60e9e643a42a8aed9116505..66f9f759302278acb07ac7feb9e48102ec6392be 100644 --- a/spec/lib/gitlab/database/type/indifferent_jsonb_spec.rb +++ b/spec/lib/gitlab/database/type/indifferent_jsonb_spec.rb @@ -29,7 +29,7 @@ Class.new(ApplicationRecord) do self.table_name = :_test_indifferent_jsonb - attribute :options, :ind_jsonb + attribute :options, ::Gitlab::Database::Type::IndifferentJsonb.new end end diff --git a/spec/lib/gitlab/database/type/symbolized_jsonb_spec.rb b/spec/lib/gitlab/database/type/symbolized_jsonb_spec.rb index a8401667b340f4a7fc98e9a5acbeaac65c256ce4..7a1904c1506321d8ed6c15bc453015010e268b27 100644 --- a/spec/lib/gitlab/database/type/symbolized_jsonb_spec.rb +++ b/spec/lib/gitlab/database/type/symbolized_jsonb_spec.rb @@ -28,7 +28,7 @@ Class.new(ApplicationRecord) do self.table_name = :_test_symbolized_jsonb - attribute :options, :sym_jsonb + attribute :options, ::Gitlab::Database::Type::SymbolizedJsonb.new end end