migrations.js 22 KB

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