migrations.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  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 Boards from '../models/boards';
  9. import CardComments from '../models/cardComments';
  10. import Cards from '../models/cards';
  11. import ChecklistItems from '../models/checklistItems';
  12. import Checklists from '../models/checklists';
  13. import CustomFields from '../models/customFields';
  14. import Integrations from '../models/integrations';
  15. import InvitationCodes from '../models/invitationCodes';
  16. import Lists from '../models/lists';
  17. import Rules from '../models/rules';
  18. import Settings from '../models/settings';
  19. import Swimlanes from '../models/swimlanes';
  20. import Triggers from '../models/triggers';
  21. import UnsavedEdits from '../models/unsavedEdits';
  22. import Users from '../models/users';
  23. // Anytime you change the schema of one of the collection in a non-backward
  24. // compatible way you have to write a migration in this file using the following
  25. // API:
  26. //
  27. // Migrations.add(name, migrationCallback, optionalOrder);
  28. // Note that we have extra migrations defined in `sandstorm.js` that are
  29. // exclusive to Sandstorm and shouldn’t be executed in the general case.
  30. // XXX I guess if we had ES6 modules we could
  31. // `import { isSandstorm } from sandstorm.js` and define the migration here as
  32. // well, but for now I want to avoid definied too many globals.
  33. // In the context of migration functions we don't want to validate database
  34. // mutation queries against the current (ie, latest) collection schema. Doing
  35. // that would work at the time we write the migration but would break in the
  36. // future when we'll update again the concerned collection schema.
  37. //
  38. // To prevent this bug we always have to disable the schema validation and
  39. // argument transformations. We generally use the shorthandlers defined below.
  40. const noValidate = {
  41. validate: false,
  42. filter: false,
  43. autoConvert: false,
  44. removeEmptyStrings: false,
  45. getAutoValues: false,
  46. };
  47. const noValidateMulti = { ...noValidate, multi: true };
  48. Migrations.add('board-background-color', () => {
  49. const defaultColor = '#16A085';
  50. Boards.update(
  51. {
  52. background: {
  53. $exists: false,
  54. },
  55. },
  56. {
  57. $set: {
  58. background: {
  59. type: 'color',
  60. color: defaultColor,
  61. },
  62. },
  63. },
  64. noValidateMulti,
  65. );
  66. });
  67. Migrations.add('lowercase-board-permission', () => {
  68. ['Public', 'Private'].forEach(permission => {
  69. Boards.update(
  70. { permission },
  71. { $set: { permission: permission.toLowerCase() } },
  72. noValidateMulti,
  73. );
  74. });
  75. });
  76. /*
  77. // Security migration: see https://github.com/wekan/wekan/issues/99
  78. Migrations.add('change-attachments-type-for-non-images', () => {
  79. const newTypeForNonImage = 'application/octet-stream';
  80. Attachments.find().forEach(file => {
  81. if (!file.isImage()) {
  82. Attachments.update(
  83. file._id,
  84. {
  85. $set: {
  86. 'original.type': newTypeForNonImage,
  87. 'copies.attachments.type': newTypeForNonImage,
  88. },
  89. },
  90. noValidate,
  91. );
  92. }
  93. });
  94. });
  95. Migrations.add('card-covers', () => {
  96. Cards.find().forEach(card => {
  97. const cover = Attachments.findOne({ cardId: card._id, cover: true });
  98. if (cover) {
  99. Cards.update(card._id, { $set: { coverId: cover._id } }, noValidate);
  100. }
  101. });
  102. Attachments.update({}, { $unset: { cover: '' } }, noValidateMulti);
  103. });
  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(
  1061. 'adapt-attachments-to-ostrio-files-api-using-meta-and-drp-cfs-leacy',
  1062. () => {
  1063. Attachments.find().forEach(file => {
  1064. Attachments.update(
  1065. file._id,
  1066. {
  1067. $set: {
  1068. 'meta.boardId': file.boardId,
  1069. 'meta.cardId': file.cardId,
  1070. 'meta.listId': file.listId,
  1071. 'meta.swimlaneId': file.swimlaneId,
  1072. },
  1073. },
  1074. noValidate,
  1075. );
  1076. });
  1077. Attachments.update(
  1078. {},
  1079. {
  1080. $unset: {
  1081. original: '', // cfs:* legacy
  1082. copies: '', // cfs:* legacy
  1083. failures: '', // cfs:* legacy
  1084. boardId: '',
  1085. cardId: '',
  1086. listId: '',
  1087. swimlaneId: '',
  1088. },
  1089. },
  1090. noValidateMulti,
  1091. );
  1092. },
  1093. );