migrations.js 28 KB

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