How can I force flyway to clean my docker oracle database?

≯℡__Kan透↙ 提交于 2021-02-18 17:39:24

问题


I've downloaded the official oracle docker image for Oracle Database EE. I've got a flyway configuration and often run flyway:clean against the locally installed XE version of the database. However flyway tells me it is not allowed to clean the database in the docker image, but it can migrate it.

Is there a way to force flyway to clean the oracle db?

To answer the questions from the comments:

Here's the error message when running flyway through maven:

org.flywaydb.core.api.FlywayException: Clean not supported on Oracle for system schema "SCHEMA_OWNER"! It must not be changed in any way except by running an Oracle-supplied script! -> [Help 1]

The user I connect with was created with alter session set "_ORACLE_SCRIPT"=true;


回答1:


Flyway will throw this exception if the current schema is considered a system schema:

@Override
protected void doClean() throws SQLException {
    if (isSystem()) {
        throw new FlywayException("Clean not supported on Oracle for system schema " + database.quote(name) + "! " +
                "It must not be changed in any way except by running an Oracle-supplied script!");
    }

A schema is considered to be a system schema if it in a list of known default schemas or has ORACLE_MAINTAINED = 'Y'.

Creating the user with alter session set "_ORACLE_SCRIPT"=true; sets ORACLE_MAINTAINED = 'Y' for the user / schema.

There are two kinds of database in Oracle 12c: a Container Database (CDB) and a Pluggable Database (PDB). This is to support Multitenancy.

You are currently creating the user in the CDB, which would be a common user across all PDBs. In that case, you must either prefix the user name with c##:

create user c##scott identified by tiger;

or use the alter session set "_ORACLE_SCRIPT"=true;, otherwise you will get the error:

ORA-65096: invalid common user or role name in oracle

The alternative is to connect to a PDB and create a local user there (no prefix required and the user will only exists in that PDB), e.g.:

sqlplus sys/Oradoc_db1@ORCLPDB1 as sysdba

create user scott identified by tiger;

The update the Flyway url to connect to that PDB as that user:

-url=jdbc:oracle:thin:@oracle-ee:1521/orclpdb1.localdomain -user="scott" -password=tiger


来源:https://stackoverflow.com/questions/51763602/how-can-i-force-flyway-to-clean-my-docker-oracle-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!