diff --git a/lib/active_record/connection_adapters/clickhouse/schema_definitions.rb b/lib/active_record/connection_adapters/clickhouse/schema_definitions.rb index d02f1bec..384b2ce3 100644 --- a/lib/active_record/connection_adapters/clickhouse/schema_definitions.rb +++ b/lib/active_record/connection_adapters/clickhouse/schema_definitions.rb @@ -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 diff --git a/lib/active_record/connection_adapters/clickhouse_adapter.rb b/lib/active_record/connection_adapters/clickhouse_adapter.rb index b6faabd8..9d6ee4d8 100644 --- a/lib/active_record/connection_adapters/clickhouse_adapter.rb +++ b/lib/active_record/connection_adapters/clickhouse_adapter.rb @@ -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)) diff --git a/lib/clickhouse-activerecord/version.rb b/lib/clickhouse-activerecord/version.rb index efa6f1df..548847fc 100644 --- a/lib/clickhouse-activerecord/version.rb +++ b/lib/clickhouse-activerecord/version.rb @@ -1,3 +1,3 @@ module ClickhouseActiverecord - VERSION = '1.0.9' + VERSION = '1.0.10' end diff --git a/spec/fixtures/migrations/add_array_datetime/1_create_actions_table.rb b/spec/fixtures/migrations/add_array_datetime/1_create_actions_table.rb index 7a1cd7f2..17048fbd 100644 --- a/spec/fixtures/migrations/add_array_datetime/1_create_actions_table.rb +++ b/spec/fixtures/migrations/add_array_datetime/1_create_actions_table.rb @@ -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 diff --git a/spec/fixtures/migrations/add_sample_data/1_create_sample_table.rb b/spec/fixtures/migrations/add_sample_data/1_create_sample_table.rb index 9619bfe5..0ae71253 100644 --- a/spec/fixtures/migrations/add_sample_data/1_create_sample_table.rb +++ b/spec/fixtures/migrations/add_sample_data/1_create_sample_table.rb @@ -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 diff --git a/spec/fixtures/migrations/add_sample_data/2_create_join_table.rb b/spec/fixtures/migrations/add_sample_data/2_create_join_table.rb index 7f4fb543..7436e8b6 100644 --- a/spec/fixtures/migrations/add_sample_data/2_create_join_table.rb +++ b/spec/fixtures/migrations/add_sample_data/2_create_join_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_add_column/1_create_some_table.rb b/spec/fixtures/migrations/dsl_add_column/1_create_some_table.rb index 35b899c5..c12567de 100644 --- a/spec/fixtures/migrations/dsl_add_column/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_add_column/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_add_column/2_modify_some_table.rb b/spec/fixtures/migrations/dsl_add_column/2_modify_some_table.rb index e6d5b479..afb1dcaf 100644 --- a/spec/fixtures/migrations/dsl_add_column/2_modify_some_table.rb +++ b/spec/fixtures/migrations/dsl_add_column/2_modify_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_function/1_create_some_function.rb b/spec/fixtures/migrations/dsl_create_function/1_create_some_function.rb index 8237036d..f49bd4df 100644 --- a/spec/fixtures/migrations/dsl_create_function/1_create_some_function.rb +++ b/spec/fixtures/migrations/dsl_create_function/1_create_some_function.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_table_with_cluster_name_alias/1_create_some_table.rb b/spec/fixtures/migrations/dsl_create_table_with_cluster_name_alias/1_create_some_table.rb index 0fc454df..2c94f452 100644 --- a/spec/fixtures/migrations/dsl_create_table_with_cluster_name_alias/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_create_table_with_cluster_name_alias/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_table_with_distributed/1_create_some_table.rb b/spec/fixtures/migrations/dsl_create_table_with_distributed/1_create_some_table.rb index 6e7a049b..231db516 100644 --- a/spec/fixtures/migrations/dsl_create_table_with_distributed/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_create_table_with_distributed/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_view_with_to_section/1_create_some_table_1.rb b/spec/fixtures/migrations/dsl_create_view_with_to_section/1_create_some_table_1.rb index 380cac45..54ad2f0e 100644 --- a/spec/fixtures/migrations/dsl_create_view_with_to_section/1_create_some_table_1.rb +++ b/spec/fixtures/migrations/dsl_create_view_with_to_section/1_create_some_table_1.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_view_with_to_section/2_create_some_table_2.rb b/spec/fixtures/migrations/dsl_create_view_with_to_section/2_create_some_table_2.rb index 6f2135d6..452158ed 100644 --- a/spec/fixtures/migrations/dsl_create_view_with_to_section/2_create_some_table_2.rb +++ b/spec/fixtures/migrations/dsl_create_view_with_to_section/2_create_some_table_2.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_view_with_to_section/3_create_some_view.rb b/spec/fixtures/migrations/dsl_create_view_with_to_section/3_create_some_view.rb index 13ff5af2..ba5b8548 100644 --- a/spec/fixtures/migrations/dsl_create_view_with_to_section/3_create_some_view.rb +++ b/spec/fixtures/migrations/dsl_create_view_with_to_section/3_create_some_view.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_view_without_to_section/1_create_some_table.rb b/spec/fixtures/migrations/dsl_create_view_without_to_section/1_create_some_table.rb index 530869ec..05e8612f 100644 --- a/spec/fixtures/migrations/dsl_create_view_without_to_section/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_create_view_without_to_section/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_create_view_without_to_section/2_create_some_view.rb b/spec/fixtures/migrations/dsl_create_view_without_to_section/2_create_some_view.rb index ac867e62..ac319364 100644 --- a/spec/fixtures/migrations/dsl_create_view_without_to_section/2_create_some_view.rb +++ b/spec/fixtures/migrations/dsl_create_view_without_to_section/2_create_some_view.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_drop_column/1_create_some_table.rb b/spec/fixtures/migrations/dsl_drop_column/1_create_some_table.rb index 35b899c5..c12567de 100644 --- a/spec/fixtures/migrations/dsl_drop_column/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_drop_column/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_drop_column/2_modify_some_table.rb b/spec/fixtures/migrations/dsl_drop_column/2_modify_some_table.rb index f68d6eda..b0618c85 100644 --- a/spec/fixtures/migrations/dsl_drop_column/2_modify_some_table.rb +++ b/spec/fixtures/migrations/dsl_drop_column/2_modify_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_drop_table/1_create_some_table.rb b/spec/fixtures/migrations/dsl_drop_table/1_create_some_table.rb index 35b899c5..c12567de 100644 --- a/spec/fixtures/migrations/dsl_drop_table/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_drop_table/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_drop_table/2_drop_some_table.rb b/spec/fixtures/migrations/dsl_drop_table/2_drop_some_table.rb index 4c9172b2..2d792781 100644 --- a/spec/fixtures/migrations/dsl_drop_table/2_drop_some_table.rb +++ b/spec/fixtures/migrations/dsl_drop_table/2_drop_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_drop_table_sync/1_create_some_table.rb b/spec/fixtures/migrations/dsl_drop_table_sync/1_create_some_table.rb index 35b899c5..c12567de 100644 --- a/spec/fixtures/migrations/dsl_drop_table_sync/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_drop_table_sync/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_drop_table_sync/2_drop_some_table.rb b/spec/fixtures/migrations/dsl_drop_table_sync/2_drop_some_table.rb index 69ddb690..e18e54b6 100644 --- a/spec/fixtures/migrations/dsl_drop_table_sync/2_drop_some_table.rb +++ b/spec/fixtures/migrations/dsl_drop_table_sync/2_drop_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_buffer_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_buffer_creation/1_create_some_table.rb index c50e7a12..f61c92ea 100644 --- a/spec/fixtures/migrations/dsl_table_buffer_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_buffer_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_datetime_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_datetime_creation/1_create_some_table.rb index bf2d30a0..74913724 100644 --- a/spec/fixtures/migrations/dsl_table_with_datetime_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_datetime_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_decimal_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_decimal_creation/1_create_some_table.rb index 3aedb806..8610a103 100644 --- a/spec/fixtures/migrations/dsl_table_with_decimal_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_decimal_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_engine_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_engine_creation/1_create_some_table.rb index 35b899c5..c12567de 100644 --- a/spec/fixtures/migrations/dsl_table_with_engine_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_engine_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_enum_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_enum_creation/1_create_some_table.rb index 15e6eb2e..0fbbca2f 100644 --- a/spec/fixtures/migrations/dsl_table_with_enum_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_enum_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_fixed_string_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_fixed_string_creation/1_create_some_table.rb index b209fef3..b20d3b3d 100644 --- a/spec/fixtures/migrations/dsl_table_with_fixed_string_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_fixed_string_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_low_cardinality_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_low_cardinality_creation/1_create_some_table.rb index dac079fb..6ed320b8 100644 --- a/spec/fixtures/migrations/dsl_table_with_low_cardinality_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_low_cardinality_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/dsl_table_with_uuid_creation/1_create_some_table.rb b/spec/fixtures/migrations/dsl_table_with_uuid_creation/1_create_some_table.rb index 9b9fad9a..6e2c388d 100644 --- a/spec/fixtures/migrations/dsl_table_with_uuid_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/dsl_table_with_uuid_creation/1_create_some_table.rb @@ -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 diff --git a/spec/fixtures/migrations/plain_function_creation/1_create_some_function.rb b/spec/fixtures/migrations/plain_function_creation/1_create_some_function.rb index a9a558fd..329dc7f5 100644 --- a/spec/fixtures/migrations/plain_function_creation/1_create_some_function.rb +++ b/spec/fixtures/migrations/plain_function_creation/1_create_some_function.rb @@ -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 diff --git a/spec/fixtures/migrations/plain_table_creation/1_create_some_table.rb b/spec/fixtures/migrations/plain_table_creation/1_create_some_table.rb index e1ade1e5..dc6e6461 100644 --- a/spec/fixtures/migrations/plain_table_creation/1_create_some_table.rb +++ b/spec/fixtures/migrations/plain_table_creation/1_create_some_table.rb @@ -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 (