blob: 591131cb2207f4c57d09c60303a0066785549ccc (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# frozen_string_literal: true
module Gitlab
module Schema
module Validation
module SchemaObjects
class Table
def initialize(name, columns)
@name = name
@columns = columns
end
attr_reader :name, :columns
def table_name
name
end
def statement
format('CREATE TABLE %s (%s)', name, columns_statement)
end
def fetch_column_by_name(column_name)
columns.find { |column| column.name == column_name }
end
def column_exists?(column_name)
column = fetch_column_by_name(column_name)
return false if column.nil?
true
end
private
def columns_statement
columns.reject(&:partition_key?).map(&:statement).join(', ')
end
end
end
end
end
end
|