migrations.js 26 KB

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