diff --git a/acceptance/cases/migration/schema_dumper_test.rb b/acceptance/cases/migration/schema_dumper_test.rb index 42e562e7..f2dc1aba 100644 --- a/acceptance/cases/migration/schema_dumper_test.rb +++ b/acceptance/cases/migration/schema_dumper_test.rb @@ -73,6 +73,20 @@ def test_dump_schema_contains_virtual_column ActiveRecord::SchemaDumper.dump connection, schema assert schema.string.include?("t.virtual \"full_name\", type: :string, as: \"COALESCE(first_name || ' ', '') || last_name\", stored: true"), schema.string end + + def test_dump_schema_contains_string_array + connection = ActiveRecord::Base.connection + schema = StringIO.new + ActiveRecord::SchemaDumper.dump connection, schema + assert schema.string.include?("t.string \"col_array_string\", array: true"), schema.string + end + + def test_dump_schema_index_storing + connection = ActiveRecord::Base.connection + schema = StringIO.new + ActiveRecord::SchemaDumper.dump connection, schema + assert schema.string.include?("t.index [\"last_name\"], name: \"index_singers_on_last_name\", order: { last_name: :asc }, storing: [\"first_name\", \"tracks_count\"]"), schema.string + end end end end diff --git a/acceptance/schema/schema.rb b/acceptance/schema/schema.rb index 1ea0e37b..ec20a8f6 100644 --- a/acceptance/schema/schema.rb +++ b/acceptance/schema/schema.rb @@ -126,6 +126,7 @@ def create_tables_in_test_schema t.integer :lock_version t.virtual :full_name, type: :string, as: "COALESCE(first_name || ' ', '') || last_name", stored: true end + add_index :singers, :last_name, storing: %i[tracks_count first_name] if is_7_1_or_higher? create_table :albums, primary_key: [:singerid, :albumid] do |t| diff --git a/lib/active_record/connection_adapters/spanner/schema_dumper.rb b/lib/active_record/connection_adapters/spanner/schema_dumper.rb index 1aa39870..83e305fa 100644 --- a/lib/active_record/connection_adapters/spanner/schema_dumper.rb +++ b/lib/active_record/connection_adapters/spanner/schema_dumper.rb @@ -27,6 +27,8 @@ def prepare_column_options column spec = { type: schema_type(column).inspect }.merge! spec end + spec[:array] = true if column.sql_type.start_with?('ARRAY<') + spec end @@ -54,7 +56,7 @@ def index_parts index index_parts = super index_parts << "null_filtered: #{index.null_filtered.inspect}" if index.null_filtered index_parts << "interleave_in: #{index.interleave_in.inspect}" if index.interleave_in - index_parts << "storing: #{format_index_parts index.storing}" if index.storing.present? + index_parts << "storing: #{format_index_parts index.storing.sort}" if index.storing.present? index_parts end