gvenzl / oci-oracle-xe

Build scripts for Oracle Database XE container/docker images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi-schema DB Access

courtney-arnold opened this issue · comments

I am using TestContainers to test a legacy project that we maintain. In this legacy project, we have multiple schemas. The contents of the DB are populated by a test script.

createTable.sql

create user schemaA identified by test quota unlimited on users;

create table schemaA.tableA (
id number(19,0) not null,
name varchar2(255 char),
primary key (id));
-- 1 Spriden
insert into
schemaA.tableA
(id, name)
values
(1234, '54AB');
-- 2
insert into
schemaA.tableA
(id, name)
values
(2345, '12AB');

grant select on schemaA.tableA to schemaB;

The APP_USER is schemaB

I see the following in the container logs

grant select on schemaA.tableA to schemaB
*
ERROR at line 1:
user or role 'SCHEMAB' does not exist

How do I grant access to a schema table?

Hey @courtney-arnold,

Thanks a lot for using these images!

The reason is that by default the setup scripts connect to the Oracle Database instance XE directly while the APP_USER is created in the XEPDB1 pluggable database (which should be used by the application).

Add this line at the beginning of your setup.sql script:

alter session set container=xepdb1;

And make sure that your application connects to the database name XEPDB1 and you should be all set!

Thanks,

So helpful. This worked perfectly.

Thanks

Glad to hear it, thanks again for using these images! :)