migrations.js 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. import fs from 'fs';
  2. import path from 'path';
  3. import { TAPi18n } from '/imports/i18n';
  4. import AccountSettings from '../models/accountSettings';
  5. import TableVisibilityModeSettings from '../models/tableVisibilityModeSettings';
  6. import Actions from '../models/actions';
  7. import Activities from '../models/activities';
  8. import Announcements from '../models/announcements';
  9. import Attachments from '../models/attachments';
  10. import AttachmentsOld from '../models/attachments_old';
  11. import Avatars from '../models/avatars';
  12. import AvatarsOld from '../models/avatars_old';
  13. import Boards from '../models/boards';
  14. import CardComments from '../models/cardComments';
  15. import Cards from '../models/cards';
  16. import ChecklistItems from '../models/checklistItems';
  17. import Checklists from '../models/checklists';
  18. import CustomFields from '../models/customFields';
  19. import Integrations from '../models/integrations';
  20. import InvitationCodes from '../models/invitationCodes';
  21. import Lists from '../models/lists';
  22. import Rules from '../models/rules';
  23. import Settings from '../models/settings';
  24. import Swimlanes from '../models/swimlanes';
  25. import Triggers from '../models/triggers';
  26. import UnsavedEdits from '../models/unsavedEdits';
  27. import Users from '../models/users';
  28. // Anytime you change the schema of one of the collection in a non-backward
  29. // compatible way you have to write a migration in this file using the following
  30. // API:
  31. //
  32. // Migrations.add(name, migrationCallback, optionalOrder);
  33. // Note that we have extra migrations defined in `sandstorm.js` that are
  34. // exclusive to Sandstorm and shouldn’t be executed in the general case.
  35. // XXX I guess if we had ES6 modules we could
  36. // `import { isSandstorm } from sandstorm.js` and define the migration here as
  37. // well, but for now I want to avoid definied too many globals.
  38. // In the context of migration functions we don't want to validate database
  39. // mutation queries against the current (ie, latest) collection schema. Doing
  40. // that would work at the time we write the migration but would break in the
  41. // future when we'll update again the concerned collection schema.
  42. //
  43. // To prevent this bug we always have to disable the schema validation and
  44. // argument transformations. We generally use the shorthandlers defined below.
  45. const noValidate = {
  46. validate: false,
  47. filter: false,
  48. autoConvert: false,
  49. removeEmptyStrings: false,
  50. getAutoValues: false,
  51. };
  52. const noValidateMulti = { ...noValidate, multi: true };
  53. Migrations.add('board-background-color', () => {
  54. const defaultColor = '#16A085';
  55. Boards.update(
  56. {
  57. background: {
  58. $exists: false,
  59. },
  60. },
  61. {
  62. $set: {
  63. background: {
  64. type: 'color',
  65. color: defaultColor,
  66. },
  67. },
  68. },
  69. noValidateMulti,
  70. );
  71. });
  72. Migrations.add('add-cardcounterlist-allowed', () => {
  73. Boards.update(
  74. {
  75. allowsCardCounterList: {
  76. $exists: false,
  77. },
  78. },
  79. {
  80. $set: {
  81. allowsCardCounterList: true,
  82. },
  83. },
  84. noValidateMulti,
  85. );
  86. });
  87. /*
  88. Migrations.add('add-boardmemberlist-allowed', () => {
  89. Boards.update(
  90. {
  91. allowsBoardMemberList: {
  92. $exists: false,
  93. },
  94. },
  95. {
  96. $set: {
  97. allowsBoardMemberList: true,
  98. },
  99. },
  100. noValidateMulti,
  101. );
  102. });
  103. */
  104. Migrations.add('lowercase-board-permission', () => {
  105. ['Public', 'Private'].forEach(permission => {
  106. Boards.update(
  107. { permission },
  108. { $set: { permission: permission.toLowerCase() } },
  109. noValidateMulti,
  110. );
  111. });
  112. });
  113. /*
  114. // Security migration: see https://github.com/wekan/wekan/issues/99
  115. Migrations.add('change-attachments-type-for-non-images', () => {
  116. const newTypeForNonImage = 'application/octet-stream';
  117. Attachments.find().forEach(file => {
  118. if (!file.isImage()) {
  119. Attachments.update(
  120. file._id,
  121. {
  122. $set: {
  123. 'original.type': newTypeForNonImage,
  124. 'copies.attachments.type': newTypeForNonImage,
  125. },
  126. },
  127. noValidate,
  128. );
  129. }
  130. });
  131. });
  132. Migrations.add('card-covers', () => {
  133. Cards.find().forEach(card => {
  134. const cover = Attachments.findOne({ cardId: card._id, cover: true });
  135. if (cover) {
  136. Cards.update(card._id, { $set: { coverId: cover._id } }, noValidate);
  137. }
  138. });
  139. Attachments.update({}, { $unset: { cover: '' } }, noValidateMulti);
  140. });
  141. */
  142. Migrations.add('use-css-class-for-boards-colors', () => {
  143. const associationTable = {
  144. '#27AE60': 'nephritis',
  145. '#C0392B': 'pomegranate',
  146. '#2980B9': 'belize',
  147. '#8E44AD': 'wisteria',
  148. '#2C3E50': 'midnight',
  149. '#E67E22': 'pumpkin',
  150. '#CD5A91': 'moderatepink',
  151. '#00AECC': 'strongcyan',
  152. '#4BBF6B': 'limegreen',
  153. '#2C3E51': 'dark',
  154. '#27AE61': 'relax',
  155. '#568BA2': 'corteza',
  156. '#499BEA': 'clearblue',
  157. '#596557': 'natural',
  158. '#2A80B8': 'modern',
  159. '#2a2a2a': 'moderndark',
  160. '#222222': 'exodark',
  161. };
  162. Boards.find().forEach(board => {
  163. const oldBoardColor = board.background.color;
  164. const newBoardColor = associationTable[oldBoardColor];
  165. Boards.update(
  166. board._id,
  167. {
  168. $set: { color: newBoardColor },
  169. $unset: { background: '' },
  170. },
  171. noValidate,
  172. );
  173. });
  174. });
  175. Migrations.add('denormalize-star-number-per-board', () => {
  176. Boards.find().forEach(board => {
  177. const nStars = Users.find({ 'profile.starredBoards': board._id }).count();
  178. Boards.update(board._id, { $set: { stars: nStars } }, noValidate);
  179. });
  180. });
  181. // We want to keep a trace of former members so we can efficiently publish their
  182. // infos in the general board publication.
  183. Migrations.add('add-member-isactive-field', () => {
  184. Boards.find({}, { fields: { members: 1 } }).forEach(board => {
  185. const allUsersWithSomeActivity = _.chain(
  186. Activities.find(
  187. { boardId: board._id },
  188. { fields: { userId: 1 } },
  189. ).fetch(),
  190. )
  191. .pluck('userId')
  192. .uniq()
  193. .value();
  194. const currentUsers = _.pluck(board.members, 'userId');
  195. const formerUsers = _.difference(allUsersWithSomeActivity, currentUsers);
  196. const newMemberSet = [];
  197. board.members.forEach(member => {
  198. member.isActive = true;
  199. newMemberSet.push(member);
  200. });
  201. formerUsers.forEach(userId => {
  202. newMemberSet.push({
  203. userId,
  204. isAdmin: false,
  205. isActive: false,
  206. });
  207. });
  208. Boards.update(board._id, { $set: { members: newMemberSet } }, noValidate);
  209. });
  210. });
  211. Migrations.add('add-sort-checklists', () => {
  212. Checklists.find().forEach((checklist, index) => {
  213. if (!checklist.hasOwnProperty('sort')) {
  214. Checklists.direct.update(
  215. checklist._id,
  216. { $set: { sort: index } },
  217. noValidate,
  218. );
  219. }
  220. checklist.items.forEach((item, index) => {
  221. if (!item.hasOwnProperty('sort')) {
  222. Checklists.direct.update(
  223. { _id: checklist._id, 'items._id': item._id },
  224. { $set: { 'items.$.sort': index } },
  225. noValidate,
  226. );
  227. }
  228. });
  229. });
  230. });
  231. Migrations.add('add-swimlanes', () => {
  232. Boards.find().forEach(board => {
  233. const swimlaneId = board.getDefaultSwimline()._id;
  234. Cards.find({ boardId: board._id }).forEach(card => {
  235. if (!card.hasOwnProperty('swimlaneId')) {
  236. Cards.direct.update(
  237. { _id: card._id },
  238. { $set: { swimlaneId } },
  239. noValidate,
  240. );
  241. }
  242. });
  243. });
  244. });
  245. Migrations.add('add-views', () => {
  246. Boards.find().forEach(board => {
  247. if (!board.hasOwnProperty('view')) {
  248. Boards.direct.update(
  249. { _id: board._id },
  250. { $set: { view: 'board-view-swimlanes' } },
  251. noValidate,
  252. );
  253. }
  254. });
  255. });
  256. Migrations.add('add-checklist-items', () => {
  257. Checklists.find().forEach(checklist => {
  258. // Create new items
  259. _.sortBy(checklist.items, 'sort').forEach((item, index) => {
  260. ChecklistItems.direct.insert({
  261. title: item.title ? item.title : 'Checklist',
  262. sort: index,
  263. isFinished: item.isFinished,
  264. checklistId: checklist._id,
  265. cardId: checklist.cardId,
  266. });
  267. });
  268. // Delete old ones
  269. Checklists.direct.update(
  270. { _id: checklist._id },
  271. { $unset: { items: 1 } },
  272. noValidate,
  273. );
  274. });
  275. });
  276. Migrations.add('add-card-types', () => {
  277. Cards.find().forEach(card => {
  278. Cards.direct.update(
  279. { _id: card._id },
  280. {
  281. $set: {
  282. type: 'cardType-card',
  283. linkedId: null,
  284. },
  285. },
  286. noValidate,
  287. );
  288. });
  289. });
  290. Migrations.add('add-custom-fields-to-cards', () => {
  291. Cards.update(
  292. {
  293. customFields: {
  294. $exists: false,
  295. },
  296. },
  297. {
  298. $set: {
  299. customFields: [],
  300. },
  301. },
  302. noValidateMulti,
  303. );
  304. });
  305. Migrations.add('add-requester-field', () => {
  306. Cards.update(
  307. {
  308. requestedBy: {
  309. $exists: false,
  310. },
  311. },
  312. {
  313. $set: {
  314. requestedBy: '',
  315. },
  316. },
  317. noValidateMulti,
  318. );
  319. });
  320. Migrations.add('add-assigner-field', () => {
  321. Cards.update(
  322. {
  323. assignedBy: {
  324. $exists: false,
  325. },
  326. },
  327. {
  328. $set: {
  329. assignedBy: '',
  330. },
  331. },
  332. noValidateMulti,
  333. );
  334. });
  335. Migrations.add('add-parent-field-to-cards', () => {
  336. Cards.update(
  337. {
  338. parentId: {
  339. $exists: false,
  340. },
  341. },
  342. {
  343. $set: {
  344. parentId: '',
  345. },
  346. },
  347. noValidateMulti,
  348. );
  349. });
  350. Migrations.add('add-subtasks-boards', () => {
  351. Boards.update(
  352. {
  353. subtasksDefaultBoardId: {
  354. $exists: false,
  355. },
  356. },
  357. {
  358. $set: {
  359. subtasksDefaultBoardId: null,
  360. subtasksDefaultListId: null,
  361. },
  362. },
  363. noValidateMulti,
  364. );
  365. });
  366. Migrations.add('add-subtasks-sort', () => {
  367. Boards.update(
  368. {
  369. subtaskSort: {
  370. $exists: false,
  371. },
  372. },
  373. {
  374. $set: {
  375. subtaskSort: -1,
  376. },
  377. },
  378. noValidateMulti,
  379. );
  380. });
  381. Migrations.add('add-subtasks-allowed', () => {
  382. Boards.update(
  383. {
  384. allowsSubtasks: {
  385. $exists: false,
  386. },
  387. },
  388. {
  389. $set: {
  390. allowsSubtasks: true,
  391. },
  392. },
  393. noValidateMulti,
  394. );
  395. });
  396. Migrations.add('add-subtasks-allowed', () => {
  397. Boards.update(
  398. {
  399. presentParentTask: {
  400. $exists: false,
  401. },
  402. },
  403. {
  404. $set: {
  405. presentParentTask: 'no-parent',
  406. },
  407. },
  408. noValidateMulti,
  409. );
  410. });
  411. Migrations.add('add-authenticationMethod', () => {
  412. Users.update(
  413. {
  414. authenticationMethod: {
  415. $exists: false,
  416. },
  417. },
  418. {
  419. $set: {
  420. authenticationMethod: 'password',
  421. },
  422. },
  423. noValidateMulti,
  424. );
  425. });
  426. Migrations.add('remove-tag', () => {
  427. Users.update(
  428. {},
  429. {
  430. $unset: {
  431. 'profile.tags': 1,
  432. },
  433. },
  434. noValidateMulti,
  435. );
  436. });
  437. Migrations.add('remove-customFields-references-broken', () => {
  438. Cards.update(
  439. { 'customFields.$value': null },
  440. {
  441. $pull: {
  442. customFields: { value: null },
  443. },
  444. },
  445. noValidateMulti,
  446. );
  447. });
  448. Migrations.add('add-product-name', () => {
  449. Settings.update(
  450. {
  451. productName: {
  452. $exists: false,
  453. },
  454. },
  455. {
  456. $set: {
  457. productName: '',
  458. },
  459. },
  460. noValidateMulti,
  461. );
  462. });
  463. Migrations.add('add-hide-logo', () => {
  464. Settings.update(
  465. {
  466. hideLogo: {
  467. $exists: false,
  468. },
  469. },
  470. {
  471. $set: {
  472. hideLogo: false,
  473. },
  474. },
  475. noValidateMulti,
  476. );
  477. });
  478. Migrations.add('add-displayAuthenticationMethod', () => {
  479. Settings.update(
  480. {
  481. displayAuthenticationMethod: {
  482. $exists: false,
  483. },
  484. },
  485. {
  486. $set: {
  487. displayAuthenticationMethod: true,
  488. },
  489. },
  490. noValidateMulti,
  491. );
  492. });
  493. Migrations.add('add-defaultAuthenticationMethod', () => {
  494. Settings.update(
  495. {
  496. defaultAuthenticationMethod: {
  497. $exists: false,
  498. },
  499. },
  500. {
  501. $set: {
  502. defaultAuthenticationMethod: 'password',
  503. },
  504. },
  505. noValidateMulti,
  506. );
  507. });
  508. Migrations.add('add-templates', () => {
  509. Boards.update(
  510. {
  511. type: {
  512. $exists: false,
  513. },
  514. },
  515. {
  516. $set: {
  517. type: 'board',
  518. },
  519. },
  520. noValidateMulti,
  521. );
  522. Swimlanes.update(
  523. {
  524. type: {
  525. $exists: false,
  526. },
  527. },
  528. {
  529. $set: {
  530. type: 'swimlane',
  531. },
  532. },
  533. noValidateMulti,
  534. );
  535. Lists.update(
  536. {
  537. type: {
  538. $exists: false,
  539. },
  540. swimlaneId: {
  541. $exists: false,
  542. },
  543. },
  544. {
  545. $set: {
  546. type: 'list',
  547. swimlaneId: '',
  548. },
  549. },
  550. noValidateMulti,
  551. );
  552. Users.find({
  553. 'profile.templatesBoardId': {
  554. $exists: false,
  555. },
  556. }).forEach(user => {
  557. // Create board and swimlanes
  558. Boards.insert(
  559. {
  560. title: TAPi18n.__('templates'),
  561. permission: 'private',
  562. type: 'template-container',
  563. members: [
  564. {
  565. userId: user._id,
  566. isAdmin: true,
  567. isActive: true,
  568. isNoComments: false,
  569. isCommentOnly: false,
  570. },
  571. ],
  572. },
  573. (err, boardId) => {
  574. // Insert the reference to our templates board
  575. Users.update(user._id, {
  576. $set: { 'profile.templatesBoardId': boardId },
  577. });
  578. // Insert the card templates swimlane
  579. Swimlanes.insert(
  580. {
  581. title: TAPi18n.__('card-templates-swimlane'),
  582. boardId,
  583. sort: 1,
  584. type: 'template-container',
  585. },
  586. (err, swimlaneId) => {
  587. // Insert the reference to out card templates swimlane
  588. Users.update(user._id, {
  589. $set: { 'profile.cardTemplatesSwimlaneId': swimlaneId },
  590. });
  591. },
  592. );
  593. // Insert the list templates swimlane
  594. Swimlanes.insert(
  595. {
  596. title: TAPi18n.__('list-templates-swimlane'),
  597. boardId,
  598. sort: 2,
  599. type: 'template-container',
  600. },
  601. (err, swimlaneId) => {
  602. // Insert the reference to out list templates swimlane
  603. Users.update(user._id, {
  604. $set: { 'profile.listTemplatesSwimlaneId': swimlaneId },
  605. });
  606. },
  607. );
  608. // Insert the board templates swimlane
  609. Swimlanes.insert(
  610. {
  611. title: TAPi18n.__('board-templates-swimlane'),
  612. boardId,
  613. sort: 3,
  614. type: 'template-container',
  615. },
  616. (err, swimlaneId) => {
  617. // Insert the reference to out board templates swimlane
  618. Users.update(user._id, {
  619. $set: { 'profile.boardTemplatesSwimlaneId': swimlaneId },
  620. });
  621. },
  622. );
  623. },
  624. );
  625. });
  626. });
  627. Migrations.add('fix-circular-reference_', () => {
  628. Cards.find().forEach(card => {
  629. if (card.parentId === card._id) {
  630. Cards.update(card._id, { $set: { parentId: '' } }, noValidateMulti);
  631. }
  632. });
  633. });
  634. Migrations.add('mutate-boardIds-in-customfields', () => {
  635. CustomFields.find().forEach(cf => {
  636. CustomFields.update(
  637. cf,
  638. {
  639. $set: {
  640. boardIds: [cf.boardId],
  641. },
  642. $unset: {
  643. boardId: '',
  644. },
  645. },
  646. noValidateMulti,
  647. );
  648. });
  649. });
  650. const modifiedAtTables = [
  651. AccountSettings,
  652. TableVisibilityModeSettings,
  653. Actions,
  654. Activities,
  655. Announcements,
  656. Boards,
  657. CardComments,
  658. Cards,
  659. ChecklistItems,
  660. Checklists,
  661. CustomFields,
  662. Integrations,
  663. InvitationCodes,
  664. Lists,
  665. Rules,
  666. Settings,
  667. Swimlanes,
  668. Triggers,
  669. UnsavedEdits,
  670. Users,
  671. ];
  672. Migrations.add('add-missing-created-and-modified', () => {
  673. Promise.all(
  674. modifiedAtTables.map(db =>
  675. db
  676. .rawCollection()
  677. .update(
  678. { modifiedAt: { $exists: false } },
  679. { $set: { modifiedAt: new Date() } },
  680. { multi: true },
  681. )
  682. .then(() =>
  683. db
  684. .rawCollection()
  685. .update(
  686. { createdAt: { $exists: false } },
  687. { $set: { createdAt: new Date() } },
  688. { multi: true },
  689. ),
  690. ),
  691. ),
  692. )
  693. .then(() => {
  694. // eslint-disable-next-line no-console
  695. console.info('Successfully added createdAt and updatedAt to all tables');
  696. })
  697. .catch(e => {
  698. // eslint-disable-next-line no-console
  699. console.error(e);
  700. });
  701. });
  702. Migrations.add('fix-incorrect-dates', () => {
  703. const tables = [
  704. AccountSettings,
  705. TableVisibilityModeSettings,
  706. Actions,
  707. Activities,
  708. Announcements,
  709. Boards,
  710. CardComments,
  711. Cards,
  712. ChecklistItems,
  713. Checklists,
  714. CustomFields,
  715. Integrations,
  716. InvitationCodes,
  717. Lists,
  718. Rules,
  719. Settings,
  720. Swimlanes,
  721. Triggers,
  722. UnsavedEdits,
  723. ];
  724. // Dates were previously created with Date.now() which is a number, not a date
  725. tables.forEach(t =>
  726. t
  727. .rawCollection()
  728. .find({ $or: [{ createdAt: { $type: 1 } }, { updatedAt: { $type: 1 } }] })
  729. .forEach(({ _id, createdAt, updatedAt }) => {
  730. t.rawCollection().update(
  731. { _id },
  732. {
  733. $set: {
  734. createdAt: new Date(createdAt),
  735. updatedAt: new Date(updatedAt),
  736. },
  737. },
  738. );
  739. }),
  740. );
  741. });
  742. Migrations.add('add-assignee', () => {
  743. Cards.update(
  744. {
  745. assignees: {
  746. $exists: false,
  747. },
  748. },
  749. {
  750. $set: {
  751. assignees: [],
  752. },
  753. },
  754. noValidateMulti,
  755. );
  756. });
  757. Migrations.add('add-profile-showDesktopDragHandles', () => {
  758. Users.update(
  759. {
  760. 'profile.showDesktopDragHandles': {
  761. $exists: false,
  762. },
  763. },
  764. {
  765. $set: {
  766. 'profile.showDesktopDragHandles': false,
  767. },
  768. },
  769. noValidateMulti,
  770. );
  771. });
  772. Migrations.add('add-profile-hiddenMinicardLabelText', () => {
  773. Users.update(
  774. {
  775. 'profile.hiddenMinicardLabelText': {
  776. $exists: false,
  777. },
  778. },
  779. {
  780. $set: {
  781. 'profile.hiddenMinicardLabelText': false,
  782. },
  783. },
  784. noValidateMulti,
  785. );
  786. });
  787. Migrations.add('add-receiveddate-allowed', () => {
  788. Boards.update(
  789. {
  790. allowsReceivedDate: {
  791. $exists: false,
  792. },
  793. },
  794. {
  795. $set: {
  796. allowsReceivedDate: true,
  797. },
  798. },
  799. noValidateMulti,
  800. );
  801. });
  802. Migrations.add('add-startdate-allowed', () => {
  803. Boards.update(
  804. {
  805. allowsStartDate: {
  806. $exists: false,
  807. },
  808. },
  809. {
  810. $set: {
  811. allowsStartDate: true,
  812. },
  813. },
  814. noValidateMulti,
  815. );
  816. });
  817. Migrations.add('add-duedate-allowed', () => {
  818. Boards.update(
  819. {
  820. allowsDueDate: {
  821. $exists: false,
  822. },
  823. },
  824. {
  825. $set: {
  826. allowsDueDate: true,
  827. },
  828. },
  829. noValidateMulti,
  830. );
  831. });
  832. Migrations.add('add-enddate-allowed', () => {
  833. Boards.update(
  834. {
  835. allowsEndDate: {
  836. $exists: false,
  837. },
  838. },
  839. {
  840. $set: {
  841. allowsEndDate: true,
  842. },
  843. },
  844. noValidateMulti,
  845. );
  846. });
  847. Migrations.add('add-members-allowed', () => {
  848. Boards.update(
  849. {
  850. allowsMembers: {
  851. $exists: false,
  852. },
  853. },
  854. {
  855. $set: {
  856. allowsMembers: true,
  857. },
  858. },
  859. noValidateMulti,
  860. );
  861. });
  862. Migrations.add('add-assignee-allowed', () => {
  863. Boards.update(
  864. {
  865. allowsAssignee: {
  866. $exists: false,
  867. },
  868. },
  869. {
  870. $set: {
  871. allowsAssignee: true,
  872. },
  873. },
  874. noValidateMulti,
  875. );
  876. });
  877. Migrations.add('add-labels-allowed', () => {
  878. Boards.update(
  879. {
  880. allowsLabels: {
  881. $exists: false,
  882. },
  883. },
  884. {
  885. $set: {
  886. allowsLabels: true,
  887. },
  888. },
  889. noValidateMulti,
  890. );
  891. });
  892. Migrations.add('add-checklists-allowed', () => {
  893. Boards.update(
  894. {
  895. allowsChecklists: {
  896. $exists: false,
  897. },
  898. },
  899. {
  900. $set: {
  901. allowsChecklists: true,
  902. },
  903. },
  904. noValidateMulti,
  905. );
  906. });
  907. Migrations.add('add-attachments-allowed', () => {
  908. Boards.update(
  909. {
  910. allowsAttachments: {
  911. $exists: false,
  912. },
  913. },
  914. {
  915. $set: {
  916. allowsAttachments: true,
  917. },
  918. },
  919. noValidateMulti,
  920. );
  921. });
  922. Migrations.add('add-comments-allowed', () => {
  923. Boards.update(
  924. {
  925. allowsComments: {
  926. $exists: false,
  927. },
  928. },
  929. {
  930. $set: {
  931. allowsComments: true,
  932. },
  933. },
  934. noValidateMulti,
  935. );
  936. });
  937. Migrations.add('add-assigned-by-allowed', () => {
  938. Boards.update(
  939. {
  940. allowsAssignedBy: {
  941. $exists: false,
  942. },
  943. },
  944. {
  945. $set: {
  946. allowsAssignedBy: true,
  947. },
  948. },
  949. noValidateMulti,
  950. );
  951. });
  952. Migrations.add('add-requested-by-allowed', () => {
  953. Boards.update(
  954. {
  955. allowsRequestedBy: {
  956. $exists: false,
  957. },
  958. },
  959. {
  960. $set: {
  961. allowsRequestedBy: true,
  962. },
  963. },
  964. noValidateMulti,
  965. );
  966. });
  967. Migrations.add('add-activities-allowed', () => {
  968. Boards.update(
  969. {
  970. allowsActivities: {
  971. $exists: false,
  972. },
  973. },
  974. {
  975. $set: {
  976. allowsActivities: true,
  977. },
  978. },
  979. noValidateMulti,
  980. );
  981. });
  982. Migrations.add('add-description-title-allowed', () => {
  983. Boards.update(
  984. {
  985. allowsDescriptionTitle: {
  986. $exists: false,
  987. },
  988. },
  989. {
  990. $set: {
  991. allowsDescriptionTitle: true,
  992. },
  993. },
  994. noValidateMulti,
  995. );
  996. });
  997. Migrations.add('add-description-text-allowed', () => {
  998. Boards.update(
  999. {
  1000. allowsDescriptionText: {
  1001. $exists: false,
  1002. },
  1003. },
  1004. {
  1005. $set: {
  1006. allowsDescriptionText: true,
  1007. },
  1008. },
  1009. noValidateMulti,
  1010. );
  1011. });
  1012. Migrations.add('add-description-text-allowed-on-minicard', () => {
  1013. Boards.update(
  1014. {
  1015. allowsDescriptionTextOnMinicard: {
  1016. $exists: false,
  1017. },
  1018. },
  1019. {
  1020. $set: {
  1021. allowsDescriptionTextOnMinicard: true,
  1022. },
  1023. },
  1024. noValidateMulti,
  1025. );
  1026. });
  1027. Migrations.add('add-sort-field-to-boards', () => {
  1028. Boards.find().forEach((board, index) => {
  1029. if (!board.hasOwnProperty('sort')) {
  1030. Boards.direct.update(board._id, { $set: { sort: index } }, noValidate);
  1031. }
  1032. });
  1033. });
  1034. Migrations.add('add-default-profile-view', () => {
  1035. Users.find().forEach(user => {
  1036. if (!user.hasOwnProperty('profile.boardView')) {
  1037. // Set default view
  1038. Users.direct.update(
  1039. { _id: user._id },
  1040. { $set: { 'profile.boardView': 'board-view-swimlanes' } },
  1041. noValidate,
  1042. );
  1043. }
  1044. });
  1045. });
  1046. Migrations.add('add-hide-logo-by-default', () => {
  1047. Settings.update(
  1048. {
  1049. hideLogo: {
  1050. hideLogo: false,
  1051. },
  1052. },
  1053. {
  1054. $set: {
  1055. hideLogo: true,
  1056. },
  1057. },
  1058. noValidateMulti,
  1059. );
  1060. });
  1061. Migrations.add('add-card-number-allowed', () => {
  1062. Boards.update(
  1063. {
  1064. allowsCardNumber: {
  1065. $exists: false,
  1066. },
  1067. },
  1068. {
  1069. $set: {
  1070. allowsCardNumber: false,
  1071. },
  1072. },
  1073. noValidateMulti,
  1074. );
  1075. });
  1076. Migrations.add('assign-boardwise-card-numbers', () => {
  1077. Boards.find().forEach(board => {
  1078. let nextCardNumber = board.getNextCardNumber();
  1079. Cards.find(
  1080. {
  1081. boardId: board._id,
  1082. cardNumber: {
  1083. $exists: false
  1084. }
  1085. },
  1086. {
  1087. sort: { createdAt: 1 }
  1088. }
  1089. ).forEach(card => {
  1090. Cards.update(
  1091. card._id,
  1092. { $set: { cardNumber: nextCardNumber } },
  1093. noValidate);
  1094. nextCardNumber++;
  1095. });
  1096. })
  1097. });
  1098. Migrations.add('add-card-details-show-lists', () => {
  1099. Boards.update(
  1100. {
  1101. allowsShowLists: {
  1102. $exists: false,
  1103. },
  1104. },
  1105. {
  1106. $set: {
  1107. allowsShowLists: true,
  1108. },
  1109. },
  1110. noValidateMulti,
  1111. );
  1112. });
  1113. Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
  1114. AttachmentsOld.find().forEach(function(fileObj) {
  1115. const newFileName = fileObj.name();
  1116. const storagePath = Attachments.storagePath({});
  1117. const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
  1118. // This is "example" variable, change it to the userId that you might be using.
  1119. const userId = fileObj.userId;
  1120. const fileType = fileObj.type();
  1121. const fileSize = fileObj.size();
  1122. const fileId = fileObj._id;
  1123. const readStream = fileObj.createReadStream('attachments');
  1124. const writeStream = fs.createWriteStream(filePath);
  1125. writeStream.on('error', function(err) {
  1126. console.log('Writing error: ', err, filePath);
  1127. });
  1128. // Once we have a file, then upload it to our new data storage
  1129. readStream.on('end', () => {
  1130. console.log('Ended: ', filePath);
  1131. // UserFiles is the new Meteor-Files/FilesCollection collection instance
  1132. Attachments.addFile(
  1133. filePath,
  1134. {
  1135. fileName: newFileName,
  1136. type: fileType,
  1137. meta: {
  1138. boardId: fileObj.boardId,
  1139. cardId: fileObj.cardId,
  1140. listId: fileObj.listId,
  1141. swimlaneId: fileObj.swimlaneId,
  1142. source: 'import'
  1143. },
  1144. userId,
  1145. size: fileSize,
  1146. fileId,
  1147. },
  1148. (err, fileRef) => {
  1149. if (err) {
  1150. console.log(err);
  1151. } else {
  1152. console.log('File Inserted: ', fileRef._id);
  1153. // Set the userId again
  1154. Attachments.update({ _id: fileRef._id }, { $set: { userId } });
  1155. fileObj.remove();
  1156. }
  1157. },
  1158. true,
  1159. ); // proceedAfterUpload
  1160. });
  1161. readStream.on('error', error => {
  1162. console.log('Error: ', filePath, error);
  1163. });
  1164. readStream.pipe(writeStream);
  1165. });
  1166. });
  1167. Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
  1168. AvatarsOld.find().forEach(function(fileObj) {
  1169. const newFileName = fileObj.name();
  1170. const storagePath = Avatars.storagePath({});
  1171. const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
  1172. // This is "example" variable, change it to the userId that you might be using.
  1173. const userId = fileObj.userId;
  1174. const fileType = fileObj.type();
  1175. const fileSize = fileObj.size();
  1176. const fileId = fileObj._id;
  1177. const readStream = fileObj.createReadStream('avatars');
  1178. const writeStream = fs.createWriteStream(filePath);
  1179. writeStream.on('error', function(err) {
  1180. console.log('Writing error: ', err, filePath);
  1181. });
  1182. // Once we have a file, then upload it to our new data storage
  1183. readStream.on('end', () => {
  1184. console.log('Ended: ', filePath);
  1185. // UserFiles is the new Meteor-Files/FilesCollection collection instance
  1186. Avatars.addFile(
  1187. filePath,
  1188. {
  1189. fileName: newFileName,
  1190. type: fileType,
  1191. meta: {
  1192. boardId: fileObj.boardId,
  1193. cardId: fileObj.cardId,
  1194. listId: fileObj.listId,
  1195. swimlaneId: fileObj.swimlaneId,
  1196. },
  1197. userId,
  1198. size: fileSize,
  1199. fileId,
  1200. },
  1201. (err, fileRef) => {
  1202. if (err) {
  1203. console.log(err);
  1204. } else {
  1205. console.log('File Inserted: ', newFileName, fileRef._id);
  1206. // Set the userId again
  1207. Avatars.update({ _id: fileRef._id }, { $set: { userId } });
  1208. Users.find().forEach(user => {
  1209. const old_url = fileObj.url();
  1210. new_url = Avatars.findOne({ _id: fileRef._id }).link(
  1211. 'original',
  1212. '/',
  1213. );
  1214. if (user.profile.avatarUrl.startsWith(old_url)) {
  1215. // Set avatar url to new url
  1216. Users.direct.update(
  1217. { _id: user._id },
  1218. { $set: { 'profile.avatarUrl': new_url } },
  1219. noValidate,
  1220. );
  1221. console.log('User avatar updated: ', user._id, new_url);
  1222. }
  1223. });
  1224. fileObj.remove();
  1225. }
  1226. },
  1227. true, // proceedAfterUpload
  1228. );
  1229. });
  1230. readStream.on('error', error => {
  1231. console.log('Error: ', filePath, error);
  1232. });
  1233. readStream.pipe(writeStream);
  1234. });
  1235. });
  1236. Migrations.add('migrate-attachment-drop-index-cardId', () => {
  1237. try {
  1238. Attachments.collection._dropIndex({'cardId': 1});
  1239. } catch (error) {
  1240. }
  1241. });
  1242. Migrations.add('migrate-attachment-migration-fix-source-import', () => {
  1243. // there was an error at first versions, so source was import, instead of import
  1244. Attachments.update(
  1245. {"meta.source":"import,"},
  1246. {$set:{"meta.source":"import"}},
  1247. noValidateMulti
  1248. );
  1249. });