<commit_before>(in-package :postgres-json)

(defun create-base-table (name schema)
  "Create a PostgreSQL table called NAME in SCHEMA, both symbols.
This is the base table for the model.  Requires an active DB
connection."
  (run `(:create-table ,(qualified-name-string name schema)
         ((,*id*      :type ,*id-type*   :primary-key t)
          (valid-to   :type timestamptz :default (:type "infinity" timestamptz))
          (valid-from :type timestamptz :default (:transaction-timestamp))
          (,*jdoc*    :type ,*jdoc-type*)))))

(defun create-old-table (name schema)
  "Create a PostgreSQL table called NAME in SCHEMA, both symbols.
This is the 'old' table for the model, which will store non current
rows.  Requires an active DB connection."
  (run `(:create-table ,(qualified-name-string name schema)
         ((,*id*      :type ,*id-type*)
          (valid-to   :type timestamptz)
          (valid-from :type timestamptz)
          (,*jdoc*    :type ,*jdoc-type*))
         (:primary-key ,*id* valid-to))))

(defun create-gin-index (name table schema)
  "Create a PostgreSQL GIN index with NAME on a database table TABLE
in SCHEMA, all symbols.  Note that if you use *JDOC-TYPE* 'json when
creating the tables you cannot then create these indexes --- see the
PostgreSQL documentation.  In fact the option 'jsonb_path_ops' to the
GIN index may be desirable under some circumstances but I have not yet
twisted s-sql to generate such an index declaration (clearly we could
just use a string).  Requires an active DB connection."
  (run `(:create-index ,name :on ,(qualified-name-string table schema)
         :using gin :fields ,*jdoc*)))
<commit_msg>Change backend to use new model parameters<commit_after>(in-package :postgres-json)

(defun create-base-table (name model-parameters)
  "Create a PostgreSQL table called NAME in *PGJ-SCHEMA*, both symbols.
Configure table columns names, types etc. using MODEL-PARAMETERS.
This is the base table for the model.  Requires an active DB
connection."
  (with-readers (id id-type jdoc jdoc-type) model-parameters
    (run `(:create-table ,(db-name-string name)
           ((,id   :type ,id-type :primary-key t)
            (valid-to    :type timestamptz :default (:type "infinity" timestamptz))
            (valid-from  :type timestamptz :default (:transaction-timestamp))
            (,jdoc :type ,jdoc-type))))))

(defun create-old-table (name model-parameters)
  "Create a PostgreSQL table called NAME in *PGJ-SCHEMA*, both symbols.
Configure table columns names, types etc. using MODEL-PARAMETERS.
This is the 'old' table for the model, which will store non current
rows.  Requires an active DB connection."
  (with-readers (id id-type jdoc jdoc-type) model-parameters
    (run `(:create-table ,(db-name-string name)
           ((,id      :type ,id-type )
            (valid-to   :type timestamptz)
            (valid-from :type timestamptz)
            (,jdoc    :type ,jdoc-type))
           (:primary-key ,id valid-to)))))

(defun create-gin-index (name table model-parameters)
  "Create a PostgreSQL GIN index with NAME on a database table TABLE
in *PGJ-SCHEMA*, all symbols.  Configure table columns names, types
etc. using MODEL-PARAMETERS.  Note that if you use 'jdoc-type of 'json
when creating the tables you cannot then create these indexes --- see
the PostgreSQL documentation.  In fact the option 'jsonb_path_ops' to
the GIN index may be desirable under some circumstances but I have not
yet twisted s-sql to generate such an index declaration (clearly we
could just use a string).  Requires an active DB connection."
  (with-readers (jdoc) model-parameters
    (run `(:create-index ,name :on ,(db-name-string table)
           :using gin :fields ,jdoc))))

{'fraction_non_alphanumeric': 0.10530546623794212, 'fraction_numerical': 0.0, 'mean_word_length': 3.3256083429895713, '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': '6094116', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1128, 'n_words': 445}