<commit_before>class CreateElasticProductState < ActiveRecord::Migration
  def up
    create_table :solidus_elastic_product_states do |t|
      t.belongs_to :product, null: false, index: true, unique: true
      t.text :json, limit: (16.megabytes - 1)
      t.boolean :uploaded, default: false, null: false
      t.datetime :locked_for_serialization_at, :locked_for_upload_at

      t.index [:json, :locked_for_serialization_at], name: 'serialization_lookup', length: { json: 1 }
      t.index [:uploaded, :locked_for_upload_at, :json], name: 'upload_lookup', length: { json: 1 }
    end
    execute "INSERT INTO #{Solidus::ElasticProduct::State.table_name} (product_id) SELECT id FROM #{Spree::Product.table_name}"
  end

  def down
    drop_table :solidus_elastic_product_states
  end
end<commit_msg>Correct migration to handle postgres pecularities<commit_after>class CreateElasticProductState < ActiveRecord::Migration
  def up
    create_table :solidus_elastic_product_states do |t|
      t.belongs_to :product, null: false, index: true, unique: true
      t.text :json, limit: (16.megabytes - 1)
      t.boolean :uploaded, default: false, null: false, index: true
      t.datetime :locked_for_serialization_at
      t.datetime :locked_for_upload_at, index: true

      t.index :locked_for_serialization_at, name: 'index_states_on_locked_for_serialization_at'
      t.index :json, where: 'json is null'
    end

    # to get out of a transaction
    execute("commit;")

    execute "INSERT INTO #{Solidus::ElasticProduct::State.table_name} (product_id) SELECT id FROM #{Spree::Product.table_name}"
  end

  def down
    drop_table :solidus_elastic_product_states
  end
end
{'fraction_non_alphanumeric': 0.09660107334525939, 'fraction_numerical': 0.004770423375074538, 'mean_word_length': 4.43042071197411, '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': '1886611', 'n_tokens_mistral': 556, 'n_tokens_neox': 532, 'n_words': 139}