Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

Re : Oracle Materialized views DROP

$
0
0

Hi,

It's a pitty this can't be achieved through liquibase itself so I worked around it using sql-maven-plugin to drop all materialized views before liquibase kicks in and only when liquibase.dropFirst is set to true. This avoids custom code and messing with classpath.

Used maven profiles to set a property to be the inverse boolean of another one since maven doesn't support it out of the box. I guess you could put the whole plugin execution in the profile too. It would probably be neater to also externalise the sql in the pom to an sql file, but for purposes of simple answer it's all below.

 My pom.xml ....
  1.     <properties>
     ...
     <db.skip.oracle.dropFirst>true</db.skip.oracle.dropFirst>
        </properties>
        ...
  2.     <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>sql-maven-plugin</artifactId>
                    <version>1.5</version>
                    <dependencies>
                        <dependency>
                            <groupId>oracle</groupId>
                            <artifactId>ojdbc6</artifactId>
                            <version>${oracle-jdbc.version}</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <driver>${db.driver}</driver>
                        <url>${db.url}</url>
                        <username>${db.user}</username>
                        <password>${db.password}</password>
                        <skip>${db.skip.oracle.dropFirst}</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>drop-oracle-specific-schema</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <delimiter>/</delimiter>
                                <delimiterType>row</delimiterType>
                                <sqlCommand>
                                    declare
                                      type mv_names_t is table of all_mviews.mview_name%type index by pls_integer;
                                      mview_names mv_names_t;
                                    begin
                                      select mview_name
                                      bulk collect into mview_names
                                      from all_mviews;
  3.                                   for indx in 1..mview_names.count loop
                                        execute immediate 'drop materialized view ' || mview_names(indx);
                                      end loop;
                                    end;
                                    /
                                </sqlCommand>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
  4.     ...
        <profiles>
            <profile>
                <id>drop-oracle-schema</id>
                <activation>
                    <property>
                        <name>liquibase.dropFirst</name>
                        <value>true</value>
                    </property>
                </activation>
                <properties>
                    <db.skip.oracle.dropFirst>false</db.skip.oracle.dropFirst>
                </properties>
            </profile>
        <profiles>
          By the way the editor posting on this site is quite buggy - I had to use my windows VM to reply in IE and even then the rendering was all off. Editor didn't even appear in chrome and ff on ubuntu.

        Viewing all articles
        Browse latest Browse all 2993

        Trending Articles