<commit_before># Models
require './lib/db/data_migration/comment'
require './lib/db/data_migration/notification'
require './lib/db/data_migration/submission'
require './lib/db/data_migration/team'
require './lib/db/data_migration/user'

# Helper classes
require './lib/db/data_migration/migration_periods'
require './lib/db/data_migration/timeframe'

class DataMigration
  def self.execute
    migrate_users
    migrate_submissions
    migrate_teams
    migrate_comments
    migrate_notifications
    # ...
  end

  def self.migrate_users
    timeframes.each do |timeframe|
      User.unmigrated_in(timeframe).each do |user|
        PGUser.create(user.pg_attributes)
      end
    end
  end

  def self.migrate_submissions
    timeframes.each do |timeframe|
      Submission.unmigrated_in(timeframe).each do |submission|
        pg_submission = PGSubmission.create(submission.pg_attributes)
        submission.viewers.each do |username|
          viewer = PGUser.find_by_username(username)
          SubmissionViewer.create(viewer_id: viewer.id, submission_id: pg_submission.id)
        end
        submission.muted_by.each do |username|
          user = PGUser.find_by_username(username)
          MutedSubmission.create(user_id: user.id, submission_id: pg_submission.id)
        end
      end
    end
  end

  def self.migrate_teams
    Team.unmigrated.each do |team|
      pg_team = PGTeam.create(team.pg_attributes)<commit_msg>Extract nested blocks in data migration<commit_after># Models
require './lib/db/data_migration/comment'
require './lib/db/data_migration/notification'
require './lib/db/data_migration/submission'
require './lib/db/data_migration/team'
require './lib/db/data_migration/user'

# Helper classes
require './lib/db/data_migration/migration_periods'
require './lib/db/data_migration/timeframe'

class DataMigration
  def self.execute
    migrate_users
    migrate_submissions
    migrate_teams
    migrate_comments
    migrate_notifications
    # ...
  end

  def self.migrate_users
    timeframes.each do |timeframe|
      User.unmigrated_in(timeframe).each do |user|
        PGUser.create(user.pg_attributes)
      end
    end
  end

  def self.migrate_submissions
    timeframes.each do |timeframe|
      Submission.unmigrated_in(timeframe).each do |submission|
        pg_submission = PGSubmission.create(submission.pg_attributes)
        migrate_submission_viewers(submission, pg_submission)
        migrate_muted_submissions(submission, pg_submission)
      end
    end
  end

  def self.migrate_submission_viewers(submission, pg_submission)
    submission.viewers.each do |username|
      viewer = PGUser.find_by_username(username)
      SubmissionViewer.create(viewer_id: viewer.id, submission_id: pg_submission.id)
    end
  end

  def self.migrate_muted_submissions(submission, pg_submission)
    submission.muted_by.each do |username|
      user = PGUser.find_by_username(username)
      MutedSubmission.create(user_id: user.id, submission_id: pg_submission.id)
    end
  end

  def self.migrate_teams
    Team.unmigrated.each do |team|
      pg_team = PGTeam.create(team.pg_attributes)
{'fraction_non_alphanumeric': 0.0877642536835362, 'fraction_numerical': 0.0, 'mean_word_length': 3.5657894736842106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1274129', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1047, 'n_words': 176}