-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NIFI-8831 Support using MSSQL as nifi registry relation database engine #7245
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...gistry-core/nifi-registry-framework/src/main/resources/db/migration/mssql/V2__Initial.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one or more | ||
| -- contributor license agreements. See the NOTICE file distributed with | ||
| -- this work for additional information regarding copyright ownership. | ||
| -- The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| -- (the "License"); you may not use this file except in compliance with | ||
| -- the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, software | ||
| -- distributed under the License is distributed on an "AS IS" BASIS, | ||
| -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| -- See the License for the specific language governing permissions and | ||
| -- limitations under the License. | ||
|
|
||
| -- The NAME column has a max size of 768 because this is the largest size that MySQL allows when using a unique constraint. | ||
| CREATE TABLE BUCKET ( | ||
| ID VARCHAR(50) NOT NULL, | ||
| NAME VARCHAR(767) NOT NULL, | ||
| DESCRIPTION TEXT, | ||
| CREATED DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| CONSTRAINT PK__BUCKET_ID PRIMARY KEY (ID), | ||
| CONSTRAINT UNIQUE__BUCKET_NAME UNIQUE (NAME) | ||
| ); | ||
|
|
||
| CREATE TABLE BUCKET_ITEM ( | ||
| ID VARCHAR(50) NOT NULL, | ||
| NAME VARCHAR(1000) NOT NULL, | ||
| DESCRIPTION TEXT, | ||
| CREATED DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| MODIFIED DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| ITEM_TYPE VARCHAR(50) NOT NULL, | ||
| BUCKET_ID VARCHAR(50) NOT NULL, | ||
| CONSTRAINT PK__BUCKET_ITEM_ID PRIMARY KEY (ID), | ||
| CONSTRAINT FK__BUCKET_ITEM_BUCKET_ID FOREIGN KEY (BUCKET_ID) REFERENCES BUCKET(ID) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE FLOW ( | ||
| ID VARCHAR(50) NOT NULL, | ||
| CONSTRAINT PK__FLOW_ID PRIMARY KEY (ID), | ||
| CONSTRAINT FK__FLOW_BUCKET_ITEM_ID FOREIGN KEY (ID) REFERENCES BUCKET_ITEM(ID) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE FLOW_SNAPSHOT ( | ||
| FLOW_ID VARCHAR(50) NOT NULL, | ||
| VERSION INT NOT NULL, | ||
| CREATED DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| CREATED_BY VARCHAR(1000) NOT NULL, | ||
| COMMENTS TEXT, | ||
| CONSTRAINT PK__FLOW_SNAPSHOT_FLOW_ID_AND_VERSION PRIMARY KEY (FLOW_ID, VERSION), | ||
| CONSTRAINT FK__FLOW_SNAPSHOT_FLOW_ID FOREIGN KEY (FLOW_ID) REFERENCES FLOW(ID) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE SIGNING_KEY ( | ||
| ID VARCHAR(50) NOT NULL, | ||
| TENANT_IDENTITY VARCHAR(767) NOT NULL, | ||
| KEY_VALUE VARCHAR(50) NOT NULL, | ||
| CONSTRAINT PK__SIGNING_KEY_ID PRIMARY KEY (ID), | ||
| CONSTRAINT UNIQUE__SIGNING_KEY_TENANT_IDENTITY UNIQUE (TENANT_IDENTITY) | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think the application shouldn't really be checking the type of database, with the exception of the Flyway stuff that sets up the DB. It is not clear to me what the different SQL here is doing, but can it be done in a general way that conforms to standard SQL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because IDENTITY is a keyword in MSSQL but not on H2, mysql, mariaDB and postgresql so for MSSQL it must be enclosed by [].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider escaping with double quotes instead, which is the ANSI/ISO standard, so hopefully works across all supported database types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ChrisSamo632,
I tried your suggestion on branch nathluu/registry-mssql-b but it does not work.
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO UGP_USER(IDENTIFIER, "IDENTITY") VALUES (?, ?)]; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"IDENTITY") VALUES ('76137000-a35a-3bb2-94d7-2f5bac309242', 'CN=user2, OU=nifi')' at line 1
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:667)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:960)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1015)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1025)
at org.apache.nifi.registry.security.authorization.database.DatabaseUserGroupProvider.addUser(DatabaseUserGroupProvider.java:133)
at org.apache.nifi.registry.security.authorization.database.DatabaseUserGroupProvider.onConfigured(DatabaseUserGroupProvider.java:97)
at org.apache.nifi.registry.security.authorization.AuthorizerFactory.getAuthorizer(AuthorizerFactory.java:191)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ANSI Mode would need to be enabled for MySQL - see https://stackoverflow.com/questions/2889871/how-do-i-escape-reserved-words-used-as-column-names-mysql-create-table/2889884#2889884, otherwise backticks would be necessary to escape column names of any reserved/keywords we're used in MySQL (I guess IDENTITY isn't such a word for existing supported DBs but is for MSSQL)
If we were to start requiring that mode to be set (I don't know whether other database types have similar settings) then document updates would be a good idea, but arguably this becomes a potentially breaking change for some users
Renaming the column to avoid keywords is another option, but again incompatible with existing deployments
I don't know which would be the preferred approach in that case. Maybe @bbende will have a preference