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

Add quiz migration #7123

Merged
merged 13 commits into from
Sep 4, 2023
Merged

Add quiz migration #7123

merged 13 commits into from
Sep 4, 2023

Conversation

m1r0
Copy link
Member

@m1r0 m1r0 commented Aug 24, 2023

Resolves #5438

Proposed Changes

  • Add a migration that migrates all the quiz data into the custom tables.
  • Update the migration job scheduler to run multiple jobs, one after another.
  • Refactor the migrations code a bit.

Testing Instructions

  1. Have some quiz entries.
  2. Enable the feature: add_filter( 'sensei_feature_flag_tables_based_progress', '__return_true' );.
  3. Go to Sensei LMS -> Tools.
  4. Run Migrate comment-based progress.
  5. It should first migrate the student progress progress and then run the quiz migration.
  6. Check the quiz tables and verify that the data is correct.
  7. To rerun the migration, truncate the tables and delete the sensei_migrated_quiz_last_comment_id option.

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Acceptance criteria is met
  • Decisions are publicly documented
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • New UIs match the designs
  • Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • Code is tested on the minimum supported PHP and WordPress versions
  • User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • "Needs Documentation" label is added if this change requires updates to documentation
  • Known issues are created as new GitHub issues

@m1r0 m1r0 self-assigned this Aug 24, 2023
@m1r0 m1r0 added this to the 4.16.2 milestone Aug 24, 2023
@github-actions
Copy link

github-actions bot commented Aug 24, 2023

WordPress Dependencies Report

The github-action-wordpress-dependencies-report action has detected some script changes between the commit d8ec1c6 and trunk. Please review and confirm the following are correct before merging.

No changes detected in the current commit. But the comment was left so it is possible to check for the edit history.

This comment was automatically generated by the github-action-wordpress-dependencies-report action.

Base automatically changed from add/recurring-job to trunk August 28, 2023 12:56
@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Merging #7123 (d8ec1c6) into trunk (c3b56a7) will increase coverage by 0.12%.
Report is 96 commits behind head on trunk.
The diff coverage is 80.83%.

Impacted file tree graph

@@             Coverage Diff              @@
##              trunk    #7123      +/-   ##
============================================
+ Coverage     49.47%   49.60%   +0.12%     
- Complexity    10569    10609      +40     
============================================
  Files           578      580       +2     
  Lines         44602    44791     +189     
  Branches        402      402              
============================================
+ Hits          22069    22220     +151     
- Misses        22206    22244      +38     
  Partials        327      327              
Files Changed Coverage Δ
includes/class-sensei.php 22.98% <0.00%> (-0.16%) ⬇️
...es/internal/migration/class-migration-abstract.php 0.00% <0.00%> (ø)
...cludes/internal/migration/class-migration-tool.php 100.00% <ø> (ø)
...on/migrations/class-student-progress-migration.php 82.97% <66.66%> (ø)
...rnal/migration/migrations/class-quiz-migration.php 79.88% <79.88%> (ø)
...ternal/migration/class-migration-job-scheduler.php 100.00% <100.00%> (ø)
...ncludes/internal/migration/class-migration-job.php 100.00% <100.00%> (ø)

... and 10 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c3b56a7...d8ec1c6. Read the comment docs.

@m1r0 m1r0 marked this pull request as ready for review August 31, 2023 18:22
@m1r0 m1r0 requested a review from a team August 31, 2023 18:23
merkushin
merkushin previously approved these changes Sep 1, 2023
Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

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

Thanks @m1r0!

Looks working. I left a few minor comments. None is blocking.

Now we need the verification tool to be sure everything migrated properly 😅

$this->migration = $migration;
$this->job_name = 'progress_migration';
$this->name = strtolower(
( new ReflectionClass( $migration ) )->getShortName()
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to replace this reflection with a public method in a migration.

  1. Reflection is more expensive. But in our case it isn't so important.
  2. That's an "implicit interface". Trying to find an analogy, I though up a terrible parallel that I don't want to share 😅 Anyway, I prefer explicit over implicit.
    What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes perfect sense. Fixed in e7332eb.

*
* @return string
*/
public function target_version(): string {
Copy link
Member

Choose a reason for hiding this comment

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

Initially, I though we'll use these migrations as part of the installation/update process.
But we decided it is important to do them manually.
Do we still need this method then? Maybe we can remove them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's not needed so I've removed it in a993d34.

);

if ( $this->dry_run ) {
echo esc_html( $comments_query . "\n" );
Copy link
Member

Choose a reason for hiding this comment

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

Is it supposed to be run in console or only in web?
esc_html is not a good escaping function for console :)
And for the web the line ending isn't suitable :)
However, we can consider that as a tradeoff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, you're right. I've made it consistent with the other migration but we should revisit this once we have a CLI command that actually uses the dry run feature. At this stage, we can consider it as a placeholder. 🙂

@m1r0 m1r0 requested a review from merkushin September 4, 2023 15:55
Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

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

👍

@m1r0 m1r0 merged commit 10761b9 into trunk Sep 4, 2023
24 checks passed
@m1r0 m1r0 deleted the add/quiz-migration branch September 4, 2023 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a migration that copies the quiz data to the new tables
2 participants