<commit_before>/**
 *
 * Table suffixes.
 * No suffix - state/configuration data.
 * _ping - data that is updated via RnDaemon pings
 * _dsp - data that is updated via dispatch
 * _count - counts maintained by triggers
 *
 */
CREATE SCHEMA plow;
CREATE LANGUAGE plpgsql;
CREATE EXTENSION hstore;

---
--- Return the current clock time in millis.
---
CREATE OR REPLACE FUNCTION plow.currentTimeMillis() RETURNS BIGINT AS $$
BEGIN
    return (EXTRACT(EPOCH FROM clock_timestamp()) * 1000)::bigint;
END;
$$ LANGUAGE plpgsql;


---
--- Returns the current time in millis, doesn't change during a transaction.
---
CREATE OR REPLACE FUNCTION plow.txTimeMillis() RETURNS BIGINT AS $$
BEGIN
    return (EXTRACT(EPOCH FROM NOW()) * 1000)::bigint;
END;
$$ LANGUAGE plpgsql;


----------------------------------------------------------

---
--- Project
---

CREATE TABLE plow.project (
  pk_project UUID NOT NULL PRIMARY KEY,
  pk_folder_default UUID,
  str_code VARCHAR(16) NOT NULL,
  str_title VARCHAR(255) NOT NULL,
  bool_active BOOLEAN NOT NULL DEFAULT 't'
) WITHOUT OIDS;

CREATE UNIQUE INDEX project_str_code_idx ON plow.project (str_code);

----------------------------------------------------------

---
--- Folders
---

CREATE TABLE plow.folder (
  pk_folder UUID NOT NULL PRIMARY KEY,
  pk_project UUID NOT NULL,
  str_name VARCHAR(128) NOT NULL,
  int_order SMALLINT NOT NULL,
  time_created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
) WITHOUT OIDS;


CREATE UNIQUE INDEX folder_name_pk_project_uniq_idx ON plow.folder (str_name, pk_project);
CREATE INDEX folder_pk_project_idx ON plow.folder (pk_project);


---

CREATE TABLE plow.folder_dsp (
  pk_folder UUID NOT NULL PRIMARY KEY,
  int_max_cores INTEGER NOT NULL DEFAULT -1,
  int_min_cores INTEGER NOT NULL DEFAULT 0,
  int_run_cores INTEGER NOT NULL DEFAULT 0,
  float_tier REAL NOT NULL DEFAULT 0.0
) WITHOUT OIDS;

CREATE INDEX folder_dsp_float_tier_idx ON plow.folder_dsp (float_tier);

----------------------------------------------------------

---
--- Jobs
---

CREATE TABLE plow.job (
  pk_job UUID NOT NULL PRIMARY KEY,
  pk_project UUID NOT NULL REFERENCES plow.folder(pk_folder),
  pk_folder UUID,
  str_name VARCHAR(160) NOT NULL,
  str_active_name VARCHAR(160),
  str_username VARCHAR(100) NOT NULL,
  str_log_path TEXT,
  int_uid INTEGER NOT NULL,
  int_state SMALLINT NOT NULL DEFAULT 0,
  bool_paused BOOLEAN NOT NULL DEFAULT 'f',
  time_started BIGINT NOT NULL DEFAULT plow.txTimeMillis(),
  time_stopped BIGINT DEFAULT 0
) WITHOUT OIDS;

CREATE UNIQUE INDEX job_str_active_name_uniq_idx ON plow.job (str_active_name);
CREATE INDEX job_int_state_bool_paused_pk_project_idx ON plow.job (int_state, bool_paused, pk_project);
CREATE INDEX job_pk_project_idx ON plow.job (pk_project);

---

