migrations.js 21 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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. '#2A80B8': 'modern',
  117. '#2a2a2a': 'moderndark',
  118. };
  119. Boards.find().forEach(board => {
  120. const oldBoardColor = board.background.color;
  121. const newBoardColor = associationTable[oldBoardColor];
  122. Boards.update(
  123. board._id,
  124. {
  125. $set: { color: newBoardColor },
  126. $unset: { background: '' },
  127. },
  128. noValidate,
  129. );
  130. });
  131. });
  132. Migrations.add('denormalize-star-number-per-board', () => {
  133. Boards.find().forEach(board => {
  134. const nStars = Users.find({ 'profile.starredBoards': board._id }).count();
  135. Boards.update(board._id, { $set: { stars: nStars } }, noValidate);
  136. });
  137. });
  138. // We want to keep a trace of former members so we can efficiently publish their
  139. // infos in the general board publication.
  140. Migrations.add('add-member-isactive-field', () => {
  141. Boards.find({}, { fields: { members: 1 } }).forEach(board => {
  142. const allUsersWithSomeActivity = _.chain(
  143. Activities.find(
  144. { boardId: board._id },
  145. { fields: { userId: 1 } },
  146. ).fetch(),
  147. )
  148. .pluck('userId')
  149. .uniq()
  150. .value();
  151. const currentUsers = _.pluck(board.members, 'userId');
  152. const formerUsers = _.difference(allUsersWithSomeActivity, currentUsers);
  153. const newMemberSet = [];
  154. board.members.forEach(member => {
  155. member.isActive = true;
  156. newMemberSet.push(member);
  157. });
  158. formerUsers.forEach(userId => {
  159. newMemberSet.push({
  160. userId,
  161. isAdmin: false,
  162. isActive: false,
  163. });
  164. });
  165. Boards.update(board._id, { $set: { members: newMemberSet } }, noValidate);
  166. });
  167. });
  168. Migrations.add('add-sort-checklists', () => {
  169. Checklists.find().forEach((checklist, index) => {
  170. if (!checklist.hasOwnProperty('sort')) {
  171. Checklists.direct.update(
  172. checklist._id,
  173. { $set: { sort: index } },
  174. noValidate,
  175. );
  176. }
  177. checklist.items.forEach((item, index) => {
  178. if (!item.hasOwnProperty('sort')) {
  179. Checklists.direct.update(
  180. { _id: checklist._id, 'items._id': item._id },
  181. { $set: { 'items.$.sort': index } },
  182. noValidate,
  183. );
  184. }
  185. });
  186. });
  187. });
  188. Migrations.add('add-swimlanes', () => {
  189. Boards.find().forEach(board => {
  190. const swimlaneId = board.getDefaultSwimline()._id;
  191. Cards.find({ boardId: board._id }).forEach(card => {
  192. if (!card.hasOwnProperty('swimlaneId')) {
  193. Cards.direct.update(
  194. { _id: card._id },
  195. { $set: { swimlaneId } },
  196. noValidate,
  197. );
  198. }
  199. });
  200. });
  201. });
  202. Migrations.add('add-views', () => {
  203. Boards.find().forEach(board => {
  204. if (!board.hasOwnProperty('view')) {
  205. Boards.direct.update(
  206. { _id: board._id },
  207. { $set: { view: 'board-view-swimlanes' } },
  208. noValidate,
  209. );
  210. }
  211. });
  212. });
  213. Migrations.add('add-checklist-items', () => {
  214. Checklists.find().forEach(checklist => {
  215. // Create new items
  216. _.sortBy(checklist.items, 'sort').forEach((item, index) => {
  217. ChecklistItems.direct.insert({
  218. title: item.title ? item.title : 'Checklist',
  219. sort: index,
  220. isFinished: item.isFinished,
  221. checklistId: checklist._id,
  222. cardId: checklist.cardId,
  223. });
  224. });
  225. // Delete old ones
  226. Checklists.direct.update(
  227. { _id: checklist._id },
  228. { $unset: { items: 1 } },
  229. noValidate,
  230. );
  231. });
  232. });
  233. Migrations.add('add-card-types', () => {
  234. Cards.find().forEach(card => {
  235. Cards.direct.update(
  236. { _id: card._id },
  237. {
  238. $set: {
  239. type: 'cardType-card',
  240. linkedId: null,
  241. },
  242. },
  243. noValidate,
  244. );
  245. });
  246. });
  247. Migrations.add('add-custom-fields-to-cards', () => {
  248. Cards.update(
  249. {
  250. customFields: {
  251. $exists: false,
  252. },
  253. },
  254. {
  255. $set: {
  256. customFields: [],
  257. },
  258. },
  259. noValidateMulti,
  260. );
  261. });
  262. Migrations.add('add-requester-field', () => {
  263. Cards.update(
  264. {
  265. requestedBy: {
  266. $exists: false,
  267. },
  268. },
  269. {
  270. $set: {
  271. requestedBy: '',
  272. },
  273. },
  274. noValidateMulti,
  275. );
  276. });
  277. Migrations.add('add-assigner-field', () => {
  278. Cards.update(
  279. {
  280. assignedBy: {
  281. $exists: false,
  282. },
  283. },
  284. {
  285. $set: {
  286. assignedBy: '',
  287. },
  288. },
  289. noValidateMulti,
  290. );
  291. });
  292. Migrations.add('add-parent-field-to-cards', () => {
  293. Cards.update(
  294. {
  295. parentId: {
  296. $exists: false,
  297. },
  298. },
  299. {
  300. $set: {
  301. parentId: '',
  302. },
  303. },
  304. noValidateMulti,
  305. );
  306. });
  307. Migrations.add('add-subtasks-boards', () => {
  308. Boards.update(
  309. {
  310. subtasksDefaultBoardId: {
  311. $exists: false,
  312. },
  313. },
  314. {
  315. $set: {
  316. subtasksDefaultBoardId: null,
  317. subtasksDefaultListId: null,
  318. },
  319. },
  320. noValidateMulti,
  321. );
  322. });
  323. Migrations.add('add-subtasks-sort', () => {
  324. Boards.update(
  325. {
  326. subtaskSort: {
  327. $exists: false,
  328. },
  329. },
  330. {
  331. $set: {
  332. subtaskSort: -1,
  333. },
  334. },
  335. noValidateMulti,
  336. );
  337. });
  338. Migrations.add('add-subtasks-allowed', () => {
  339. Boards.update(
  340. {
  341. allowsSubtasks: {
  342. $exists: false,
  343. },
  344. },
  345. {
  346. $set: {
  347. allowsSubtasks: true,
  348. },
  349. },
  350. noValidateMulti,
  351. );
  352. });
  353. Migrations.add('add-subtasks-allowed', () => {
  354. Boards.update(
  355. {
  356. presentParentTask: {
  357. $exists: false,
  358. },
  359. },
  360. {
  361. $set: {
  362. presentParentTask: 'no-parent',
  363. },
  364. },
  365. noValidateMulti,
  366. );
  367. });
  368. Migrations.add('add-authenticationMethod', () => {
  369. Users.update(
  370. {
  371. authenticationMethod: {
  372. $exists: false,
  373. },
  374. },
  375. {
  376. $set: {
  377. authenticationMethod: 'password',
  378. },
  379. },
  380. noValidateMulti,
  381. );
  382. });
  383. Migrations.add('remove-tag', () => {
  384. Users.update(
  385. {},
  386. {
  387. $unset: {
  388. 'profile.tags': 1,
  389. },
  390. },
  391. noValidateMulti,
  392. );
  393. });
  394. Migrations.add('remove-customFields-references-broken', () => {
  395. Cards.update(
  396. { 'customFields.$value': null },
  397. {
  398. $pull: {
  399. customFields: { value: null },
  400. },
  401. },
  402. noValidateMulti,
  403. );
  404. });
  405. Migrations.add('add-product-name', () => {
  406. Settings.update(
  407. {
  408. productName: {
  409. $exists: false,
  410. },
  411. },
  412. {
  413. $set: {
  414. productName: '',
  415. },
  416. },
  417. noValidateMulti,
  418. );
  419. });
  420. Migrations.add('add-hide-logo', () => {
  421. Settings.update(
  422. {
  423. hideLogo: {
  424. $exists: false,
  425. },
  426. },
  427. {
  428. $set: {
  429. hideLogo: false,
  430. },
  431. },
  432. noValidateMulti,
  433. );
  434. });
  435. Migrations.add('add-displayAuthenticationMethod', () => {
  436. Settings.update(
  437. {
  438. displayAuthenticationMethod: {
  439. $exists: false,
  440. },
  441. },
  442. {
  443. $set: {
  444. displayAuthenticationMethod: true,
  445. },
  446. },
  447. noValidateMulti,
  448. );
  449. });
  450. Migrations.add('add-defaultAuthenticationMethod', () => {
  451. Settings.update(
  452. {
  453. defaultAuthenticationMethod: {
  454. $exists: false,
  455. },
  456. },
  457. {
  458. $set: {
  459. defaultAuthenticationMethod: 'password',
  460. },
  461. },
  462. noValidateMulti,
  463. );
  464. });
  465. Migrations.add('add-templates', () => {
  466. Boards.update(
  467. {
  468. type: {
  469. $exists: false,
  470. },
  471. },
  472. {
  473. $set: {
  474. type: 'board',
  475. },
  476. },
  477. noValidateMulti,
  478. );
  479. Swimlanes.update(
  480. {
  481. type: {
  482. $exists: false,
  483. },
  484. },
  485. {
  486. $set: {
  487. type: 'swimlane',
  488. },
  489. },
  490. noValidateMulti,
  491. );
  492. Lists.update(
  493. {
  494. type: {
  495. $exists: false,
  496. },
  497. swimlaneId: {
  498. $exists: false,
  499. },
  500. },
  501. {
  502. $set: {
  503. type: 'list',
  504. swimlaneId: '',
  505. },
  506. },
  507. noValidateMulti,
  508. );
  509. Users.find({
  510. 'profile.templatesBoardId': {
  511. $exists: false,
  512. },
  513. }).forEach(user => {
  514. // Create board and swimlanes
  515. Boards.insert(
  516. {
  517. title: TAPi18n.__('templates'),
  518. permission: 'private',
  519. type: 'template-container',
  520. members: [
  521. {
  522. userId: user._id,
  523. isAdmin: true,
  524. isActive: true,
  525. isNoComments: false,
  526. isCommentOnly: false,
  527. },
  528. ],
  529. },
  530. (err, boardId) => {
  531. // Insert the reference to our templates board
  532. Users.update(user._id, {
  533. $set: { 'profile.templatesBoardId': boardId },
  534. });
  535. // Insert the card templates swimlane
  536. Swimlanes.insert(
  537. {
  538. title: TAPi18n.__('card-templates-swimlane'),
  539. boardId,
  540. sort: 1,
  541. type: 'template-container',
  542. },
  543. (err, swimlaneId) => {
  544. // Insert the reference to out card templates swimlane
  545. Users.update(user._id, {
  546. $set: { 'profile.cardTemplatesSwimlaneId': swimlaneId },
  547. });
  548. },
  549. );
  550. // Insert the list templates swimlane
  551. Swimlanes.insert(
  552. {
  553. title: TAPi18n.__('list-templates-swimlane'),
  554. boardId,
  555. sort: 2,
  556. type: 'template-container',
  557. },
  558. (err, swimlaneId) => {
  559. // Insert the reference to out list templates swimlane
  560. Users.update(user._id, {
  561. $set: { 'profile.listTemplatesSwimlaneId': swimlaneId },
  562. });
  563. },
  564. );
  565. // Insert the board templates swimlane
  566. Swimlanes.insert(
  567. {
  568. title: TAPi18n.__('board-templates-swimlane'),
  569. boardId,
  570. sort: 3,
  571. type: 'template-container',
  572. },
  573. (err, swimlaneId) => {
  574. // Insert the reference to out board templates swimlane
  575. Users.update(user._id, {
  576. $set: { 'profile.boardTemplatesSwimlaneId': swimlaneId },
  577. });
  578. },
  579. );
  580. },
  581. );
  582. });
  583. });
  584. Migrations.add('fix-circular-reference_', () => {
  585. Cards.find().forEach(card => {
  586. if (card.parentId === card._id) {
  587. Cards.update(card._id, { $set: { parentId: '' } }, noValidateMulti);
  588. }
  589. });
  590. });
  591. Migrations.add('mutate-boardIds-in-customfields', () => {
  592. CustomFields.find().forEach(cf => {
  593. CustomFields.update(
  594. cf,
  595. {
  596. $set: {
  597. boardIds: [cf.boardId],
  598. },
  599. $unset: {
  600. boardId: '',
  601. },
  602. },
  603. noValidateMulti,
  604. );
  605. });
  606. });
  607. const modifiedAtTables = [
  608. AccountSettings,
  609. Actions,
  610. Activities,
  611. Announcements,
  612. Boards,
  613. CardComments,
  614. Cards,
  615. ChecklistItems,
  616. Checklists,
  617. CustomFields,
  618. Integrations,
  619. InvitationCodes,
  620. Lists,
  621. Rules,
  622. Settings,
  623. Swimlanes,
  624. Triggers,
  625. UnsavedEdits,
  626. Users,
  627. ];
  628. Migrations.add('add-missing-created-and-modified', () => {
  629. Promise.all(
  630. modifiedAtTables.map(db =>
  631. db
  632. .rawCollection()
  633. .update(
  634. { modifiedAt: { $exists: false } },
  635. { $set: { modifiedAt: new Date() } },
  636. { multi: true },
  637. )
  638. .then(() =>
  639. db
  640. .rawCollection()
  641. .update(
  642. { createdAt: { $exists: false } },
  643. { $set: { createdAt: new Date() } },
  644. { multi: true },
  645. ),
  646. ),
  647. ),
  648. )
  649. .then(() => {
  650. // eslint-disable-next-line no-console
  651. console.info('Successfully added createdAt and updatedAt to all tables');
  652. })
  653. .catch(e => {
  654. // eslint-disable-next-line no-console
  655. console.error(e);
  656. });
  657. });
  658. Migrations.add('fix-incorrect-dates', () => {
  659. const tables = [
  660. AccountSettings,
  661. Actions,
  662. Activities,
  663. Announcements,
  664. Boards,
  665. CardComments,
  666. Cards,
  667. ChecklistItems,
  668. Checklists,
  669. CustomFields,
  670. Integrations,
  671. InvitationCodes,
  672. Lists,
  673. Rules,
  674. Settings,
  675. Swimlanes,
  676. Triggers,
  677. UnsavedEdits,
  678. ];
  679. // Dates were previously created with Date.now() which is a number, not a date
  680. tables.forEach(t =>
  681. t
  682. .rawCollection()
  683. .find({ $or: [{ createdAt: { $type: 1 } }, { updatedAt: { $type: 1 } }] })
  684. .forEach(({ _id, createdAt, updatedAt }) => {
  685. t.rawCollection().update(
  686. { _id },
  687. {
  688. $set: {
  689. createdAt: new Date(createdAt),
  690. updatedAt: new Date(updatedAt),
  691. },
  692. },
  693. );
  694. }),
  695. );
  696. });
  697. Migrations.add('add-assignee', () => {
  698. Cards.update(
  699. {
  700. assignees: {
  701. $exists: false,
  702. },
  703. },
  704. {
  705. $set: {
  706. assignees: [],
  707. },
  708. },
  709. noValidateMulti,
  710. );
  711. });
  712. Migrations.add('add-profile-showDesktopDragHandles', () => {
  713. Users.update(
  714. {
  715. 'profile.showDesktopDragHandles': {
  716. $exists: false,
  717. },
  718. },
  719. {
  720. $set: {
  721. 'profile.showDesktopDragHandles': false,
  722. },
  723. },
  724. noValidateMulti,
  725. );
  726. });
  727. Migrations.add('add-profile-hiddenMinicardLabelText', () => {
  728. Users.update(
  729. {
  730. 'profile.hiddenMinicardLabelText': {
  731. $exists: false,
  732. },
  733. },
  734. {
  735. $set: {
  736. 'profile.hiddenMinicardLabelText': false,
  737. },
  738. },
  739. noValidateMulti,
  740. );
  741. });
  742. Migrations.add('add-receiveddate-allowed', () => {
  743. Boards.update(
  744. {
  745. allowsReceivedDate: {
  746. $exists: false,
  747. },
  748. },
  749. {
  750. $set: {
  751. allowsReceivedDate: true,
  752. },
  753. },
  754. noValidateMulti,
  755. );
  756. });
  757. Migrations.add('add-startdate-allowed', () => {
  758. Boards.update(
  759. {
  760. allowsStartDate: {
  761. $exists: false,
  762. },
  763. },
  764. {
  765. $set: {
  766. allowsStartDate: true,
  767. },
  768. },
  769. noValidateMulti,
  770. );
  771. });
  772. Migrations.add('add-duedate-allowed', () => {
  773. Boards.update(
  774. {
  775. allowsDueDate: {
  776. $exists: false,
  777. },
  778. },
  779. {
  780. $set: {
  781. allowsDueDate: true,
  782. },
  783. },
  784. noValidateMulti,
  785. );
  786. });
  787. Migrations.add('add-enddate-allowed', () => {
  788. Boards.update(
  789. {
  790. allowsEndDate: {
  791. $exists: false,
  792. },
  793. },
  794. {
  795. $set: {
  796. allowsEndDate: true,
  797. },
  798. },
  799. noValidateMulti,
  800. );
  801. });
  802. Migrations.add('add-members-allowed', () => {
  803. Boards.update(
  804. {
  805. allowsMembers: {
  806. $exists: false,
  807. },
  808. },
  809. {
  810. $set: {
  811. allowsMembers: true,
  812. },
  813. },
  814. noValidateMulti,
  815. );
  816. });
  817. Migrations.add('add-assignee-allowed', () => {
  818. Boards.update(
  819. {
  820. allowsAssignee: {
  821. $exists: false,
  822. },
  823. },
  824. {
  825. $set: {
  826. allowsAssignee: true,
  827. },
  828. },
  829. noValidateMulti,
  830. );
  831. });
  832. Migrations.add('add-labels-allowed', () => {
  833. Boards.update(
  834. {
  835. allowsLabels: {
  836. $exists: false,
  837. },
  838. },
  839. {
  840. $set: {
  841. allowsLabels: true,
  842. },
  843. },
  844. noValidateMulti,
  845. );
  846. });
  847. Migrations.add('add-checklists-allowed', () => {
  848. Boards.update(
  849. {
  850. allowsChecklists: {
  851. $exists: false,
  852. },
  853. },
  854. {
  855. $set: {
  856. allowsChecklists: true,
  857. },
  858. },
  859. noValidateMulti,
  860. );
  861. });
  862. Migrations.add('add-attachments-allowed', () => {
  863. Boards.update(
  864. {
  865. allowsAttachments: {
  866. $exists: false,
  867. },
  868. },
  869. {
  870. $set: {
  871. allowsAttachments: true,
  872. },
  873. },
  874. noValidateMulti,
  875. );
  876. });
  877. Migrations.add('add-comments-allowed', () => {
  878. Boards.update(
  879. {
  880. allowsComments: {
  881. $exists: false,
  882. },
  883. },
  884. {
  885. $set: {
  886. allowsComments: true,
  887. },
  888. },
  889. noValidateMulti,
  890. );
  891. });
  892. Migrations.add('add-assigned-by-allowed', () => {
  893. Boards.update(
  894. {
  895. allowsAssignedBy: {
  896. $exists: false,
  897. },
  898. },
  899. {
  900. $set: {
  901. allowsAssignedBy: true,
  902. },
  903. },
  904. noValidateMulti,
  905. );
  906. });
  907. Migrations.add('add-requested-by-allowed', () => {
  908. Boards.update(
  909. {
  910. allowsRequestedBy: {
  911. $exists: false,
  912. },
  913. },
  914. {
  915. $set: {
  916. allowsRequestedBy: true,
  917. },
  918. },
  919. noValidateMulti,
  920. );
  921. });
  922. Migrations.add('add-activities-allowed', () => {
  923. Boards.update(
  924. {
  925. allowsActivities: {
  926. $exists: false,
  927. },
  928. },
  929. {
  930. $set: {
  931. allowsActivities: true,
  932. },
  933. },
  934. noValidateMulti,
  935. );
  936. });
  937. Migrations.add('add-description-title-allowed', () => {
  938. Boards.update(
  939. {
  940. allowsDescriptionTitle: {
  941. $exists: false,
  942. },
  943. },
  944. {
  945. $set: {
  946. allowsDescriptionTitle: true,
  947. },
  948. },
  949. noValidateMulti,
  950. );
  951. });
  952. Migrations.add('add-description-text-allowed', () => {
  953. Boards.update(
  954. {
  955. allowsDescriptionText: {
  956. $exists: false,
  957. },
  958. },
  959. {
  960. $set: {
  961. allowsDescriptionText: true,
  962. },
  963. },
  964. noValidateMulti,
  965. );
  966. });
  967. Migrations.add('add-sort-field-to-boards', () => {
  968. Boards.find().forEach((board, index) => {
  969. if (!board.hasOwnProperty('sort')) {
  970. Boards.direct.update(board._id, { $set: { sort: index } }, noValidate);
  971. }
  972. });
  973. });
  974. Migrations.add('add-default-profile-view', () => {
  975. Users.find().forEach(user => {
  976. if (!user.hasOwnProperty('profile.boardView')) {
  977. // Set default view
  978. Users.direct.update(
  979. { _id: user._id },
  980. { $set: { 'profile.boardView': 'board-view-swimlanes' } },
  981. noValidate,
  982. );
  983. }
  984. });
  985. });
  986. Migrations.add('add-hide-logo-by-default', () => {
  987. Settings.update(
  988. {
  989. hideLogo: {
  990. hideLogo: false,
  991. },
  992. },
  993. {
  994. $set: {
  995. hideLogo: true,
  996. },
  997. },
  998. noValidateMulti,
  999. );
  1000. });