migrations.js 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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('fix-incorrect-dates', () => {
  976. cas = CFSAttachments.find();
  977. console.log('cas', cas);
  978. });
  979. import { MongoInternals } from 'meteor/mongo';
  980. Migrations.add('change-attachment-library', () => {
  981. const http = require('http');
  982. const fs = require('fs');
  983. CFSAttachments.find().forEach(file => {
  984. const bucket = new MongoInternals.NpmModule.GridFSBucket(MongoInternals.defaultRemoteCollectionDriver().mongo.db, {bucketName: 'cfs_gridfs.attachments'});
  985. const gfsId = new MongoInternals.NpmModule.ObjectID(file.copies.attachments.key);
  986. const reader = bucket.openDownloadStream(gfsId);
  987. const path = `/var/attachments/${file.name()}`;
  988. const fd = fs.createWriteStream(path);
  989. reader.pipe(fd);
  990. let opts = {
  991. fileName: file.name(),
  992. type: file.type(),
  993. fileId: file._id,
  994. meta: {
  995. userId: file.userId,
  996. boardId: file.boardId,
  997. cardId: file.cardId
  998. }
  999. };
  1000. if (file.listId) {
  1001. opts.meta.listId = file.listId;
  1002. }
  1003. if (file.swimlaneId) {
  1004. opts.meta.swimlaneId = file.swimlaneId;
  1005. }
  1006. Attachments.addFile(path, opts, (err, fileRef) => {
  1007. if (err) {
  1008. console.log('error when migrating ', fileName, err);
  1009. } else {
  1010. file.remove();
  1011. }
  1012. });
  1013. });
  1014. });