CREATE TABLE plow.job_dsp (
  pk_job UUID NOT NULL PRIMARY KEY,<commit_msg>Fixed issue with job key constraints, folder was accidentally on project column.<commit_after>/**
 *
 * Table suffixes.
 * No suffix - state/configuration data.
 * _ping - data that is updated via RnDaemon pings
 * _dsp - data that is updated via dispatch
 * _count - counts maintained by triggers
 *
 */
CREATE SCHEMA plow;
CREATE LANGUAGE plpgsql;
CREATE EXTENSION hstore;

---
--- Return the current clock time in millis.
---
CREATE OR REPLACE FUNCTION plow.currentTimeMillis() RETURNS BIGINT AS $$
BEGIN
    return (EXTRACT(EPOCH FROM clock_timestamp()) * 1000)::bigint;
END;
$$ LANGUAGE plpgsql;


---
--- Returns the current time in millis, doesn't change during a transaction.
---
CREATE OR REPLACE FUNCTION plow.txTimeMillis() RETURNS BIGINT AS $$
BEGIN
    return (EXTRACT(EPOCH FROM NOW()) * 1000)::bigint;
END;
$$ LANGUAGE plpgsql;


----------------------------------------------------------

---
--- Project
---

CREATE TABLE plow.project (
  pk_project UUID NOT NULL PRIMARY KEY,
  pk_folder_default UUID,
  str_code VARCHAR(16) NOT NULL,
  str_title VARCHAR(255) NOT NULL,
  bool_active BOOLEAN NOT NULL DEFAULT 't'
) WITHOUT OIDS;

CREATE UNIQUE INDEX project_str_code_idx ON plow.project (str_code);

----------------------------------------------------------

---
--- Folders
---

CREATE TABLE plow.folder (
  pk_folder UUID NOT NULL PRIMARY KEY,
  pk_project UUID NOT NULL,
  str_name VARCHAR(128) NOT NULL,
  int_order SMALLINT NOT NULL,
  time_created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
) WITHOUT OIDS;


CREATE UNIQUE INDEX folder_name_pk_project_uniq_idx ON plow.folder (str_name, pk_project);
CREATE INDEX folder_pk_project_idx ON plow.folder (pk_project);


---

CREATE TABLE plow.folder_dsp (
  pk_folder UUID NOT NULL PRIMARY KEY,
  int_max_cores INTEGER NOT NULL DEFAULT -1,
  int_min_cores INTEGER NOT NULL DEFAULT 0,
  int_run_cores INTEGER NOT NULL DEFAULT 0,
  float_tier REAL NOT NULL DEFAULT 0.0
) WITHOUT OIDS;

CREATE INDEX folder_dsp_float_tier_idx ON plow.folder_dsp (float_tier);

----------------------------------------------------------

---
--- Jobs
---

CREATE TABLE plow.job (
  pk_job UUID NOT NULL PRIMARY KEY,
  pk_project UUID NOT NULL REFERENCES plow.project(pk_project),
  pk_folder UUID REFERENCES plow.folder(pk_folder),
  str_name VARCHAR(160) NOT NULL,
  str_active_name VARCHAR(160),
  str_username VARCHAR(100) NOT NULL,
  str_log_path TEXT,
  int_uid INTEGER NOT NULL,
  int_state SMALLINT NOT NULL DEFAULT 0,
  bool_paused BOOLEAN NOT NULL DEFAULT 'f',
  time_started BIGINT NOT NULL DEFAULT plow.txTimeMillis(),
  time_stopped BIGINT DEFAULT 0
) WITHOUT OIDS;

CREATE UNIQUE INDEX job_str_active_name_uniq_idx ON plow.job (str_active_name);
CREATE INDEX job_int_state_bool_paused_pk_project_idx ON plow.job (int_state, bool_paused, pk_project);
CREATE INDEX job_pk_project_idx ON plow.job (pk_project);

---

CREATE TABLE plow.job_dsp (
  pk_job UUID NOT NULL PRIMARY KEY,
{'fraction_non_alphanumeric': 0.13599447036461032, 'fraction_numerical': 0.011059270779332988, 'mean_word_length': 3.1225071225071224, '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': '6857034', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1878, 'n_words': 610}