migrations.js 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  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. });
  1041. Migrations.add('add-card-details-show-lists', () => {
  1042. Boards.update(
  1043. {
  1044. allowsShowLists: {
  1045. $exists: false,
  1046. },
  1047. },
  1048. {
  1049. $set: {
  1050. allowsShowLists: true,
  1051. },
  1052. },
  1053. noValidateMulti,
  1054. );
  1055. });