<commit_before>RSpec.shared_context 'database' do
  let(:configuration) { ROM::Configuration.new(:sql, uri) }
  let(:conn) { configuration.gateways[:default].connection }
  let(:rom) { ROM.container(configuration) }
  let(:uri) do
    if defined? JRUBY_VERSION
      'jdbc:postgresql://localhost/rom_repository'
    else
      'postgres://localhost/rom_repository'
    end
  end

  before do
    conn.loggers << LOGGER

    [:tags, :tasks, :posts, :users, :posts_labels, :labels, :books,
     :reactions, :messages].each { |table| conn.drop_table?(table) }

    conn.create_table :books do
      primary_key :id
      column :title, String
      column :created_at, Time
      column :updated_at, Time
    end

    conn.create_table :users do
      primary_key :id
      column :name, String
    end

    conn.create_table :tasks do
      primary_key :id
      foreign_key :user_id, :users, null: false, on_delete: :cascade
      column :title, String
    end

    conn.create_table :tags do
      primary_key :id
      foreign_key :task_id, :tasks, null: false, on_delete: :cascade
      column :name, String
    end

    conn.create_table :labels do
      primary_key :id
      column :name, String
    end

    conn.create_table :posts do
      primary_key :id
      foreign_key :author_id, :users, null: false, on_delete: :cascade
      column :title, String, null: false
      column :body, String
    end

    conn.create_table :posts_labels do
      foreign_key :post_id, :labels, null: false, on_delete: :cascade
      foreign_key :label_id, :labels, null: false, on_delete: :cascade
      primary_key [:post_id, :label_id]
    end

    conn.create_table :messages do
      primary_key :message_id
      column :author, String
      column :body, String
    end

    conn.create_table :reactions do
      primary_key :reaction_id
      foreign_key :message_id, :messages, null: false
      column :author, String
    end
  end
end<commit_msg>Disconnect container after spec examples finish<commit_after>RSpec.shared_context 'database' do
  let(:configuration) { ROM::Configuration.new(:sql, uri) }
  let(:conn) { configuration.gateways[:default].connection }
  let(:rom) { ROM.container(configuration) }
  let(:uri) do
    if defined? JRUBY_VERSION
      'jdbc:postgresql://localhost/rom_repository'
    else
      'postgres://localhost/rom_repository'
    end
  end

  before do
    conn.loggers << LOGGER

    [:tags, :tasks, :posts, :users, :posts_labels, :labels, :books,
     :reactions, :messages].each { |table| conn.drop_table?(table) }

    conn.create_table :books do
      primary_key :id
      column :title, String
      column :created_at, Time
      column :updated_at, Time
    end

    conn.create_table :users do
      primary_key :id
      column :name, String
    end

    conn.create_table :tasks do
      primary_key :id
      foreign_key :user_id, :users, null: false, on_delete: :cascade
      column :title, String
    end

    conn.create_table :tags do
      primary_key :id
      foreign_key :task_id, :tasks, null: false, on_delete: :cascade
      column :name, String
    end

    conn.create_table :labels do
      primary_key :id
      column :name, String
    end

    conn.create_table :posts do
      primary_key :id
      foreign_key :author_id, :users, null: false, on_delete: :cascade
      column :title, String, null: false
      column :body, String
    end

    conn.create_table :posts_labels do
      foreign_key :post_id, :labels, null: false, on_delete: :cascade
      foreign_key :label_id, :labels, null: false, on_delete: :cascade
      primary_key [:post_id, :label_id]
    end

    conn.create_table :messages do
      primary_key :message_id
      column :author, String
      column :body, String
    end

    conn.create_table :reactions do
      primary_key :reaction_id
      foreign_key :message_id, :messages, null: false
      column :author, String
    end
  end

  after do
    rom.disconnect
  end
end
{'fraction_non_alphanumeric': 0.09393099974817426, 'fraction_numerical': 0.0, 'mean_word_length': 2.9171597633136095, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2724115', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1241, 'n_words': 348}