diff --git a/server/src/scripts/rename-user.js b/server/src/scripts/rename-user.js new file mode 100644 index 000000000..e79279755 --- /dev/null +++ b/server/src/scripts/rename-user.js @@ -0,0 +1,40 @@ +// @flow + +import { updateTypes } from 'lib/types/update-types'; + +import { createUpdates } from '../creators/update-creator'; +import { dbQuery, SQL } from '../database/database'; +import { fetchKnownUserInfos } from '../fetchers/user-fetchers'; +import { createScriptViewer } from '../session/scripts'; +import { main } from './utils'; + +const userID = '518252'; +const newUsername = 'atul'; + +async function renameUser() { + const [adjacentUsers] = await Promise.all([ + fetchKnownUserInfos(createScriptViewer(userID)), + dbQuery( + SQL`UPDATE users SET username = ${newUsername} WHERE id = ${userID}`, + ), + ]); + + const updateDatas = []; + const time = Date.now(); + updateDatas.push({ + type: updateTypes.UPDATE_CURRENT_USER, + userID, + time, + }); + for (const adjacentUserID in adjacentUsers) { + updateDatas.push({ + type: updateTypes.UPDATE_USER, + userID: adjacentUserID, + time, + updatedUserID: userID, + }); + } + await createUpdates(updateDatas); +} + +main([renameUser]);