<commit_before>Sequel.migration do
  up do
    create_table :revisions do
      primary_key :id

      Time :created_at

      foreign_key :user_id,
        :users,
        :on_delete => :cascade,
        :on_update => :cascade,
        :key       => :id

      foreign_key :section_entry_id,
        :section_entries,
        :on_delete => :cascade,
        :on_update => :cascade,
        :key       => :id
    end

    alter_table :section_entries do
      add_foreign_key :revision_id, :revisions,
        :on_update => :cascade,
        :on_delete => :cascade,
        :key       => :id
    end

    alter_table :custom_field_values do
      add_foreign_key :revision_id, :revisions,
        :on_update => :cascade,
        :on_delete => :cascade,
        :key       => :id
    end

    # Create a revision for each existing entry.
    entries = Zen.database[:section_entries] \
      .select(:id, :user_id) \
      .order(:id.asc)

    entries.each do |entry|
      rev_id = Zen.database[:revisions].insert(
        :created_at       => Time.now,
        :user_id          => entry[:user_id],
        :section_entry_id => entry[:id]
      )

      Zen.database[:section_entries] \
        .filter(:id => entry[:id]) \
        .update(:revision_id => rev_id)

      Zen.database[:custom_field_values] \<commit_msg>Update the migration for revisions.<commit_after>Sequel.migration do
  up do
    create_table :revisions do
      primary_key :id

      Time :created_at

      foreign_key :user_id,
        :users,
        :on_delete => :cascade,
        :on_update => :cascade,
        :key       => :id

      foreign_key :section_entry_id,
        :section_entries,
        :on_delete => :cascade,
        :on_update => :cascade,
        :key       => :id
    end

    alter_table :section_entries do
      add_foreign_key :revision_id, :revisions,
        :on_update => :cascade,
        :on_delete => :set_null,
        :key       => :id
    end

    alter_table :custom_field_values do
      add_foreign_key :revision_id, :revisions,
        :on_update => :cascade,
        :on_delete => :cascade,
        :key       => :id
    end

    # Create a revision for each existing entry.
    entries = Zen.database[:section_entries] \
      .select(:id, :user_id) \
      .order(:id.asc)

    entries.each do |entry|
      rev_id = Zen.database[:revisions].insert(
        :created_at       => Time.now,
        :user_id          => entry[:user_id],
        :section_entry_id => entry[:id]
      )

      Zen.database[:section_entries] \
        .filter(:id => entry[:id]) \
        .update(:revision_id => rev_id)

      Zen.database[:custom_field_values] \
{'fraction_non_alphanumeric': 0.1176249530251785, 'fraction_numerical': 0.0, 'mean_word_length': 2.01131221719457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '7057356', 'n_tokens_mistral': 882, 'n_tokens_neox': 852, 'n_words': 174}