migrations.js 27 KB

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