<commit_before>class CreateProfiles < ActiveRecord::Migration[5.2]
  def change
    create_table :profiles do |t|
      t.references :user, index: true, foreign_key: true
      t.string :display_name, length: 50
      t.string :description, length: 200, null: false, default: ''
      t.string :location, length: 72, null: false, default: ''
      t.string :website, null: false, default: ''
      t.string :motivation_header, null: false, default: ''

      t.timestamps
    end

    User.find_each do |user|
      Profile.create!(
        user_id: user.id,
        display_name: user.display_name,
        description: user.bio,
        location: user.location,
        website: user.website,
      )
    end<commit_msg>Use an INSERT INTO ... SELECT to move profile data and drop the old columns<commit_after>class CreateProfiles < ActiveRecord::Migration[5.2]
  def change
    create_table :profiles do |t|
      t.references :user, index: true, foreign_key: true
      t.string :display_name, length: 50
      t.string :description, length: 200, null: false, default: ''
      t.string :location, length: 72, null: false, default: ''
      t.string :website, null: false, default: ''
      t.string :motivation_header, null: false, default: ''

      t.timestamps
    end

    transaction do
      execute 'INSERT INTO profiles (user_id, display_name, description, location, website, motivation_header, created_at, updated_at) SELECT users.id as user_id, users.display_name, users.bio as description, users.location, users.website, users.motivation_header, users.created_at, users.updated_at FROM users;'

      remove_column :users, :display_name
      remove_column :users, :bio
      remove_column :users, :location
      remove_column :users, :website
      remove_column :users, :motivation_header
    end
{'fraction_non_alphanumeric': 0.1019845644983462, 'fraction_numerical': 0.009922822491730982, 'mean_word_length': 3.311163895486936, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2484153', 'n_tokens_mistral': 565, 'n_tokens_neox': 532, 'n_words': 162}