<commit_before>(ns pe-fp-app.lifecycle
  (:require [pe-fp-app.config :as config]
            [clojure.tools.logging :as log]
            [pe-jdbc-utils.core :as jcore]
            [clojure.java.jdbc :as j]
            [pe-user-core.ddl :as uddl]
            [pe-fp-core.ddl :as fpddl]
            [pe-user-core.core :as usercore]
            [clojure.tools.nrepl.server :as nrepl]
            [environ.core :refer [env]]))

(def nrepl-server)

(def target-schema-version 0)

(def ddl-operations
  {0 (fn []
       ;; User / auth-token setup
       (j/db-do-commands config/db-spec
                         true
                         uddl/v0-create-user-account-ddl
                         uddl/v0-add-unique-constraint-user-account-email
                         uddl/v0-add-unique-constraint-user-account-username
                         uddl/v0-create-authentication-token-ddl)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (uddl/v0-create-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (uddl/v0-create-user-account-updated-count-trigger-fn config/db-spec))
       ;; Vehicle setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-vehicle-ddl
                         fpddl/v0-add-unique-constraint-vehicle-name)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-vehicle-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-vehicle-updated-count-trigger-fn config/db-spec))
       ;; Fuelstation setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-fuelstation-ddl
                         fpddl/v0-create-index-on-fuelstation-name)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fuelstation-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fuelstation-updated-count-trigger-fn config/db-spec))
       ;; Fuel purchase log setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-fplog-ddl)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fplog-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fplog-updated-count-trigger-fn config/db-spec))
       ;; Environment log setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-envlog-ddl)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-envlog-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-envlog-updated-count-trigger-fn config/db-spec)))})

(defn init-database
  []
  ;; Database setup
  (log/info "Proceeding to create database")
  (jcore/create-database config/db-spec-without-db config/fp-db-name)

  ;; Create schema version table
  (j/db-do-commands config/db-spec true uddl/schema-version-ddl)<commit_msg>removed 'create database' step from init<commit_after>(ns pe-fp-app.lifecycle
  (:require [pe-fp-app.config :as config]
            [clojure.tools.logging :as log]
            [pe-jdbc-utils.core :as jcore]
            [clojure.java.jdbc :as j]
            [pe-user-core.ddl :as uddl]
            [pe-fp-core.ddl :as fpddl]
            [pe-user-core.core :as usercore]
            [clojure.tools.nrepl.server :as nrepl]
            [environ.core :refer [env]]))

(def nrepl-server)

(def target-schema-version 0)

(def ddl-operations
  {0 (fn []
       ;; User / auth-token setup
       (j/db-do-commands config/db-spec
                         true
                         uddl/v0-create-user-account-ddl
                         uddl/v0-add-unique-constraint-user-account-email
                         uddl/v0-add-unique-constraint-user-account-username
                         uddl/v0-create-authentication-token-ddl)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (uddl/v0-create-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (uddl/v0-create-user-account-updated-count-trigger-fn config/db-spec))
       ;; Vehicle setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-vehicle-ddl
                         fpddl/v0-add-unique-constraint-vehicle-name)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-vehicle-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-vehicle-updated-count-trigger-fn config/db-spec))
       ;; Fuelstation setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-fuelstation-ddl
                         fpddl/v0-create-index-on-fuelstation-name)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fuelstation-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fuelstation-updated-count-trigger-fn config/db-spec))
       ;; Fuel purchase log setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-fplog-ddl)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fplog-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-fplog-updated-count-trigger-fn config/db-spec))
       ;; Environment log setup
       (j/db-do-commands config/db-spec
                         true
                         fpddl/v0-create-envlog-ddl)
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-envlog-updated-count-inc-trigger-function-fn config/db-spec))
       (jcore/with-try-catch-exec-as-query config/db-spec
         (fpddl/v0-create-envlog-updated-count-trigger-fn config/db-spec)))})

(defn init-database
  []
  ;; Database setup
  (log/info "Proceeding to setup database")

  ;; Create schema version table
  (j/db-do-commands config/db-spec true uddl/schema-version-ddl)
{'fraction_non_alphanumeric': 0.12993920972644377, 'fraction_numerical': 0.006686930091185411, 'mean_word_length': 1.8052003410059676, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5257947', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2193, 'n_words': 277}