migrations.js 27 KB

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