Ben Stickley
Ben Stickley

Reputation: 2120

TypeORM migration:run Oracle Alias Issue

I'm using TypeORM with an Oracle DB. When I add a migration and run typeorm migration:run I get this output:

bash-4.4$ typeorm migration:run
query: SELECT "TABLE_NAME" FROM "USER_TABLES" WHERE "TABLE_NAME" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
typeorm migration:run

Runs all pending migrations.

Options:
  -h, --help         Show help                                         [boolean]
  --connection, -c   Name of the connection on which run a query.
                                                            [default: "default"]
  --transaction, -t  Indicates if transaction should be used or not for
                     migration run. Enabled by default.     [default: "default"]
  --config, -f       Name of the file with connection configuration.
                                                          [default: "ormconfig"]
  -v, --version      Show version number                               [boolean]

[Error: ORA-24422: error occurred while trying to destroy the Session Pool] {
  errorNum: 24422,
  offset: 0
}

I tried running the last query listed with typeorm query "select * from \"migrations\" \"migrations\" order by \"id\" desc;" but then I got this error:

bash-4.4$ typeorm query "select * from \"migrations\" \"migrations\" ordery by \"id\" desc;"
Running query: select * from "migrations" "migrations" ordery by "id" desc;
Error during query execution:
QueryFailedError: ORA-00933: SQL command not properly ended
    at new QueryFailedError (/opt/app-root/src/.npm-global/lib/node_modules/typeorm/error/QueryFailedError.js:11:28)
    at handler (/opt/app-root/src/.npm-global/lib/node_modules/typeorm/driver/oracle/OracleQueryRunner.js:175:45)
    at Connection.custExecuteCb (/opt/app-root/src/bridge-server/node_modules/oracledb/lib/connection.js:103:7) {
  message: 'ORA-00933: SQL command not properly ended',
  errorNum: 933,
  offset: 40,
  name: 'QueryFailedError',
  query: 'select * from "migrations" "migrations" ordery by "id" desc;',
  parameters: []
}

I think the issue is the way TypeORM uses the table name alias. If I remove the second \"migrations\" above the query works fine.

Does anyone know what I should do? Thanks for your help!

Upvotes: 1

Views: 875

Answers (2)

Klaus Ertl
Klaus Ertl

Reputation: 1243

I ran into the same problem, which was caused by a schema configuration.

The output SELECT * FROM "myschema"."migrations" order by "id" DESC ; generated by typeorm does not work. It seems that there is an error in the statement generation, because the statement SELECT * FROM myschema."migrations" order by "id" DESC ; does work.

I fixed the issue by removing the schema.

Edit: The statement generation is correct, but case sensitive... so when I've fixed the case of my schema it also works with the generated statement SELECT * FROM "myschema"."migrations" order by "id" DESC ;

Upvotes: 1

Ben Stickley
Ben Stickley

Reputation: 2120

I was incorrect in my hypothesis. After using typeorm migration:generate to create my migration file instead of manually creating the file, the issue was resolved. It seems the issue arises when the name property in the migration class does not match the filename but I'm not totally sure.

Upvotes: 0

Related Questions