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 4 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 = "metadata_key")
@Column(name = "metadata_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 = "metadata_key")
@Column(name = "metadata_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 metadata_key;
Copy link
Contributor

@fjtirado fjtirado Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to rename, I think we should rename key to name or id

alter table definitions_nodes_metadata alter column value rename to metadata_value;
Copy link
Contributor

@fjtirado fjtirado Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think value should be ok, but since it was reserved by standard, maybe stringValue ;)?

alter table definitions_metadata alter column key rename to metadata_key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, key to name

alter table definitions_metadata alter column value rename to metadata_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 metadata_key;
alter table definitions_nodes_metadata rename column value to metadata_value;
alter table definitions_metadata rename column key to metadata_key;
alter table definitions_metadata rename column value to metadata_value;
alter table definitions_annotations rename column value to annotation;
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
@Entity
@IdClass(CacheId.class)
@Table(name = "kogito_data_cache", uniqueConstraints = @UniqueConstraint(columnNames = { "name",
"key" }), indexes = @Index(columnList = "name,key", unique = true))
"cache_key" }), indexes = @Index(columnList = "name,cache_key", unique = true))
public class CacheEntity {

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

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

@Convert(converter = JsonBinaryConverter.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 key rename to cache_key;
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@


create table if not exists kogito_data_cache (
key varchar(255) not null,
cache_key varchar(255) not null,
name varchar(255) not null,
json_value jsonb,
primary key (key, name)
primary key (cache_key, name)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 key to cache_key;
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, " +
"ROW_NUMBER() OVER (ORDER BY name, cache_key) as id, " +
"name, " +
"key, " +
"cache_key, " +
"field1MappedField, " +
"field2MappedField " +
"FROM " +
Expand Down Expand Up @@ -174,7 +174,7 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = BasicTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "key", column = "cache_key"),
@FieldResult(name = "name", column = "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, " +
"ROW_NUMBER() OVER (ORDER BY name, cache_key) as id, " +
"name, " +
"key, " +
"cache_key, " +
"root, " +
"nestedBasicMappedField, " +
"nestedComplexCollectionMappedField1, " +
Expand Down Expand Up @@ -210,7 +210,7 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = ComplexHierarchicalTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "key", column = "cache_key"),
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "root", column = "root"),
@FieldResult(name = "nestedBasicMappedField", column = "nestedBasicMappedField"),
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, " +
"ROW_NUMBER() OVER (ORDER BY name, cache_key) as id, " +
"name, " +
"key, " +
"cache_key, " +
"root, " +
"nestedBasicMappedField, " +
"nestedBasicCollectionMappedField " +
Expand Down Expand Up @@ -194,7 +194,7 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = HierarchicalTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "key", column = "cache_key"),
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "root", column = "root"),
@FieldResult(name = "nestedBasicMappedField", column = "nestedBasicMappedField"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void dynamicMappingDefinitionCreation() {
final PostgresMappingDefinition definition = new PostgresMappingDefinition("ExampleMappingId",
"kogito_data_cache",
"json_value",
List.of(new PostgresField("key")),
List.of(new PostgresField("cache_key")),
List.of(new PostgresPartitionField("name", "Example")),
"Example",
List.of(new PostgresMapping("field1",
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, " +
"ROW_NUMBER() OVER (ORDER BY name, cache_key) as id, " +
"name, " +
"key, " +
"cache_key, " +
"field1MappedField, " +
"field2MappedField " +
"FROM " +
Expand Down Expand Up @@ -89,7 +89,7 @@ void testApplyMappingToExistingData() {
databaseManager.createArtifacts(new PostgresMappingDefinition("dynamicMappingId",
"kogito_data_cache",
"json_value",
List.of(new PostgresField("key")),
List.of(new PostgresField("cache_key")),
List.of(new PostgresPartitionField("name", CACHE_NAME)),
"DynamicTypeExtract",
List.of(new PostgresMapping("field1",
Expand Down Expand Up @@ -120,7 +120,7 @@ private void assertResultSize(final int expected) {
@EntityResult(
entityClass = DynamicTypeExtractRow.class,
fields = { @FieldResult(name = "id", column = "id"),
@FieldResult(name = "key", column = "key"),
@FieldResult(name = "key", column = "cache_key"),
@FieldResult(name = "name", column = "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 @@ -6,7 +6,7 @@
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName": "key"
"fieldName": "cache_key"
}
],
"sourceTablePartitionFields": [
Expand Down Expand Up @@ -39,7 +39,7 @@
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName": "key"
"fieldName": "cache_key"
}
],
"sourceTablePartitionFields": [
Expand Down Expand Up @@ -79,7 +79,7 @@
"sourceTableJsonFieldName": "json_value",
"sourceTableIdentityFields": [
{
"fieldName": "key"
"fieldName": "cache_key"
}
],
"sourceTablePartitionFields": [
Expand Down
Loading