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

[kie-issues#1606] Modify columns in the flyway migration scripts which uses sql reserved words #2139

Merged
merged 8 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class NodeEntity extends AbstractEntity {
@CollectionTable(name = "definitions_nodes_metadata", joinColumns = { @JoinColumn(name = "node_id", referencedColumnName = "id"),
@JoinColumn(name = "process_id", referencedColumnName = "process_id"), @JoinColumn(name = "process_version", referencedColumnName = "process_version") },
foreignKey = @ForeignKey(name = "fk_definitions_nodes_metadata_definitions_nodes"))
@MapKeyColumn(name = "key")
@Column(name = "value")
@MapKeyColumn(name = "name")
@Column(name = "meta_value")
private Map<String, String> metadata;

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public class ProcessDefinitionEntity extends AbstractEntity {
@ElementCollection
@CollectionTable(name = "definitions_annotations", joinColumns = { @JoinColumn(name = "process_id", referencedColumnName = "id"),
@JoinColumn(name = "process_version", referencedColumnName = "version") }, foreignKey = @ForeignKey(name = "fk_definitions_annotations"))
@Column(name = "value")
@Column(name = "annotation")
private Set<String> annotations;
@ElementCollection
@CollectionTable(name = "definitions_metadata", joinColumns = {
@JoinColumn(name = "process_id", referencedColumnName = "id"), @JoinColumn(name = "process_version", referencedColumnName = "version") },
foreignKey = @ForeignKey(name = "fk_definitions_metadata"))
@MapKeyColumn(name = "key")
@Column(name = "value")
@MapKeyColumn(name = "name")
@Column(name = "meta_value")
private Map<String, String> metadata;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

alter table definitions_nodes_metadata alter column key rename to name;
alter table definitions_nodes_metadata alter column value rename to meta_value;
alter table definitions_metadata alter column key rename to name;
alter table definitions_metadata alter column value rename to meta_value;
alter table definitions_annotations alter column value rename to annotation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

alter table definitions_nodes_metadata rename column key to name;
alter table definitions_nodes_metadata rename column value to meta_value;
alter table definitions_metadata rename column key to name;
alter table definitions_metadata rename column value to meta_value;
alter table definitions_annotations rename column value to annotation;
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public List<T> execute() {

// Build the query to retrieve the filtered data from the temporary table above.
StringBuilder queryString = new StringBuilder("SELECT * FROM kogito_data_cache")
.append(" WHERE name = '")
.append(" WHERE cache_name = '")
.append(name)
.append("'");
if (filters != null && !filters.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@

@Entity
@IdClass(CacheId.class)
@Table(name = "kogito_data_cache", uniqueConstraints = @UniqueConstraint(columnNames = { "name",
"key" }), indexes = @Index(columnList = "name,key", unique = true))
@Table(name = "kogito_data_cache", uniqueConstraints = @UniqueConstraint(columnNames = { "cache_name",
"var_name" }), indexes = @Index(columnList = "cache_name,var_name", unique = true))
public class CacheEntity {

@Id
@Column(nullable = false)
@Column(name = "cache_name", nullable = false)
private String name;

@Id
@Column(nullable = false)
@Column(name = "var_name", nullable = false)
private String key;

@Convert(converter = JsonBinaryConverter.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

alter table kogito_data_cache alter column name rename to cache_name;
alter table kogito_data_cache alter column key rename to var_name;
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@


create table if not exists kogito_data_cache (
key varchar(255) not null,
name varchar(255) not null,
var_name varchar(255) not null,
cache_name varchar(255) not null,
json_value jsonb,
primary key (key, name)
primary key (var_name, cache_name)
);

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

alter table kogito_data_cache rename column name to cache_name;
alter table kogito_data_cache rename column key to var_name;
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ The following limitations apply:
All examples assume the following schema:
```postgresql
create table kogito_data_cache (
key varchar(255) not null,
name varchar(255) not null,
var_name varchar(255) not null,
cache_name varchar(255) not null,
json_value jsonb,
primary key (key, name)
);
Expand All @@ -130,13 +130,13 @@ entities through JPA. There are code examples in `org.kie.kogito:persistence-com
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName":"key",
"fieldName":"var_name",
"fieldType": "STRING"
}
],
"sourceTablePartitionFields": [
{
"fieldName": "name",
"fieldName": "cache_name",
"fieldType": "STRING",
"fieldValue": "BasicType"
}
Expand Down Expand Up @@ -186,13 +186,13 @@ Result
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName":"key",
"fieldName":"var_name",
"fieldType": "STRING"
}
],
"sourceTablePartitionFields": [
{
"fieldName": "name",
"fieldName": "cache_name",
"fieldType": "STRING",
"fieldValue": "HierarchicalType"
}
Expand Down Expand Up @@ -265,13 +265,13 @@ Result
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName":"key",
"fieldName":"var_name",
"fieldType": "STRING"
}
],
"sourceTablePartitionFields": [
{
"fieldName": "name",
"fieldName": "cache_name",
"fieldType": "STRING",
"fieldValue": "ComplexHierarchicalType"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName":"key",
"fieldName":"var_name",
"fieldType": "STRING"
}
],
"sourceTablePartitionFields": [
{
"fieldName": "name",
"fieldName": "cache_name",
"fieldType": "STRING",
"fieldValue": "BasicType"
}
Expand Down Expand Up @@ -41,13 +41,13 @@
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName":"key",
"fieldName":"var_name",
"fieldType": "STRING"
}
],
"sourceTablePartitionFields": [
{
"fieldName": "name",
"fieldName": "cache_name",
"fieldType": "STRING",
"fieldValue": "HierarchicalType"
}
Expand Down Expand Up @@ -83,13 +83,13 @@
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName":"key",
"fieldName":"var_name",
"fieldType": "STRING"
}
],
"sourceTablePartitionFields": [
{
"fieldName": "name",
"fieldName": "cache_name",
"fieldType": "STRING",
"fieldValue": "ComplexHierarchicalType"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class BasicTypeMappingIT {
private static final String CACHE_NAME = "BasicType";

private static final String SQL = "SELECT " +
"ROW_NUMBER() OVER (ORDER BY name, key) as id, " +
"name, " +
"key, " +
"ROW_NUMBER() OVER (ORDER BY cache_name, var_name) as id, " +
"cache_name, " +
"var_name, " +
"field1MappedField, " +
"field2MappedField " +
"FROM " +
Expand Down Expand Up @@ -174,8 +174,8 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = BasicTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "key", column = "var_name"),
@FieldResult(name = "name", column = "cache_name"),
@FieldResult(name = "field1MappedField", column = "field1MappedField"),
@FieldResult(name = "field2MappedField", column = "field2MappedField") })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class ComplexHierarchicalTypeMappingIT {
private static final String CACHE_NAME = "ComplexHierarchicalType";

private static final String SQL = "SELECT " +
"ROW_NUMBER() OVER (ORDER BY name, key) as id, " +
"name, " +
"key, " +
"ROW_NUMBER() OVER (ORDER BY cache_name, var_name) as id, " +
"cache_name, " +
"var_name, " +
"root, " +
"nestedBasicMappedField, " +
"nestedComplexCollectionMappedField1, " +
Expand Down Expand Up @@ -210,8 +210,8 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = ComplexHierarchicalTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "key", column = "var_name"),
@FieldResult(name = "name", column = "cache_name"),
@FieldResult(name = "root", column = "root"),
@FieldResult(name = "nestedBasicMappedField", column = "nestedBasicMappedField"),
@FieldResult(name = "nestedComplexCollectionMappedField1", column = "nestedComplexCollectionMappedField1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class HierarchicalTypeMappingIT {
private static final String CACHE_NAME = "HierarchicalType";

private static final String SQL = "SELECT " +
"ROW_NUMBER() OVER (ORDER BY name, key) as id, " +
"name, " +
"key, " +
"ROW_NUMBER() OVER (ORDER BY cache_name, var_name) as id, " +
"cache_name, " +
"var_name, " +
"root, " +
"nestedBasicMappedField, " +
"nestedBasicCollectionMappedField " +
Expand Down Expand Up @@ -194,8 +194,8 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = HierarchicalTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "key", column = "var_name"),
@FieldResult(name = "name", column = "cache_name"),
@FieldResult(name = "root", column = "root"),
@FieldResult(name = "nestedBasicMappedField", column = "nestedBasicMappedField"),
@FieldResult(name = "nestedBasicCollectionMappedField", column = "nestedBasicCollectionMappedField") })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void dynamicMappingDefinitionCreation() {
final PostgresMappingDefinition definition = new PostgresMappingDefinition("ExampleMappingId",
"kogito_data_cache",
"json_value",
List.of(new PostgresField("key")),
List.of(new PostgresPartitionField("name", "Example")),
List.of(new PostgresField("var_name")),
List.of(new PostgresPartitionField("cache_name", "Example")),
"Example",
List.of(new PostgresMapping("field1",
new PostgresJsonField("field1", JsonType.STRING))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class PostgresApplyMappingSqlBuilderIT {
private static final String CACHE_NAME = "DynamicType";

private static final String SQL = "SELECT " +
"ROW_NUMBER() OVER (ORDER BY name, key) as id, " +
"name, " +
"key, " +
"ROW_NUMBER() OVER (ORDER BY cache_name, var_name) as id, " +
"cache_name, " +
"var_name, " +
"field1MappedField, " +
"field2MappedField " +
"FROM " +
Expand Down Expand Up @@ -89,8 +89,8 @@ void testApplyMappingToExistingData() {
databaseManager.createArtifacts(new PostgresMappingDefinition("dynamicMappingId",
"kogito_data_cache",
"json_value",
List.of(new PostgresField("key")),
List.of(new PostgresPartitionField("name", CACHE_NAME)),
List.of(new PostgresField("var_name")),
List.of(new PostgresPartitionField("cache_name", CACHE_NAME)),
"DynamicTypeExtract",
List.of(new PostgresMapping("field1",
new PostgresJsonField("field1MappedField", JsonType.STRING)),
Expand Down Expand Up @@ -120,8 +120,8 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = DynamicTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "key", column = "var_name"),
@FieldResult(name = "name", column = "cache_name"),
@FieldResult(name = "field1MappedField", column = "field1MappedField"),
@FieldResult(name = "field2MappedField", column = "field2MappedField") })
})
Expand Down
Loading
Loading