50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/clickhouse-activerecord/migration.rb', line 50
def create_table
return if table_exists?
key_options = connection.internal_string_options_for_primary_key
table_options = {
id: false,
options: connection.adapter_name.downcase == 'clickhouse' ? 'ReplacingMergeTree(created_at) PARTITION BY key ORDER BY key' : '',
if_not_exists: true
}
full_config = connection.instance_variable_get(:@full_config) || {}
if full_config[:distributed_service_tables]
table_options.merge!(with_distributed: table_name, sharding_key: 'cityHash64(created_at)')
distributed_suffix = "_#{full_config[:distributed_service_tables_suffix] || 'distributed'}"
end
connection.create_table(table_name + distributed_suffix.to_s, **table_options) do |t|
t.string :key, **key_options
t.string :value
t.timestamps
end
end
|