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
991 stars 342 forks source link

When using relative path the generated relative path is relative to the supplied baseDir not the sql file #1644

Closed ryanewtaylor closed 11 months ago

ryanewtaylor commented 1 year ago

Configuration

I have the following directory structure. The migration_data template folder was generated by ora2pg.

.ORA2PG_MIGRATION
├───migration_data
│   ├───config
|   │   └───ora2pg.conf
|   ├───data
|   ├───reports
|   ├───schema
|   │   ├───dblinks
|   │   ├───directories
|   │   ├───...
|   └───sources
|       ├───functions
|       ├───mviews
|       ├─── ...
└─── export-raw-data.ps1

In my org2pg.config I specify to use relative paths.

PSQL_RELATIVE_PATH  1

Invocation

I have a custom PowerShell script, export-raw-data.ps1 that calls ora2pg to create a data.sql file in the migration_data/data. My working directory is ORA2PG_MIGRATION. The precise invocation is

PS C:\dev\ORA2PG_MIGRATION> .\export-raw-data.ps1
Invoking ora2pg...
ora2pg -c 'migration_data\config\ora2pg.conf' -t 'COPY' -o 'data.sql' -a 'MY_TABLE' -b 'migration_data\data'

This generates as I would expect data.sql and MY_TABLE_data.sql files in the migration_data\data folder.

.ORA2PG_MIGRATION
├───migration_data
│   ├───config
|   │   └───ora2pg.conf
|   ├───data
|   │   ├───data.sql
|   │   └───MY_TABLE_data.sql

Actual Result

When I inspect data.sql the `\ir command includes the baseDir supplied in the ora2pg call.

SET search_path = my_schema,public;
BEGIN;
ALTER TABLE MY_TABLE_data DISABLE TRIGGER USER;

\ir 'migration_data\data/MY_TABLE_data.sql'

ALTER TABLE MY_TABLE ENABLE TRIGGER USER;
COMMIT;

Expected Result

I would have expected the relative path to be relative to the sql file, not to the baseDir. That is, I would have expected this.

SET search_path = my_schema,public;
BEGIN;
ALTER TABLE MY_TABLE_data DISABLE TRIGGER USER;

\ir 'MY_TABLE_data.sql'

ALTER TABLE MY_TABLE ENABLE TRIGGER USER;
COMMIT;

According to the PostgreSQL documentation

The \ir command is similar to \i, but resolves relative file names differently. When executing in interactive mode, the two commands behave identically. However, when invoked from a script, \ir interprets file names relative to the directory in which the script is located, rather than the current working directory.

Question

How can I instruct ora2pg to generate a path relative to the script location rather than the baseDir provided in the ora2pg command?

darold commented 1 year ago

Right, that should be the case, there is a regression here.

darold commented 11 months ago

Commit 481787e fixes this issue.