<commit_before>---
- block:
  - name: List all schemas in the fpsd database.
    command: psql -c '\dn' fpsd
    register: schemas
    changed_when: false

  - name: Create the raw schema.
    command: psql -c 'CREATE SCHEMA raw;'
    when: "'raw' not in schemas.stdout"

  - name: List all tables in the raw schema.
    command: psql -c '\dt raw.*'
    register: tables
    changed_when: false

  - name: "Create the tables: crawls, hs_history, frontpage_examples, & frontpage_traces."
    command: psql -c '{{ lookup("file", item) }}'
    with_items: "{{ fpsd_database_raw_schema_tables }}"
    # Each file is of the form create_table_<table name>.sql, hence the magic
    # numbers
    when: "item[13:-4] not in tables.stdout"

  environment: "{{ fpsd_database_psql_env }}"<commit_msg>Simplifies logic for parsing out database table names<commit_after>---
- block:
  - name: List all schemas in the fpsd database.
    command: psql -c '\dn' fpsd
    register: schemas
    changed_when: false

  - name: Create the raw schema.
    command: psql -c 'CREATE SCHEMA raw;'
    when: "'raw' not in schemas.stdout"

  - name: List all tables in the raw schema.
    command: psql -c '\dt raw.*'
    register: tables
    changed_when: false

  - name: "Create the tables: crawls, hs_history, frontpage_examples, & frontpage_traces."
    command: psql -c '{{ lookup("file", item) }}'
    with_items: "{{ fpsd_database_raw_schema_tables }}"
    # Each file is of the form create_table_<table name>.sql, so let's extract the
    # expected table name and inspect the table list to check if it already exists.
    when: item|regex_replace('^create_table_(.*)\\.sql$', '\\1') not in tables.stdout

  environment: "{{ fpsd_database_psql_env }}"
{'fraction_non_alphanumeric': 0.11836027713625866, 'fraction_numerical': 0.0023094688221709007, 'mean_word_length': 3.2790123456790123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4221257', 'n_tokens_mistral': 581, 'n_tokens_neox': 564, 'n_words': 194}