-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a migration to update the usernames field in Strapi (#152)
* chore: use pnpm * feat: create endpoint to update usernames * feat: create migration to update the username field * refactor: revert pnpm changes * fix: audit fix * fix: update packages * fix: remove unused export from methods
- Loading branch information
1 parent
9cb6733
commit fa012ca
Showing
7 changed files
with
2,125 additions
and
1,266 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,10 @@ | ||
#!/bin/bash | ||
|
||
read -p "Enter the name for the migration file: " userFileName | ||
currentDateTime=$(date +"%Y.%m.%dT%H.%M.%S") | ||
fileName="${currentDateTime}.${userFileName}.js" | ||
|
||
mkdir -p ./database/migrations | ||
touch "./database/migrations/$fileName" | ||
|
||
echo "Migration file created: ./database/migrations/$fileName" |
Empty file.
26 changes: 26 additions & 0 deletions
26
strapi/database/migrations/2025.01.16T09.18.30.update_innousers_username.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,26 @@ | ||
module.exports = { | ||
async up() { | ||
console.info('Starting the "update_innousers_username" migration'); | ||
await strapi.db.transaction(async () => { | ||
const innoUsers = await strapi.entityService.findMany('api::inno-user.inno-user'); | ||
innoUsers.map(async (user) => { | ||
if (!user.username) { | ||
const username = user.email.split('@')[0]; | ||
await strapi.entityService.update( | ||
"api::inno-user.inno-user", | ||
user.id, | ||
{ | ||
data: { | ||
username: username | ||
}, | ||
} | ||
) | ||
strapi.log.info( | ||
`[Migration]: Username for the InnoUser with id ${user.id} was updated.` | ||
) | ||
} | ||
}); | ||
strapi.log.info('Usernames for all Inno Users were updated.'); | ||
}); | ||
}, | ||
}; |
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