migrations.js 22 KB

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