migrations.js 21 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. import AccountSettings from '../models/accountSettings';
  2. import Actions from '../models/actions';
  3. import Activities from '../models/activities';
  4. import Announcements from '../models/announcements';
  5. import Boards from '../models/boards';
  6. import CardComments from '../models/cardComments';
  7. import Cards from '../models/cards';
  8. import ChecklistItems from '../models/checklistItems';
  9. import Checklists from '../models/checklists';
  10. import CustomFields from '../models/customFields';
  11. import Integrations from '../models/integrations';
  12. import InvitationCodes from '../models/invitationCodes';
  13. import Lists from '../models/lists';
  14. import Rules from '../models/rules';
  15. import Settings from '../models/settings';
  16. import Swimlanes from '../models/swimlanes';
  17. import Triggers from '../models/triggers';
  18. import UnsavedEdits from '../models/unsavedEdits';
  19. import Users from '../models/users';
  20. // Anytime you change the schema of one of the collection in a non-backward
  21. // compatible way you have to write a migration in this file using the following
  22. // API:
  23. //
  24. // Migrations.add(name, migrationCallback, optionalOrder);
  25. // Note that we have extra migrations defined in `sandstorm.js` that are
  26. // exclusive to Sandstorm and shouldn’t be executed in the general case.
  27. // XXX I guess if we had ES6 modules we could
  28. // `import { isSandstorm } from sandstorm.js` and define the migration here as
  29. // well, but for now I want to avoid definied too many globals.
  30. // In the context of migration functions we don't want to validate database
  31. // mutation queries against the current (ie, latest) collection schema. Doing
  32. // that would work at the time we write the migration but would break in the
  33. // future when we'll update again the concerned collection schema.
  34. //
  35. // To prevent this bug we always have to disable the schema validation and
  36. // argument transformations. We generally use the shorthandlers defined below.
  37. const noValidate = {
  38. validate: false,
  39. filter: false,
  40. autoConvert: false,
  41. removeEmptyStrings: false,
  42. getAutoValues: false,
  43. };
  44. const noValidateMulti = { ...noValidate, multi: true };
  45. Migrations.add('board-background-color', () => {
  46. const defaultColor = '#16A085';
  47. Boards.update(
  48. {
  49. background: {
  50. $exists: false,
  51. },
  52. },
  53. {
  54. $set: {
  55. background: {
  56. type: 'color',
  57. color: defaultColor,
  58. },
  59. },
  60. },
  61. noValidateMulti,
  62. );
  63. });
  64. Migrations.add('lowercase-board-permission', () => {
  65. ['Public', 'Private'].forEach(permission => {
  66. Boards.update(
  67. { permission },
  68. { $set: { permission: permission.toLowerCase() } },
  69. noValidateMulti,
  70. );
  71. });
  72. });
  73. // Security migration: see https://github.com/wekan/wekan/issues/99
  74. Migrations.add('change-attachments-type-for-non-images', () => {
  75. const newTypeForNonImage = 'application/octet-stream';
  76. Attachments.find().forEach(file => {
  77. if (!file.isImage()) {
  78. Attachments.update(
  79. file._id,
  80. {
  81. $set: {
  82. 'original.type': newTypeForNonImage,
  83. 'copies.attachments.type': newTypeForNonImage,
  84. },
  85. },
  86. noValidate,
  87. );
  88. }
  89. });
  90. });
  91. Migrations.add('card-covers', () => {
  92. Cards.find().forEach(card => {
  93. const cover = Attachments.findOne({ cardId: card._id, cover: true });
  94. if (cover) {
  95. Cards.update(card._id, { $set: { coverId: cover._id } }, noValidate);
  96. }
  97. });
  98. Attachments.update({}, { $unset: { cover: '' } }, noValidateMulti);
  99. });
  100. Migrations.add('use-css-class-for-boards-colors', () => {
  101. const associationTable = {
  102. '#27AE60': 'nephritis',
  103. '#C0392B': 'pomegranate',
  104. '#2980B9': 'belize',
  105. '#8E44AD': 'wisteria',
  106. '#2C3E50': 'midnight',
  107. '#E67E22': 'pumpkin',
  108. '#CD5A91': 'moderatepink',
  109. '#00AECC': 'strongcyan',
  110. '#4BBF6B': 'limegreen',
  111. '#2C3E51': 'dark',
  112. '#27AE61': 'relax',
  113. '#568BA2': 'corteza',
  114. '#499BEA': 'clearblue',
  115. '#596557': 'natural',
  116. };
  117. Boards.find().forEach(board => {
  118. const oldBoardColor = board.background.color;
  119. const newBoardColor = associationTable[oldBoardColor];
  120. Boards.update(
  121. board._id,
  122. {
  123. $set: { color: newBoardColor },
  124. $unset: { background: '' },
  125. },
  126. noValidate,
  127. );
  128. });
  129. });
  130. Migrations.add('denormalize-star-number-per-board', () => {
  131. Boards.find().forEach(board => {
  132. const nStars = Users.find({ 'profile.starredBoards': board._id }).count();
  133. Boards.update(board._id, { $set: { stars: nStars } }, noValidate);
  134. });
  135. });
  136. // We want to keep a trace of former members so we can efficiently publish their
  137. // infos in the general board publication.
  138. Migrations.add('add-member-isactive-field', () => {
  139. Boards.find({}, { fields: { members: 1 } }).forEach(board => {
  140. const allUsersWithSomeActivity = _.chain(
  141. Activities.find(
  142. { boardId: board._id },
  143. { fields: { userId: 1 } },
  144. ).fetch(),
  145. )
  146. .pluck('userId')
  147. .uniq()
  148. .value();
  149. const currentUsers = _.pluck(board.members, 'userId');
  150. const formerUsers = _.difference(allUsersWithSomeActivity, currentUsers);
  151. const newMemberSet = [];
  152. board.members.forEach(member => {
  153. member.isActive = true;
  154. newMemberSet.push(member);
  155. });
  156. formerUsers.forEach(userId => {
  157. newMemberSet.push({
  158. userId,
  159. isAdmin: false,
  160. isActive: false,
  161. });
  162. });
  163. Boards.update(board._id, { $set: { members: newMemberSet } }, noValidate);
  164. });
  165. });
  166. Migrations.add('add-sort-checklists', () => {
  167. Checklists.find().forEach((checklist, index) => {
  168. if (!checklist.hasOwnProperty('sort')) {
  169. Checklists.direct.update(
  170. checklist._id,
  171. { $set: { sort: index } },
  172. noValidate,
  173. );
  174. }
  175. checklist.items.forEach((item, index) => {
  176. if (!item.hasOwnProperty('sort')) {
  177. Checklists.direct.update(
  178. { _id: checklist._id, 'items._id': item._id },
  179. { $set: { 'items.$.sort': index } },
  180. noValidate,
  181. );
  182. }
  183. });
  184. });
  185. });
  186. Migrations.add('add-swimlanes', () => {
  187. Boards.find().forEach(board => {
  188. const swimlaneId = board.getDefaultSwimline()._id;
  189. Cards.find({ boardId: board._id }).forEach(card => {
  190. if (!card.hasOwnProperty('swimlaneId')) {
  191. Cards.direct.update(
  192. { _id: card._id },
  193. { $set: { swimlaneId } },
  194. noValidate,
  195. );
  196. }
  197. });
  198. });
  199. });
  200. Migrations.add('add-views', () => {
  201. Boards.find().forEach(board => {
  202. if (!board.hasOwnProperty('view')) {
  203. Boards.direct.update(
  204. { _id: board._id },
  205. { $set: { view: 'board-view-swimlanes' } },
  206. noValidate,
  207. );
  208. }
  209. });
  210. });
  211. Migrations.add('add-checklist-items', () => {
  212. Checklists.find().forEach(checklist => {
  213. // Create new items
  214. _.sortBy(checklist.items, 'sort').forEach((item, index) => {
  215. ChecklistItems.direct.insert({
  216. title: item.title ? item.title : 'Checklist',
  217. sort: index,
  218. isFinished: item.isFinished,
  219. checklistId: checklist._id,
  220. cardId: checklist.cardId,
  221. });
  222. });
  223. // Delete old ones
  224. Checklists.direct.update(
  225. { _id: checklist._id },
  226. { $unset: { items: 1 } },
  227. noValidate,
  228. );
  229. });
  230. });
  231. Migrations.add('add-profile-view', () => {
  232. Users.find().forEach(user => {
  233. if (!user.hasOwnProperty('profile.boardView')) {
  234. // Set default view
  235. Users.direct.update(
  236. { _id: user._id },
  237. { $set: { 'profile.boardView': 'board-view-lists' } },
  238. noValidate,
  239. );
  240. }
  241. });
  242. });
  243. Migrations.add('add-card-types', () => {
  244. Cards.find().forEach(card => {
  245. Cards.direct.update(
  246. { _id: card._id },
  247. {
  248. $set: {
  249. type: 'cardType-card',
  250. linkedId: null,
  251. },
  252. },
  253. noValidate,
  254. );
  255. });
  256. });
  257. Migrations.add('add-custom-fields-to-cards', () => {
  258. Cards.update(
  259. {
  260. customFields: {
  261. $exists: false,
  262. },
  263. },
  264. {
  265. $set: {
  266. customFields: [],
  267. },
  268. },
  269. noValidateMulti,
  270. );
  271. });
  272. Migrations.add('add-requester-field', () => {
  273. Cards.update(
  274. {
  275. requestedBy: {
  276. $exists: false,
  277. },
  278. },
  279. {
  280. $set: {
  281. requestedBy: '',
  282. },
  283. },
  284. noValidateMulti,
  285. );
  286. });
  287. Migrations.add('add-assigner-field', () => {
  288. Cards.update(
  289. {
  290. assignedBy: {
  291. $exists: false,
  292. },
  293. },
  294. {
  295. $set: {
  296. assignedBy: '',
  297. },
  298. },
  299. noValidateMulti,
  300. );
  301. });
  302. Migrations.add('add-parent-field-to-cards', () => {
  303. Cards.update(
  304. {
  305. parentId: {
  306. $exists: false,
  307. },
  308. },
  309. {
  310. $set: {
  311. parentId: '',
  312. },
  313. },
  314. noValidateMulti,
  315. );
  316. });
  317. Migrations.add('add-subtasks-boards', () => {
  318. Boards.update(
  319. {
  320. subtasksDefaultBoardId: {
  321. $exists: false,
  322. },
  323. },
  324. {
  325. $set: {
  326. subtasksDefaultBoardId: null,
  327. subtasksDefaultListId: null,
  328. },
  329. },
  330. noValidateMulti,
  331. );
  332. });
  333. Migrations.add('add-subtasks-sort', () => {
  334. Boards.update(
  335. {
  336. subtaskSort: {
  337. $exists: false,
  338. },
  339. },
  340. {
  341. $set: {
  342. subtaskSort: -1,
  343. },
  344. },
  345. noValidateMulti,
  346. );
  347. });
  348. Migrations.add('add-subtasks-allowed', () => {
  349. Boards.update(
  350. {
  351. allowsSubtasks: {
  352. $exists: false,
  353. },
  354. },
  355. {
  356. $set: {
  357. allowsSubtasks: true,
  358. },
  359. },
  360. noValidateMulti,
  361. );
  362. });
  363. Migrations.add('add-subtasks-allowed', () => {
  364. Boards.update(
  365. {
  366. presentParentTask: {
  367. $exists: false,
  368. },
  369. },
  370. {
  371. $set: {
  372. presentParentTask: 'no-parent',
  373. },
  374. },
  375. noValidateMulti,
  376. );
  377. });
  378. Migrations.add('add-authenticationMethod', () => {
  379. Users.update(
  380. {
  381. authenticationMethod: {
  382. $exists: false,
  383. },
  384. },
  385. {
  386. $set: {
  387. authenticationMethod: 'password',
  388. },
  389. },
  390. noValidateMulti,
  391. );
  392. });
  393. Migrations.add('remove-tag', () => {
  394. Users.update(
  395. {},
  396. {
  397. $unset: {
  398. 'profile.tags': 1,
  399. },
  400. },
  401. noValidateMulti,
  402. );
  403. });
  404. Migrations.add('remove-customFields-references-broken', () => {
  405. Cards.update(
  406. { 'customFields.$value': null },
  407. {
  408. $pull: {
  409. customFields: { value: null },
  410. },
  411. },
  412. noValidateMulti,
  413. );
  414. });
  415. Migrations.add('add-product-name', () => {
  416. Settings.update(
  417. {
  418. productName: {
  419. $exists: false,
  420. },
  421. },
  422. {
  423. $set: {
  424. productName: '',
  425. },
  426. },
  427. noValidateMulti,
  428. );
  429. });
  430. Migrations.add('add-hide-logo', () => {
  431. Settings.update(
  432. {
  433. hideLogo: {
  434. $exists: false,
  435. },
  436. },
  437. {
  438. $set: {
  439. hideLogo: false,
  440. },
  441. },
  442. noValidateMulti,
  443. );
  444. });
  445. Migrations.add('add-displayAuthenticationMethod', () => {
  446. Settings.update(
  447. {
  448. displayAuthenticationMethod: {
  449. $exists: false,
  450. },
  451. },
  452. {
  453. $set: {
  454. displayAuthenticationMethod: true,
  455. },
  456. },
  457. noValidateMulti,
  458. );
  459. });
  460. Migrations.add('add-defaultAuthenticationMethod', () => {
  461. Settings.update(
  462. {
  463. defaultAuthenticationMethod: {
  464. $exists: false,
  465. },
  466. },
  467. {
  468. $set: {
  469. defaultAuthenticationMethod: 'password',
  470. },
  471. },
  472. noValidateMulti,
  473. );
  474. });
  475. Migrations.add('add-templates', () => {
  476. Boards.update(
  477. {
  478. type: {
  479. $exists: false,
  480. },
  481. },
  482. {
  483. $set: {
  484. type: 'board',
  485. },
  486. },
  487. noValidateMulti,
  488. );
  489. Swimlanes.update(
  490. {
  491. type: {
  492. $exists: false,
  493. },
  494. },
  495. {
  496. $set: {
  497. type: 'swimlane',
  498. },
  499. },
  500. noValidateMulti,
  501. );
  502. Lists.update(
  503. {
  504. type: {
  505. $exists: false,
  506. },
  507. swimlaneId: {
  508. $exists: false,
  509. },
  510. },
  511. {
  512. $set: {
  513. type: 'list',
  514. swimlaneId: '',
  515. },
  516. },
  517. noValidateMulti,
  518. );
  519. Users.find({
  520. 'profile.templatesBoardId': {
  521. $exists: false,
  522. },
  523. }).forEach(user => {
  524. // Create board and swimlanes
  525. Boards.insert(
  526. {
  527. title: TAPi18n.__('templates'),
  528. permission: 'private',
  529. type: 'template-container',
  530. members: [
  531. {
  532. userId: user._id,
  533. isAdmin: true,
  534. isActive: true,
  535. isNoComments: false,
  536. isCommentOnly: false,
  537. },
  538. ],
  539. },
  540. (err, boardId) => {
  541. // Insert the reference to our templates board
  542. Users.update(user._id, {
  543. $set: { 'profile.templatesBoardId': boardId },
  544. });
  545. // Insert the card templates swimlane
  546. Swimlanes.insert(
  547. {
  548. title: TAPi18n.__('card-templates-swimlane'),
  549. boardId,
  550. sort: 1,
  551. type: 'template-container',
  552. },
  553. (err, swimlaneId) => {
  554. // Insert the reference to out card templates swimlane
  555. Users.update(user._id, {
  556. $set: { 'profile.cardTemplatesSwimlaneId': swimlaneId },
  557. });
  558. },
  559. );
  560. // Insert the list templates swimlane
  561. Swimlanes.insert(
  562. {
  563. title: TAPi18n.__('list-templates-swimlane'),
  564. boardId,
  565. sort: 2,
  566. type: 'template-container',
  567. },
  568. (err, swimlaneId) => {
  569. // Insert the reference to out list templates swimlane
  570. Users.update(user._id, {
  571. $set: { 'profile.listTemplatesSwimlaneId': swimlaneId },
  572. });
  573. },
  574. );
  575. // Insert the board templates swimlane
  576. Swimlanes.insert(
  577. {
  578. title: TAPi18n.__('board-templates-swimlane'),
  579. boardId,
  580. sort: 3,
  581. type: 'template-container',
  582. },
  583. (err, swimlaneId) => {
  584. // Insert the reference to out board templates swimlane
  585. Users.update(user._id, {
  586. $set: { 'profile.boardTemplatesSwimlaneId': swimlaneId },
  587. });
  588. },
  589. );
  590. },
  591. );
  592. });
  593. });
  594. Migrations.add('fix-circular-reference_', () => {
  595. Cards.find().forEach(card => {
  596. if (card.parentId === card._id) {
  597. Cards.update(card._id, { $set: { parentId: '' } }, noValidateMulti);
  598. }
  599. });
  600. });
  601. Migrations.add('mutate-boardIds-in-customfields', () => {
  602. CustomFields.find().forEach(cf => {
  603. CustomFields.update(
  604. cf,
  605. {
  606. $set: {
  607. boardIds: [cf.boardId],
  608. },
  609. $unset: {
  610. boardId: '',
  611. },
  612. },
  613. noValidateMulti,
  614. );
  615. });
  616. });
  617. const modifiedAtTables = [
  618. AccountSettings,
  619. Actions,
  620. Activities,
  621. Announcements,
  622. Boards,
  623. CardComments,
  624. Cards,
  625. ChecklistItems,
  626. Checklists,
  627. CustomFields,
  628. Integrations,
  629. InvitationCodes,
  630. Lists,
  631. Rules,
  632. Settings,
  633. Swimlanes,
  634. Triggers,
  635. UnsavedEdits,
  636. Users,
  637. ];
  638. Migrations.add('add-missing-created-and-modified', () => {
  639. Promise.all(
  640. modifiedAtTables.map(db =>
  641. db
  642. .rawCollection()
  643. .update(
  644. { modifiedAt: { $exists: false } },
  645. { $set: { modifiedAt: new Date() } },
  646. { multi: true },
  647. )
  648. .then(() =>
  649. db
  650. .rawCollection()
  651. .update(
  652. { createdAt: { $exists: false } },
  653. { $set: { createdAt: new Date() } },
  654. { multi: true },
  655. ),
  656. ),
  657. ),
  658. )
  659. .then(() => {
  660. // eslint-disable-next-line no-console
  661. console.info('Successfully added createdAt and updatedAt to all tables');
  662. })
  663. .catch(e => {
  664. // eslint-disable-next-line no-console
  665. console.error(e);
  666. });
  667. });
  668. Migrations.add('fix-incorrect-dates', () => {
  669. const tables = [
  670. AccountSettings,
  671. Actions,
  672. Activities,
  673. Announcements,
  674. Boards,
  675. CardComments,
  676. Cards,
  677. ChecklistItems,
  678. Checklists,
  679. CustomFields,
  680. Integrations,
  681. InvitationCodes,
  682. Lists,
  683. Rules,
  684. Settings,
  685. Swimlanes,
  686. Triggers,
  687. UnsavedEdits,
  688. ];
  689. // Dates were previously created with Date.now() which is a number, not a date
  690. tables.forEach(t =>
  691. t
  692. .rawCollection()
  693. .find({ $or: [{ createdAt: { $type: 1 } }, { updatedAt: { $type: 1 } }] })
  694. .forEach(({ _id, createdAt, updatedAt }) => {
  695. t.rawCollection().update(
  696. { _id },
  697. {
  698. $set: {
  699. createdAt: new Date(createdAt),
  700. updatedAt: new Date(updatedAt),
  701. },
  702. },
  703. );
  704. }),
  705. );
  706. });
  707. Migrations.add('add-assignee', () => {
  708. Cards.update(
  709. {
  710. assignees: {
  711. $exists: false,
  712. },
  713. },
  714. {
  715. $set: {
  716. assignees: [],
  717. },
  718. },
  719. noValidateMulti,
  720. );
  721. });
  722. Migrations.add('add-profile-showDesktopDragHandles', () => {
  723. Users.update(
  724. {
  725. 'profile.showDesktopDragHandles': {
  726. $exists: false,
  727. },
  728. },
  729. {
  730. $set: {
  731. 'profile.showDesktopDragHandles': false,
  732. },
  733. },
  734. noValidateMulti,
  735. );
  736. });
  737. Migrations.add('add-profile-hiddenMinicardLabelText', () => {
  738. Users.update(
  739. {
  740. 'profile.hiddenMinicardLabelText': {
  741. $exists: false,
  742. },
  743. },
  744. {
  745. $set: {
  746. 'profile.hiddenMinicardLabelText': false,
  747. },
  748. },
  749. noValidateMulti,
  750. );
  751. });
  752. Migrations.add('add-receiveddate-allowed', () => {
  753. Boards.update(
  754. {
  755. allowsReceivedDate: {
  756. $exists: false,
  757. },
  758. },
  759. {
  760. $set: {
  761. allowsReceivedDate: true,
  762. },
  763. },
  764. noValidateMulti,
  765. );
  766. });
  767. Migrations.add('add-startdate-allowed', () => {
  768. Boards.update(
  769. {
  770. allowsStartDate: {
  771. $exists: false,
  772. },
  773. },
  774. {
  775. $set: {
  776. allowsStartDate: true,
  777. },
  778. },
  779. noValidateMulti,
  780. );
  781. });
  782. Migrations.add('add-duedate-allowed', () => {
  783. Boards.update(
  784. {
  785. allowsDueDate: {
  786. $exists: false,
  787. },
  788. },
  789. {
  790. $set: {
  791. allowsDueDate: true,
  792. },
  793. },
  794. noValidateMulti,
  795. );
  796. });
  797. Migrations.add('add-enddate-allowed', () => {
  798. Boards.update(
  799. {
  800. allowsEndDate: {
  801. $exists: false,
  802. },
  803. },
  804. {
  805. $set: {
  806. allowsEndDate: true,
  807. },
  808. },
  809. noValidateMulti,
  810. );
  811. });
  812. Migrations.add('add-members-allowed', () => {
  813. Boards.update(
  814. {
  815. allowsMembers: {
  816. $exists: false,
  817. },
  818. },
  819. {
  820. $set: {
  821. allowsMembers: true,
  822. },
  823. },
  824. noValidateMulti,
  825. );
  826. });
  827. Migrations.add('add-assignee-allowed', () => {
  828. Boards.update(
  829. {
  830. allowsAssignee: {
  831. $exists: false,
  832. },
  833. },
  834. {
  835. $set: {
  836. allowsAssignee: true,
  837. },
  838. },
  839. noValidateMulti,
  840. );
  841. });
  842. Migrations.add('add-labels-allowed', () => {
  843. Boards.update(
  844. {
  845. allowsLabels: {
  846. $exists: false,
  847. },
  848. },
  849. {
  850. $set: {
  851. allowsLabels: true,
  852. },
  853. },
  854. noValidateMulti,
  855. );
  856. });
  857. Migrations.add('add-checklists-allowed', () => {
  858. Boards.update(
  859. {
  860. allowsChecklists: {
  861. $exists: false,
  862. },
  863. },
  864. {
  865. $set: {
  866. allowsChecklists: true,
  867. },
  868. },
  869. noValidateMulti,
  870. );
  871. });
  872. Migrations.add('add-attachments-allowed', () => {
  873. Boards.update(
  874. {
  875. allowsAttachments: {
  876. $exists: false,
  877. },
  878. },
  879. {
  880. $set: {
  881. allowsAttachments: true,
  882. },
  883. },
  884. noValidateMulti,
  885. );
  886. });
  887. Migrations.add('add-comments-allowed', () => {
  888. Boards.update(
  889. {
  890. allowsComments: {
  891. $exists: false,
  892. },
  893. },
  894. {
  895. $set: {
  896. allowsComments: true,
  897. },
  898. },
  899. noValidateMulti,
  900. );
  901. });
  902. Migrations.add('add-assigned-by-allowed', () => {
  903. Boards.update(
  904. {
  905. allowsAssignedBy: {
  906. $exists: false,
  907. },
  908. },
  909. {
  910. $set: {
  911. allowsAssignedBy: true,
  912. },
  913. },
  914. noValidateMulti,
  915. );
  916. });
  917. Migrations.add('add-requested-by-allowed', () => {
  918. Boards.update(
  919. {
  920. allowsRequestedBy: {
  921. $exists: false,
  922. },
  923. },
  924. {
  925. $set: {
  926. allowsRequestedBy: true,
  927. },
  928. },
  929. noValidateMulti,
  930. );
  931. });
  932. Migrations.add('add-activities-allowed', () => {
  933. Boards.update(
  934. {
  935. allowsActivities: {
  936. $exists: false,
  937. },
  938. },
  939. {
  940. $set: {
  941. allowsActivities: true,
  942. },
  943. },
  944. noValidateMulti,
  945. );
  946. });
  947. Migrations.add('add-description-title-allowed', () => {
  948. Boards.update(
  949. {
  950. allowsDescriptionTitle: {
  951. $exists: false,
  952. },
  953. },
  954. {
  955. $set: {
  956. allowsDescriptionTitle: true,
  957. },
  958. },
  959. noValidateMulti,
  960. );
  961. });
  962. Migrations.add('add-description-text-allowed', () => {
  963. Boards.update(
  964. {
  965. allowsDescriptionText: {
  966. $exists: false,
  967. },
  968. },
  969. {
  970. $set: {
  971. allowsDescriptionText: true,
  972. },
  973. },
  974. noValidateMulti,
  975. );
  976. });
  977. Migrations.add('add-sort-field-to-boards', () => {
  978. Boards.find().forEach((board, index) => {
  979. if (!board.hasOwnProperty('sort')) {
  980. Boards.direct.update(board._id, { $set: { sort: index } }, noValidate);
  981. }
  982. });
  983. });