rsim / oracle-enhanced

Oracle enhaced adapter for ActiveRecord
MIT License
544 stars 308 forks source link

Can't create a table with default bigint primary key. #2382

Open jva opened 1 month ago

jva commented 1 month ago

Steps to reproduce

I can't get the standalone tests running on ARM64. But here is the code that reproduces it in my schema.rb:

create_table "account_users", id: { limit: 19, precision: 19 }, force: :cascade do |t| t.integer "account_id", limit: 19, precision: 19, null: false ...

Expected behavior

rails db:test:prepare command should execute and create table with large number primary key

Actual behavior

╰─± rails db:test:prepare --trace
** Invoke db:test:prepare (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
DEBUG: database.yml using Oracle database
** Execute db:load_config
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke db:load_config
** Invoke db:check_protected_environments (first_time)
** Invoke db:load_config
** Execute db:check_protected_environments
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
rails aborted!
NoMethodError: undefined method `to_sym' for {:limit=>19, :precision=>19}:Hash
Did you mean?  to_s
               to_set
/Users/jva/.rvm/gems/jruby-9.3.13.0@rails61/gems/activerecord-6.1.7.7/lib/active_record/connection_adapters/abstract/schema_definitions.rb:407:in `column'
/Users/jva/.rvm/gems/jruby-9.3.13.0@rails61/gems/activerecord-6.1.7.7/lib/active_record/connection_adapters/abstract/schema_definitions.rb:242:in `primary_key'
/Users/jva/.rvm/gems/jruby-9.3.13.0@rails61/gems/activerecord-oracle_enhanced-adapter-6.1.6/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb:9:in `primary_key'
/Users/jva/.rvm/gems/jruby-9.3.13.0@rails61/gems/activerecord-oracle_enhanced-adapter-6.1.6/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb:214:in `create_table'

System configuration

Rails version: gem 'rails', '6.1.7.7'

Oracle enhanced adapter version: activerecord-oracle_enhanced-adapter (6.1.6)

Ruby version: jruby 9.3.13.0 (2.6.8) 2023-11-02 09b6f2263a OpenJDK 64-Bit Server VM 11.0.19+7 on 11.0.19+7 [arm64-darwin]

Oracle Database version: Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production

jva commented 1 month ago

I was able to fix it with this code in /lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb

module ActiveRecord
  module ConnectionAdapters
    module OracleEnhanced
      module ColumnMethods
        def primary_key(name, type = :primary_key, **options)
          # This is a placeholder for future :auto_increment support
          if type.is_a?(Hash)
            options = type
            type = :primary_key
          end
          super
        end