Skip to content

Commit

Permalink
change tests to migration 7.1 version & fix #133
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Jul 11, 2024
1 parent 26aadea commit 65ef7e3
Show file tree
Hide file tree
Showing 32 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def enum(*args, **options)

args.each { |name| column(name, kind, **options.except(:limit)) }
end

private

def valid_column_definition_options
super + [:array, :low_cardinality, :fixed_string, :value, :type]
end
end

class IndexDefinition
Expand Down
6 changes: 5 additions & 1 deletion lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ def create_table(table_name, **options, &block)
options = apply_replica(table_name, options)
td = create_table_definition(apply_cluster(table_name), **options)
block.call td if block_given?
td.column(:id, options[:id], null: false) if options[:id].present? && td[:id].blank? && options[:as].blank?
# support old migration version: in 5.0 options id: :integer, but 7.1 options empty
# todo remove auto add id column in future
if (!options.key?(:id) || options[:id].present? && options[:id] != false) && td[:id].blank? && options[:as].blank?
td.column(:id, options[:id] || :integer, null: false)
end

if options[:force]
drop_table(table_name, options.merge(if_exists: true))
Expand Down
2 changes: 1 addition & 1 deletion lib/clickhouse-activerecord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ClickhouseActiverecord
VERSION = '1.0.9'
VERSION = '1.0.10'
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateActionsTable < ActiveRecord::Migration[5.0]
class CreateActionsTable < ActiveRecord::Migration[7.1]
def up
create_table :actions, options: 'MergeTree ORDER BY date', force: true do |t|
t.datetime :array_datetime, null: false, array: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSampleTable < ActiveRecord::Migration[5.0]
class CreateSampleTable < ActiveRecord::Migration[7.1]
def up
create_table :sample, options: 'ReplacingMergeTree PARTITION BY toYYYYMM(date) ORDER BY (event_name)' do |t|
t.string :event_name, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateJoinTable < ActiveRecord::Migration[5.0]
class CreateJoinTable < ActiveRecord::Migration[7.1]
def up
create_table :joins, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (event_name)' do |t|
t.string :event_name, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)' do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ModifySomeTable < ActiveRecord::Migration[5.0]
class ModifySomeTable < ActiveRecord::Migration[7.1]
def up
add_column :some, :new_column, :big_integer
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeFunction < ActiveRecord::Migration[5.0]
class CreateSomeFunction < ActiveRecord::Migration[7.1]
def up
create_function :some_fun, "(x,y) -> x + y"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def change
create_table :some, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)', sync: true, id: false do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def change
create_table :some_distributed, with_distributed: :some, id: false, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)' do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeTable1 < ActiveRecord::Migration[5.0]
class CreateSomeTable1 < ActiveRecord::Migration[7.1]
def change
create_table :some_table_1, options: 'MergeTree ORDER BY col' do |t|
t.string :col, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeTable2 < ActiveRecord::Migration[5.0]
class CreateSomeTable2 < ActiveRecord::Migration[7.1]
def change
create_table :some_table_2, options: 'MergeTree ORDER BY col' do |t|
t.string :col, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeView < ActiveRecord::Migration[5.0]
class CreateSomeView < ActiveRecord::Migration[7.1]
def change
create_view :some_view, materialized: true, as: 'select * from some_table_1', to: 'some_table_2'
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def change
create_table :some_table, options: 'MergeTree ORDER BY col' do |t|
t.string :col, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSomeView < ActiveRecord::Migration[5.0]
class CreateSomeView < ActiveRecord::Migration[7.1]
def change
create_view :some_view, materialized: true, as: 'select * from some_table'
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)' do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ModifySomeTable < ActiveRecord::Migration[5.0]
class ModifySomeTable < ActiveRecord::Migration[7.1]
def up
remove_column :some, :id
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)' do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class DropSomeTable < ActiveRecord::Migration[5.0]
class DropSomeTable < ActiveRecord::Migration[7.1]
def up
drop_table :some
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)' do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class DropSomeTable < ActiveRecord::Migration[5.0]
class DropSomeTable < ActiveRecord::Migration[7.1]
def up
drop_table :some, sync: true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, id: false, force: true do |t|
t.datetime :datetime, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some do |t|
t.decimal :money, precision: 16, scale: 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, options: 'MergeTree PARTITION BY toYYYYMM(date) ORDER BY (date)' do |t|
t.date :date, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, id: false do |t|
t.enum :enum8, value: { key1: 1, key2: 2 }, limit: 1, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, id: false do |t|
t.string :fixed_string1, fixed_string: 1, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, id: false do |t|
t.string :col1, low_cardinality: true, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some, id: false do |t|
t.uuid :col1, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeFunction < ActiveRecord::Migration[5.0]
class CreateSomeFunction < ActiveRecord::Migration[7.1]
def up
sql = <<~SQL
CREATE FUNCTION some_fun AS (x,y) -> x + y
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
execute <<~SQL
CREATE TABLE some (
Expand Down

0 comments on commit 65ef7e3

Please sign in to comment.