ora_migrator icon indicating copy to clipboard operation
ora_migrator copied to clipboard

Primary key column is not set as "SERIAL" or with default value from sequence.

Open alubhaji opened this issue 5 years ago • 4 comments

First of all, many thanks for this tool. :-)

Issue description: If I have a table "foo" in Oracle with primary key "id" and an associated sequence, the table and sequence gets created in PostgreSQL but the next value for the key is not set by the sequence. I can run the following to fix it of course. ALTER TABLE foo ALTER COLUMN id SET DEFAULT nextval('foo_id_seq');

I did this test run using: SELECT db_migrate( plugin => 'ora_migrator', server => 'oracle', only_schemas => '{TEST_SCHEMA}');

Thanks!

alubhaji avatar Apr 09 '21 14:04 alubhaji

Please tell me the complete SQL statements to create the Oracle table and sequence, and how the sequence value is set in Oracle.

laurenz avatar Apr 09 '21 18:04 laurenz

Thanks, Laurenz. The table uses a "before insert" trigger to get the next value of the sequence. I can't provide the actual code. The trigger code looks similar to the one below:

CREATE OR REPLACE TRIGGER FOO_B_I BEFORE INSERT ON FOO FOR EACH ROW BEGIN :NEW.ID := FOO_SEQ.NEXTVAL; END; / SHOW ERRORS;

alubhaji avatar Apr 13 '21 03:04 alubhaji

ora_migrator won't migrate that into a DEFAULT automatically.

Don't consider ora_migrator to be an intelligent tool that will read and understand a trigger definition, deduce that it sets a value from a sequence and provide an equivalent column DEFAULT clause. The design principle is that ora_migrator takes care of the 90% that can easily be handled automatically and leaves the rest to you.

Just add the appropriate ALTER TABLE statement at the end of your migration process.

You will find that ora_migrator does not migrate PL/SQL code at all - you will have to translate it yourself.

laurenz avatar Apr 13 '21 03:04 laurenz

I assumed so as well. Thanks again.

alubhaji avatar Apr 13 '21 14:04 alubhaji