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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters')
-rw-r--r--gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/active_record_adapter.rb25
-rw-r--r--gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/base.rb33
-rw-r--r--gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/pg_adapter.rb30
3 files changed, 88 insertions, 0 deletions
diff --git a/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/active_record_adapter.rb b/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/active_record_adapter.rb
new file mode 100644
index 00000000000..10af0fc3647
--- /dev/null
+++ b/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/active_record_adapter.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Schema
+ module Validation
+ module Sources
+ module ConnectionAdapters
+ class ActiveRecordAdapter < Base
+ extend Forwardable
+
+ def_delegators :@connection, :current_schema
+
+ def exec_query(sql, schemas)
+ connection.exec_query(sql, nil, schemas)
+ end
+
+ def select_rows(sql, schemas)
+ connection.select_rows(sql, nil, schemas)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/base.rb b/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/base.rb
new file mode 100644
index 00000000000..713cbbe0a6d
--- /dev/null
+++ b/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/base.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Schema
+ module Validation
+ module Sources
+ module ConnectionAdapters
+ class Base
+ def initialize(connection)
+ @connection = connection
+ end
+
+ def current_schema
+ raise NotImplementedError, "#{self.class} does not implement #{__method__}"
+ end
+
+ def select_rows(sql, schemas = [])
+ raise NotImplementedError, "#{self.class} does not implement #{__method__}"
+ end
+
+ def exec_query(sql, schemas = [])
+ raise NotImplementedError, "#{self.class} does not implement #{__method__}"
+ end
+
+ private
+
+ attr_reader :connection
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/pg_adapter.rb b/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/pg_adapter.rb
new file mode 100644
index 00000000000..4dcaf15be71
--- /dev/null
+++ b/gems/gitlab-schema-validation/lib/gitlab/schema/validation/sources/connection_adapters/pg_adapter.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Schema
+ module Validation
+ module Sources
+ module ConnectionAdapters
+ class PgAdapter < Base
+ def initialize(connection)
+ @connection = connection
+ @connection.type_map_for_results = PG::BasicTypeMapForResults.new(connection)
+ end
+
+ def current_schema
+ connection.exec('SELECT current_schema').first['current_schema']
+ end
+
+ def exec_query(sql, schemas)
+ connection.exec(sql, schemas)
+ end
+
+ def select_rows(sql, schemas)
+ exec_query(sql, schemas).values
+ end
+ end
+ end
+ end
+ end
+ end
+end