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 added to repo (fixes #208) #209

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

chris-steele
Copy link
Contributor

#208

New

  • migration scripts added to repo

@chris-steele chris-steele marked this pull request as draft January 29, 2025 08:38
@chris-steele chris-steele marked this pull request as ready for review January 29, 2025 10:31
@chris-steele chris-steele marked this pull request as draft January 29, 2025 16:22
@chris-steele chris-steele marked this pull request as ready for review February 4, 2025 09:58
Copy link
Contributor

@joe-allen-89 joe-allen-89 left a comment

Choose a reason for hiding this comment

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

A couple of changes for using the new helpers, and a couple of queries on best practice but all looking good.

migrations/v6.js Outdated
Comment on lines 1 to 7
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
import _ from 'lodash';

const getCourse = content => {
const course = content.find(({ _type }) => _type === 'course');
return course;
};
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
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
import _ from 'lodash';
const getCourse = content => {
const course = content.find(({ _type }) => _type === 'course');
return course;
};
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getCourse } from 'adapt-migrations';
import _ from 'lodash';

migrations/v6.js Outdated
Comment on lines 9 to 11
const getGlobals = content => {
return getCourse(content)?._globals?._menu?._boxMenu;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

As you've added a mutate for checking globals exists I don't think the getGlobals function is needed here, could be kept inline.

Comment on lines +62 to +65
mutateContent('Box menu - add _graphic attribute', async (content) => {
course._boxMenu._graphic = defaultGraphic;
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.

@chris-steele Thoughts on splitting these into two mutates as there's two attributes in the object? Or as it's setting a single attribute leave it as one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could argue that you are adding a single attribute; it just happens to be of type object. I'd say let's leave as is otherwise we might fall on the sword of consistency elsewhere where there are tons of new properties which will make for a very verbose script.

migrations/v6.js Outdated
whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' });

whereContent('Box menu - where course has _backgroundImage', async (content) => {
course = getCourse(content);
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
course = getCourse(content);
course = getCourse();

migrations/v4.js Outdated
Comment on lines 28 to 44
mutateContent('Box menu - remove globals', async (content) => {
delete courseBoxMenuGlobals.ariaRegion;
delete courseBoxMenuGlobals.menuItem;
delete courseBoxMenuGlobals.menuEnd;
return true;
});

checkContent('Box menu - check globals', async (content) => {
const globals = getGlobals(content);
const isValid = (
Object.hasOwn(globals, 'ariaRegion') === false &&
Object.hasOwn(globals, 'menuItem') === false &&
Object.hasOwn(globals, 'menuEnd') === false
);
if (!isValid) throw new Error('Box menu - global attributes ariaRegion menuItem menuEnd');
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.

Similar to another comment, best practice on seperating these rather than in one mutate/check?

migrations/v2.js Outdated
let course, courseBoxMenuGlobals;
const durationLabel = 'Duration:';

whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Just so we're not migrating anything earlier than v2

Suggested change
whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' });
whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '>=2.0.0 <2.0.3' });

migrations/v6.js Outdated
let course, courseBoxMenuGlobals;
const itemCount = 'Item {{_nthChild}} of {{_totalChild}}';

whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: '<v6.3.10' });
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
whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: '<v6.3.10' });
whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: '<6.3.10' });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the reason for this suggestion @joe-allen-89 ? v6.3.10 is a valid release/tag

Copy link
Contributor

Choose a reason for hiding this comment

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

@chris-steele it throws an error as invalid version number as it fails VERSION_CHECK

Copy link
Member

@oliverfoster oliverfoster Feb 21, 2025

Choose a reason for hiding this comment

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

We're not comparing release tags, we're comparing valid semver version numbers with semver ranges. They don't have a v on the front. Think package.json:version not GitHub tags

migrations/v6.js Outdated
return true;
});

updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' });
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('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' });
updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: '6.3.10', framework: '">=5.24.2' });

migrations/v4.js Outdated
});

checkContent('Box menu - check global attribute menuEnd', async (content) => {
const isValid = Object.hasOwn(courseBoxMenuGlobals, 'menuEnd') === false;
Copy link
Member

@oliverfoster oliverfoster Feb 21, 2025

Choose a reason for hiding this comment

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

Because boolean === false is the same as !booleanwhat you've got here is:

if ((Object.hasOwn(courseBoxMenuGlobals, 'menuEnd') === false) === false) throw...

Object.has('') returns a Boolean that you're flipping twice. Which is a bit weird. You could instead change the variable name to isInvalid to suit the throw early rather than having if (!isValid) throw... or instead just return true early with if (isValid) return true;.

    const isInvalid = Object.hasOwn(courseBoxMenuGlobals, 'menuEnd');
    if (isInvalid) throw....
    return true;
    const isValid = !Object.hasOwn(courseBoxMenuGlobals, 'menuEnd');
    if (isValid) return true;
    throw...

You can use ! to flip Booleans rather than === false or !== true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Reviewing
Development

Successfully merging this pull request may close these issues.

3 participants