-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from Vizzuality/change_data_tool_resource_typ…
…e_to_has_many Changed relation between data tool and resource type to has_many
- Loading branch information
Showing
3 changed files
with
22 additions
and
4 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...ase/migrations/2024.01.19T10.00.00.change_data_tool_resource_type_relation_to_has_many.js
This file contains 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,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'); | ||
}, | ||
} |
This file contains 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 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