composite-primary-keys / composite_primary_keys

Composite Primary Keys support for Active Record
1.03k stars 351 forks source link

Does not work with string primary keys #584

Closed mghadley closed 1 year ago

mghadley commented 1 year ago

I am trying to use this gem with the Google Spanner database and it is so close to working. I am using GUIDs as primary keys and need to store them as strings. The t.parent_key method creates an integer column. The migration then breaks because the interleaving then looks for an integer primary key in the parent table. Unless I have missed it, there is no way to specify the parent_key column type. My migration methods are below.


     create_table :institutions, :id => false do |t|
      t.string :institution_guid, :primary_key => true
      t.string :name
      t.string :website
      t.string :support_email
      t.string :support_phone
      t.json :addresses

      t.timestamps
    end

    create_table :customers, :id => false do |t|
      t.interleave_in :institutions
      t.string :customer_guid, :primary_key => true
      t.parent_key :institution_guid
      t.string :external_customer_id, :null => false
      t.string :first_name
      t.string :middle_name
      t.string :last_name
      t.date :date_of_birth
      t.string :tax_id
      t.string :goverment_id
      t.string :customer_type
      t.json :emails
      t.json :addresses
      t.json :telephones

      t.timestamps
    end
mghadley commented 1 year ago

My mistake. The parent_key method is coming from another gem.