erlangbureau / jamdb_oracle

Oracle Database driver for Erlang
MIT License
106 stars 48 forks source link

it generates invalid modify fk key query #89

Closed bartekupartek closed 3 years ago

bartekupartek commented 3 years ago

I encountered the following issue during migrations:

alter table(:patient_appointment_requests) do
  modify(
    :appointment_id,
    references(:appointments,
      on_replace: :nilify,
      type: :binary_id,
      on_delete: :nilify_all
    )
  )
end

it generates query with additional comma between column type appointment_id raw(16), and constraint:

  # ALTER TABLE patient_appointment_requests MODIFY appointment_id raw(16), ADD CONSTRAINT patient_appointment_requests_appointment_id_fkey FOREIGN KEY (appointment_id) REFERENCES appointments(id) ON DELETE SET NULL
  # ** (Jamdb.Oracle.Error) 'ORA-01735: invalid ALTER TABLE option\n'

valid query should be:

ALTER TABLE patient_appointment_requests
MODIFY appointment_id raw(16)
ADD CONSTRAINT patient_appointment_requests_appointment_id_fkey
FOREIGN KEY (appointment_id)
REFERENCES appointments(id)
ON DELETE SET NULL
bartekupartek commented 3 years ago

I believe it shouldn't have comma here https://github.com/erlangbureau/jamdb_oracle/blob/master/lib/jamdb_oracle_query.ex#L781 (not sure about reason of this comma)

vstavskyi commented 3 years ago

Thanks. If there are new patches, Please share them with us, Everyone will be grateful.