Liquibase Oracle: Generate changelog tries to create objects from another schema - oracle

I want to generate a changelog XML from an existing Oracle schema, let's name it A. This schema contains references to another schema, schema B. Tables in schema A for example contain foreign keys referencing tables in schema B. User A has only SELECT and REFERENCES privileges on the tables of schema B.
When I try to create a database changelog for schema A, tables and constraints from B are included, even though they are not owned by user A. Is there any way to change this behavior? I tries to set the defaultCatalogName, defaultSchemaName, changelogCatalogName and changelogSchemaName parameters, but nothing changed.

It should work the way you expect, but due to bug https://liquibase.jira.com/browse/CORE-1784 it is not working as expected. It is fixed for the upcoming 3.2.0 release, probably out in mid March.

Related

H2 set schema changes schema_search_path

If I have a schema_search_path set and I wish to create a bunch of tables using a common script by setting the schema and not explicating the
schema in the table create (common script could be used in multiple schemas, this also sets the schema_search_path to just the specified schema.
This seems like an undesirable side affect.
Value set by SET SCHEMA_SEARCH_PATH is not affected by any other commands.
But this value is only used when an identified is not qualified with the schema and an object with this name doesn't exist in the current schema (affected by SET SCHEMA command).
For example, tables referenced by non-qualified names are searched in the following order:
Tables of the current schema.
Local temporary tables. (Currently they also include query aliases from the WITH clauses, but this may be changed when somebody will implement a separate scope of identifiers for these views.)
Tables of each schema from SCHEMA_SEARCH_PATH, if any. When multiple schemas are specified, they order has a meaning, they are processed in the same order.
Legacy or compatibility tables, such as DUAL or SYSDUMMY1 in DB2 and Derby compatibility modes.
The first table matched by its name will be used.
This is a complex case, for the most types of database objects only steps (1) and (3) are performed.
If you think that something is not going as described here and you can create a standalone test case (Java / JDBC / SQL only, no third-party libraries), you can create a bug report on GitHub:
https://github.com/h2database/h2database/issues

2 databases on the one H2 instance

I have JPA Repository with #Query that joins tables from other DBs, that located on the same server.
SELECT id,co.name from Agenc a inner join[other_db_mame].[schema_name].[table_name] co .....
I want to write integration tests to cover the flow with this query.
In intégration tests I use H2 DB
And my question is, how to correctly configure H2 DB to have 2 DBs and make this query work?
Maybe there is a way, to create another db via scripts, or smth like this?
H2 supports direct access only to one database at once, but you can create linked tables to tables from other databases.
To create a linked table, you can use a CREATE LINKED TABLE command:
https://h2database.com/html/commands.html#create_linked_table
CREATE LINKED TABLE targetTableName('', 'jdbcURL', 'username', 'password', 'sourceTableName');
You can also link the whole schema with LINK_SCHEMA function:
https://h2database.com/html/functions.html#link_schema
CALL LINK_SCHEMA('targetSchemaName', '', 'jdbcURL', 'username', 'password', 'sourceSchemaName');
Note that format of fully-qualified table name in H2 (and in the SQL Standard) is catalogName.schemaName.tableName. H2 supports only one catalog (and its name is the same as a name of database) and you can't define additional catalogs. Non-standard -syntax with [identifier] is not accepted by H2 unless you use a MSSQLServer compatibility mode. In this mode you can use that syntax, but you can't have different names of catalogs anyway, so if they are fixed in your application, you have a problem.
Actually H2 can ignore the specified name of catalog if IGNORE_CATALOGS setting is set to TRUE:
https://h2database.com/html/commands.html#set_ignore_catalogs
SET IGNORE_CATALOGS TRUE;
But if combinations of schema and table name aren't unique in your original configuration, there is nothing to do with H2. You can't create different tables with the same schema and table name in H2 in any way.

How to use Oracle Dblinks that honor referential integrity constraints?

I have a need to move data between two identical Oracle databases. I have figured out how to use dbLinks to achieve most of it. Here is my confusion.
Lets say I have Table A, which refers to Table B present in DB1 and also similar structure in DB2. Is there any way possible for me to create db link to move data between Table A in DB1 and DB2 which automatically copies the relevant data in Table B to support referential constraints (without me having to spell it out)?
Thanks
Kay
A simple approach would be to duplicate the foreign key and check constraints in DB2.TableB in the destination table DB1.TableA.
A little more work is to create a materialized view in DB1 along the lines of
Create Materialized View TableA as Select * from TableB#DB2.link;
Refresh as required... You cannot do a fast refresh on a remote database but very few applications require true real time synchronization.

Sqoop accessing specific Oracle Schema

I have an Oracle database that has a number of schemas in it, a master schema and a bunch of children schemas. My master schema has privileges so that it can create/destroy/access tables in any of the children.
My question is, I'm doing a list-tables in Sqoop on the master schema and I I'm seeing all the children tables get included in the results.
Is there a way to distinguish which schema those tables belong to? I have some names that overlap and it's impossible to tell which table goes where at the moment.
mj
I believe that this issue is being solved by SQOOP-741 [1].
Links:
1: https://issues.apache.org/jira/browse/SQOOP-741
Sounds like you are selecting from ALL_TABLES. If you are logged in as the "master" schema user, you want to select from USER_TABLES. If you are selecting from ALL_TABLES you need to filter by OWNER=.

Oracle Database creation with exitsting tables

I've database with 15 tables. Now due to development process one column has to added to all the tables in the database. This changes should not affect the existing process because some other services are also consuming this database. So to accomplish it I thought of creating a new database. Is there are any other way to do it.
Usually it should be enough to create a new schema ("user") and create the tables in that new schema. In Oracle, identically named tables can exist in several schemas.
CREATE USER xxx IDENTIFIED BY yyy
you can create another schema for development and import the table to new schema.Developer should use the development schema instead of production schema.you can also create new database and import from current database but it might be last option
What's wrong with alter table T add (COL varchar2(5)); ?
Of course dependend stored procedures or packages become invalid.
You can leave them alone, then the first call would return an exception and auto-recompile the called procedure. Or you can alter procedure P compile;.

Resources