migrations.js 26 KB

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