summaryrefslogtreecommitdiff
path: root/lib/serializers
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-09-02 16:35:15 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2019-01-04 16:38:17 +0100
commit0103d5be960e620342c67436ddd64ca9e729d7a8 (patch)
treeb4f2cdd4a5ef8f6c906d71c674cc5f13f791c889 /lib/serializers
parentb647ad96f6e7cd1e6ca078635bb1ea49ee7d589f (diff)
downloadgitlab-ce-0103d5be960e620342c67436ddd64ca9e729d7a8.tar.gz
Add config_options|variables to BuildMetadatakamil-refactor-ci-builds-v5
These are data columns that store runtime configuration of build needed to execute it on runner and within pipeline. The definition of this data is that once used, and when no longer needed (due to retry capability) they can be freely removed. They use `jsonb` on PostgreSQL, and `text` on MySQL (due to lacking support for json datatype on old enough version).
Diffstat (limited to 'lib/serializers')
-rw-r--r--lib/serializers/json.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/serializers/json.rb b/lib/serializers/json.rb
new file mode 100644
index 00000000000..93cb192087a
--- /dev/null
+++ b/lib/serializers/json.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Serializers
+ # This serializer exports data as JSON,
+ # it is designed to be used with interwork compatibility between MySQL and PostgreSQL
+ # implementations, as used version of MySQL does not support native json type
+ #
+ # Secondly, the loader makes the resulting hash to have deep indifferent access
+ class JSON
+ class << self
+ def dump(obj)
+ # MySQL stores data as text
+ # look at ./config/initializers/ar_mysql_jsonb_support.rb
+ if Gitlab::Database.mysql?
+ obj = ActiveSupport::JSON.encode(obj)
+ end
+
+ obj
+ end
+
+ def load(data)
+ return if data.nil?
+
+ # On MySQL we store data as text
+ # look at ./config/initializers/ar_mysql_jsonb_support.rb
+ if Gitlab::Database.mysql?
+ data = ActiveSupport::JSON.decode(data)
+ end
+
+ Gitlab::Utils.deep_indifferent_access(data)
+ end
+ end
+ end
+end