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 #208) #213

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

New: Migration Scripts (fixes #208) #213

wants to merge 17 commits into from

Conversation

joe-replin
Copy link
Contributor

New

Testing

Test using this branch of the Adapt Framework which includes the scripts that handle the migration.
adaptlearning/adapt_framework#3633

@joe-replin joe-replin self-assigned this Jan 30, 2025
Copy link
Contributor

@chris-steele chris-steele left a comment

Choose a reason for hiding this comment

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

Good work on a tricky customer @joe-replin; just added a few suggestions.

@@ -0,0 +1,225 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';

describe('adapt-contrib-assessment - v2.0.0 > v2.0.3', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think references to v2.0.0 should be v2.0.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to double check, I have been starting mine at 2.0.0 per the discussion here. Happy to start at 2.0.1, but I don't think that's what we agreed upon.
adaptlearning/adapt-contrib-accordion#159 (comment)

Copy link
Contributor

@chris-steele chris-steele Feb 14, 2025

Choose a reason for hiding this comment

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

Sorry, meant to say should this use 2.0.0 as this supports framework v2 (there is no v2.0.0)

migrations/v2.js Outdated

checkContent('adapt-contrib-assessment - check assessment._questions._canShowModelAnswer attribute', async () => {
const isValid = assessments.every(assessment =>
assessment._questions.every(item =>
Copy link
Contributor

Choose a reason for hiding this comment

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

assessment._questions.every(item => item._canShowModelAnswer) is a little shorter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess what I'm trying to achieve here is the possibility that there may be multiple assessments in a given build. So first, I want to grab all the assessments and then look for every instance of assessment._questions within each possible assessment. Most of the time there will only be 1 assessment, but we do allow multiple.

Copy link
Member

Choose a reason for hiding this comment

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

Why is !== false necessary when item._canShowModelAnswer would be a truthy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see now.

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

updatePlugin('adapt-contrib-assessment - update to v2.1.0', { name: 'adapt-contrib-assessment', version: '2.1.0', framework: '>=2.0.18' });
Copy link
Contributor

Choose a reason for hiding this comment

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

The update to v2.1.0 requires framework v2.1.3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good looking out. Thanks.

migrations/v2.js Outdated
});

checkContent('adapt-contrib-assessment - check assessment._requireAssessmentPassed attribute', async () => {
const isValid = assessments.every(assessment =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to go with convention, perhaps: const isValid = assessments.every(assessment => !_.has(assessment, '_requireAssessmentPassed'));

Copy link
Contributor Author

@joe-replin joe-replin Feb 18, 2025

Choose a reason for hiding this comment

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

Thanks. Not super familiar with lodash helpers. But will apply this to other, similar delete modifications.

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

updatePlugin('adapt-contrib-assessment - update to v2.1.1', { name: 'adapt-contrib-assessment', version: '2.1.1', framework: '>=2.0.18' });
Copy link
Contributor

Choose a reason for hiding this comment

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

The update to v2.1.1 requires framework v2.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

migrations/v3.js Outdated
});

checkContent('adapt-contrib-assessment - check course._postTotalScoreToLms attribute', async () => {
const isValid = !assessmentConfig._postTotalScoreToLms;
Copy link
Contributor

Choose a reason for hiding this comment

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

const isValid = !_.has(assessmentConfig, '_postTotalScoreToLms');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

migrations/v4.js Outdated
});

describe('adapt-contrib-assessment - v4.3.0 > v4.4.0', async () => {
let course, assessmentConfig, assessments;
Copy link
Contributor

@chris-steele chris-steele Feb 12, 2025

Choose a reason for hiding this comment

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

assessments isn't initialized in this block

Copy link
Contributor Author

@joe-replin joe-replin Feb 18, 2025

Choose a reason for hiding this comment

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

What about the _scoreToPass and _correctToPass where it is used?

migrations/v4.js Outdated
/**
* * Add JSON field and set attribute.
*/
mutateContent('adapt-contrib-assessment - add assessment._scoreToPass', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this have been _correctToPass and on assessmentConfig?

whereContent('adapt-contrib-assessment - where assessment', async content => {
course = content.filter(({ _type }) => _type === 'course');
assessmentConfig = course.find(({ _assessment }) => _assessment);
if (assessmentConfig) 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.

I think the _assessment configuration in course is optional, so we would still want to run the migrations on the _assessment configurations in articles

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the mutations taking place within this describe statement is at the course level per the previous comment about switching _correctToPass and _scoreToPass to assessmentConfig.

migrations/v4.js Outdated
/**
* * Add JSON field and set attribute.
*/
mutateContent('adapt-contrib-assessment - modify assessment._questions._resetType value', async () => {
Copy link
Contributor

@chris-steele chris-steele Feb 12, 2025

Choose a reason for hiding this comment

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

I think your caution is justified; as with not changing boolean defaults, we should only change enumerated types if the default becomes invalid (and the invalid value is used). I would therefore remove this migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

migrations/v2.js Outdated
Comment on lines 8 to 12
whereContent('adapt-contrib-assessment - where assessment', async content => {
articles = content.filter(({ _type }) => _type === 'article');
assessments = articles.filter(({ _type, _assessment }) => _type === 'article' && _assessment !== undefined);
return assessments.length;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably simplify this further to a single filter.

Thoughts on changing assessments to assessmentArticles?

Suggested change
whereContent('adapt-contrib-assessment - where assessment', async content => {
articles = content.filter(({ _type }) => _type === 'article');
assessments = articles.filter(({ _type, _assessment }) => _type === 'article' && _assessment !== undefined);
return assessments.length;
});
whereContent('adapt-contrib-assessment - where assessment', async content => {
assessmentArticles = content.filter(({ _type, _assessment }) => _type === 'article' && _assessment !== undefined);
return assessments.length;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call.

migrations/v4.js Outdated
Comment on lines 22 to 24
const isValid = assessments.every(assessment =>
assessment._scrollToOnReset === false
);
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
const isValid = assessments.every(assessment =>
assessment._scrollToOnReset === false
);
const isValid = assessments.every(({ assessment }) =>
assessment._scrollToOnReset === false
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in a separate commit.

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

Successfully merging this pull request may close these issues.

Add Migration Scripts
4 participants