Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of replaceIfExists for CreateView #17

Open
pichlerm opened this issue May 28, 2018 · 0 comments
Open

Support of replaceIfExists for CreateView #17

pichlerm opened this issue May 28, 2018 · 0 comments

Comments

@pichlerm
Copy link

pichlerm commented May 28, 2018

We use CreateView with replaceIfExists="true" to change the definition of an existent view.
Also by directly creating a CreateViewChange which does not exclude Hana support in its supportsReplaceIfExistsOption (because it does not know about it).

For MS-SQL the CreateViewGenerator creates some SQL that checks for existence of the view with a top level IF NOT EXISTS which I have not found for Hana.
http://stackoverflow.com/questions/163246/sql-server-equivalent-to-oracles-create-or-replace-view

Hana supports an ALTER VIEW in addition to CREATE VIEW and DROP VIEW, however the ALTER VIEW requires an existent view, whereas replaceIfExists should both work when the view exists (replacing it) or not (creating it).

The simplest way for replaceIfExists I have found, was to do a DROP VIEW in case of CREATE VIEW (like done for MS-SQL in Liquibase 2.x); this will log an error if the view did not exist, but still create it afterwards.

Changes in CreateViewGeneratorHanaDB.java:

  • validate: Comment out
    if (createViewStatement.isReplaceIfExists()) { validationErrors.checkDisallowedField("replaceIfExists", ...); }

  • generateSql:
    String viewName = database.escapeViewName(statement.getSchemaName(), statement.getViewName());
    if (statement.isReplaceIfExists()) {
    sql.add(new UnparsedSql("DROP VIEW " + viewName));
    }
    sql.add(new UnparsedSql("CREATE VIEW " + viewName +
    " AS " + statement.getSelectQuery()));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant