migrations.js 23 KB

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