Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Migration Scripts (fixes #57) #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions migrations/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';

describe('adapt-contrib-blank - v2.0.0 > v4.1.3', async () => {
let blanks;

whereFromPlugin('adapt-contrib-blank - from v2.0.0', { name: 'adapt-contrib-blank', version: '<=4.1.3' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to check if it's lower than the version we're updating to not equal to. Either '<4.1.3' or '<= 4.1.2'.

Suggested change
whereFromPlugin('adapt-contrib-blank - from v2.0.0', { name: 'adapt-contrib-blank', version: '<=4.1.3' });
whereFromPlugin('adapt-contrib-blank - from v2.0.0', { name: 'adapt-contrib-blank', version: '<4.1.3' });


whereContent('adapt-contrib-blank - where blank', async content => {
blanks = content.filter(({ _component }) => _component === 'blank');
if (blanks) return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per Ollie's suggestion (adaptlearning/adapt-contrib-accordion#159 (comment)) to condense these checks slightly suggested tweek

Suggested change
if (blanks) return true;
return blanks.length

});

/**
* * Add JSON field to component and set attribute.
*/
mutateContent('adapt-contrib-blank - add blank._isOptional', async () => {
blanks.forEach(blank => {
blank._isOptional = true;
});
return true;
});

checkContent('adapt-contrib-blank - check blank._isOptional atrribute', async () => {
const isValid = blanks.every(({ _isOptional }) => _isOptional === true);
if (!isValid) throw new Error('adapt-contrib-blank - _isOptional not added to every instance of blank');
return true;
});

updatePlugin('adapt-contrib-blank - update to v4.1.3', { name: 'adapt-contrib-blank', version: '4.1.3', framework: '>=4' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updatePlugin('adapt-contrib-blank - update to v4.1.3', { name: 'adapt-contrib-blank', version: '4.1.3', framework: '>=4' });
updatePlugin('adapt-contrib-blank - update to v4.1.3', { name: 'adapt-contrib-blank', version: '4.1.3', framework: '>=5.19.1' });

});
Loading