<commit_before>--------------------------------------------------------------------------------
-- table: application_log                                                     --
--------------------------------------------------------------------------------

CREATE TABLE "application_log"
(
    "id"            SERIAL                      NOT NULL,
    "timestamp"     TIMESTAMP WITH TIME ZONE    NOT NULL    DEFAULT CURRENT_TIMESTAMP,
    "loggedUserId"  INTEGER,
    "priority"      INTEGER                     NOT NULL    DEFAULT 1,
    "eventType"     CHARACTER VARYING           NOT NULL,

    PRIMARY KEY ( "id" ),
    FOREIGN KEY ( "loggedUserId" )
     REFERENCES "user" ( "id" )
      ON UPDATE CASCADE
      ON DELETE SET NULL
);

--------------------------------------------------------------------------------
-- table: application_log_property                                            --
--------------------------------------------------------------------------------

CREATE TABLE "application_log_property"
(
    "logId"     INTEGER             NOT NULL,
    "name"      CHARACTER VARYING   NOT NULL,
    "value"     TEXT,

    FOREIGN KEY ( "logId" )
     REFERENCES "application_log" ( "id" )
      ON UPDATE CASCADE
      ON DELETE CASCADE
);

--------------------------------------------------------------------------------
-- function: application_log_clear_old_log()                                  --
--------------------------------------------------------------------------------

CREATE OR REPLACE FUNCTION "application_log_clear_old_log"()
                   RETURNS TRIGGER
                       SET search_path FROM CURRENT
                  LANGUAGE plpgsql
                        AS $$
BEGIN

    DELETE FROM "application_log"
          WHERE "timestamp" < ( CURRENT_TIMESTAMP - INTERVAL '1 month' );

    RETURN NEW;

END $$;

--------------------------------------------------------------------------------<commit_msg>add index for "application_log"."timestamp" @ primary key for "application_log_property"<commit_after>--------------------------------------------------------------------------------
-- table: application_log                                                     --
--------------------------------------------------------------------------------

CREATE TABLE "application_log"
(
    "id"            SERIAL                      NOT NULL,
    "timestamp"     TIMESTAMP WITH TIME ZONE    NOT NULL    DEFAULT CURRENT_TIMESTAMP,
    "loggedUserId"  INTEGER,
    "priority"      INTEGER                     NOT NULL    DEFAULT 1,
    "eventType"     CHARACTER VARYING           NOT NULL,

    PRIMARY KEY ( "id" ),
    FOREIGN KEY ( "loggedUserId" )
     REFERENCES "user" ( "id" )
      ON UPDATE CASCADE
      ON DELETE SET NULL
);

CREATE INDEX ON "application_log" ( "timestamp" DESC );

--------------------------------------------------------------------------------
-- table: application_log_property                                            --
--------------------------------------------------------------------------------

CREATE TABLE "application_log_property"
(
    "logId"     INTEGER             NOT NULL,
    "name"      CHARACTER VARYING   NOT NULL,
    "value"     TEXT,

    PRIMARY KEY ( "logId", "name" ),
    FOREIGN KEY ( "logId" )
     REFERENCES "application_log" ( "id" )
      ON UPDATE CASCADE
      ON DELETE CASCADE
);

--------------------------------------------------------------------------------
-- function: application_log_clear_old_log()                                  --
--------------------------------------------------------------------------------

CREATE OR REPLACE FUNCTION "application_log_clear_old_log"()
                   RETURNS TRIGGER
                       SET search_path FROM CURRENT
                  LANGUAGE plpgsql
                        AS $$
BEGIN

    DELETE FROM "application_log"
          WHERE "timestamp" < ( CURRENT_TIMESTAMP - INTERVAL '1 month' );

    RETURN NEW;

END $$;

--------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.3289248101885868, 'fraction_numerical': 0.0009796718099436689, 'mean_word_length': 0.7687310524036379, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3216861', 'n_tokens_mistral': 905, 'n_tokens_neox': 834, 'n_words': 227}