Skip to content

Commit

Permalink
Merge pull request #143 from Vizzuality/change_data_tool_resource_typ…
Browse files Browse the repository at this point in the history
…e_to_has_many

Changed relation between data tool and resource type to has_many
  • Loading branch information
Agnieszka Figiel authored Jan 19, 2024
2 parents a73ee8d + 2328884 commit 9184754
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
async up(knex) {
// change the relation from 1:1 to 1:n without losing data

// add a data_tool_resource_type_order column
await knex.schema.table('data_tools_data_tool_resource_type_links', table => {
table.integer('data_tool_resource_type_order');
});
// populate the reorder column with 1
await knex.raw('UPDATE data_tools_data_tool_resource_type_links SET data_tool_resource_type_order = 1');
// make the column not nullable
await knex.schema.alterTable('data_tools_data_tool_resource_type_links', table => {
table.integer('data_tool_resource_type_order').notNullable().alter();
});
// rename the table to match strapi convention
await knex.schema.renameTable('data_tools_data_tool_resource_type_links', 'data_tools_data_tool_resource_types_links');
},
}
4 changes: 2 additions & 2 deletions cms/src/api/data-tool/content-types/data-tool/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"target": "api::data-tool-language.data-tool-language",
"mappedBy": "data_tool"
},
"data_tool_resource_type": {
"data_tool_resource_types": {
"type": "relation",
"relation": "oneToOne",
"relation": "oneToMany",
"target": "api::data-tool-resource-type.data-tool-resource-type"
},
"geography": {
Expand Down
4 changes: 2 additions & 2 deletions cms/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ export interface ApiDataToolDataTool extends Schema.CollectionType {
'oneToMany',
'api::data-tool-language.data-tool-language'
>;
data_tool_resource_type: Attribute.Relation<
data_tool_resource_types: Attribute.Relation<
'api::data-tool.data-tool',
'oneToOne',
'oneToMany',
'api::data-tool-resource-type.data-tool-resource-type'
>;
geography: Attribute.Text;
Expand Down

0 comments on commit 9184754

Please sign in to comment.