darold / ora2pg

Ora2Pg is a free tool used to migrate an Oracle database to a PostgreSQL compatible schema. It connects your Oracle database, scan it automatically and extracts its structure or data, it then generates SQL scripts that you can load into PostgreSQL.
http://www.ora2pg.com/
GNU General Public License v3.0
978 stars 341 forks source link

Unwanted NOT NULL constraint #1711

Closed fljdin closed 4 months ago

fljdin commented 7 months ago

Hi Gilles,

Ora2Pg version: v24.1

When I use a REPLACE_COLS directive, I've got a partial support for my column renaming on the NOT NULL constraint statement. Given the following Oracle table:

CREATE TABLE "TEST" (
  "TEST_ID" NUMBER(22) PRIMARY KEY,
  "IS_ACTIVE" VARCHAR(1) DEFAULT 'N' NOT NULL 
);
# config/ora2pg.conf
REPLACE_COLS   TEST(TEST_ID:ID) TEST(IS_ACTIVE:ACTIVE)
ora2pg -c config/ora2pg.conf -t TABLE -a TEST -b schema/tables -o tables.sql
-- schema/tables/table.sql
CREATE TABLE test (
        id numeric(22) NOT NULL,
        active varchar(1) NOT NULL DEFAULT 'N'
) ;
ALTER TABLE test ADD PRIMARY KEY (id);
ALTER TABLE test ALTER COLUMN is_active SET NOT NULL;

The PRIMARY KEY constraint statement is defined on renamed column, but NOT NULL is not. As NOT NULL is already defined in CREATE TABLE statement, is the ALTER COLUMN SET NOT NULL statement necessary?

Regards, Florent

darold commented 4 months ago

Commit 69593ca fixes this issue.