Skip to content

Commit

Permalink
Merge pull request #54 from EdwardKaravakis/main
Browse files Browse the repository at this point in the history
Port Oracle changes to Postgres
  • Loading branch information
EdwardKaravakis authored Sep 8, 2023
2 parents 686fede + 62928db commit 61a85f8
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
61 changes: 61 additions & 0 deletions schema/postgres/sqls/patches/0.0.16.patch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- patch to be used to upgrade from version 0.0.15

-- MODIFICATIONTIME TRIGGER
-- New column JEDI_TASKS.REALMODIFICATIONTIME
ALTER TABLE jedi_tasks ADD realmodificationtime timestamp;
COMMENT ON COLUMN jedi_tasks.realmodificationtime IS E'Set ALWAYS to last modification time, without any tricks like old timestamps';

CREATE INDEX jedi_tasks_realmodtime_idx ON jedi_tasks (realmodificationtime);

-- Trigger to set JEDI_TASKS.REALMODIFICATIONTIME to current UTC timestamp
DROP TRIGGER IF EXISTS update_realmodificationtime ON jedi_tasks CASCADE;
-- Trigger to set JEDI_TASKS.REALMODIFICATIONTIME to current UTC timestamp
CREATE OR REPLACE FUNCTION update_realmodificationtime_trg() RETURNS trigger AS $BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
NEW.realmodificationtime := CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
ELSIF (TG_OP = 'UPDATE') THEN
IF NEW.modificationtime <> OLD.modificationtime THEN
NEW.realmodificationtime := CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
END IF;
END IF;
RETURN NEW;
END
$BODY$
LANGUAGE 'plpgsql';

ALTER FUNCTION update_realmodificationtime_trg() OWNER TO panda;

CREATE TRIGGER update_realmodificationtime
BEFORE INSERT OR UPDATE ON jedi_tasks FOR EACH ROW
EXECUTE PROCEDURE update_realmodificationtime_trg();
/

-- SQL_QUEUE TABLE

CREATE TABLE sql_queue
(
topic varchar(50),
pandaid bigint,
execution_order integer,
jeditaskid bigint,
creationtime timestamp,
data VARCHAR(4000)
);

CREATE INDEX sql_queue_topic_task_idx ON sql_queue (topic, jeditaskid);
CREATE INDEX sql_queue_topic_creationtime_idx ON sql_queue (topic, creationtime);
COMMENT ON TABLE sql_queue IS E'Queue to send messages between agents';
COMMENT ON COLUMN sql_queue.topic IS E'Topic of the message';
COMMENT ON COLUMN sql_queue.pandaid IS E'Job ID';
COMMENT ON COLUMN sql_queue.execution_order IS E'In case multiple SQLs need to be executed together';
COMMENT ON COLUMN sql_queue.jeditaskid IS E'JEDI Task ID in case the messages want to be batched';
COMMENT ON COLUMN sql_queue.creationtime IS E'Timestamp when the message was created';
COMMENT ON COLUMN sql_queue.data IS E'CLOB in JSON format containing the SQL query and variables';
ALTER TABLE sql_queue ADD PRIMARY KEY (topic, pandaid, execution_order);


-- Update versions
UPDATE pandadb_version SET major=0, minor=0, patch=16 where component='JEDI';
UPDATE pandadb_version SET major=0, minor=0, patch=16 where component='SERVER';
COMMIT;
24 changes: 23 additions & 1 deletion schema/postgres/sqls/pg_PANDA_TABLE.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ ALTER TABLE carbon_region_emissions OWNER TO panda;
ALTER TABLE carbon_region_emissions ADD PRIMARY KEY (region,timestamp);


CREATE TABLE sql_queue (
topic varchar(50),
pandaid bigint,
execution_order integer,
jeditaskid bigint,
creationtime timestamp,
data VARCHAR(4000)
) ;
CREATE INDEX sql_queue_topic_task_idx ON sql_queue (topic, jeditaskid);
CREATE INDEX sql_queue_topic_creationtime_idx ON sql_queue (topic, creationtime);
COMMENT ON TABLE sql_queue IS E'Queue to send messages between agents';
COMMENT ON COLUMN sql_queue.topic IS E'Topic of the message';
COMMENT ON COLUMN sql_queue.pandaid IS E'Job ID';
COMMENT ON COLUMN sql_queue.execution_order IS E'In case multiple SQLs need to be executed together';
COMMENT ON COLUMN sql_queue.jeditaskid IS E'JEDI Task ID in case the messages want to be batched';
COMMENT ON COLUMN sql_queue.creationtime IS E'Timestamp when the message was created';
COMMENT ON COLUMN sql_queue.data IS E'CLOB in JSON format containing the SQL query and variables';
ALTER TABLE sql_queue ADD PRIMARY KEY (topic, pandaid, execution_order);


CREATE TABLE cloudtasks (
id integer NOT NULL,
taskname varchar(128),
Expand Down Expand Up @@ -907,7 +927,8 @@ CREATE TABLE jedi_tasks (
memory_leak_core bigint,
memory_leak_x2 decimal(14,3),
attemptnr smallint,
container_name varchar(200)
container_name varchar(200),
realmodificationtime timestamp
) PARTITION BY RANGE (jeditaskid) ;
COMMENT ON COLUMN jedi_tasks.amiflag IS E'It will contain a mask, one bit per AMI task (AMI has two tasks) with default value at insertion for "amiflag" to 3 (0b00000011). A trigger when the field “campaign” is modified: if "amiflag" is NULL then "amiflag" = 2 else "amiflag" = BITOR(AMIFLAG, 2)';
COMMENT ON COLUMN jedi_tasks.architecture IS E'The architecture on which the task runs. Eg, $CMTCONFIG';
Expand Down Expand Up @@ -996,6 +1017,7 @@ CREATE INDEX jedi_tasks_nametaskid_idx ON jedi_tasks (taskname, jeditaskid);
CREATE INDEX jedi_tasks_parent_tid_idx ON jedi_tasks (parent_tid);
CREATE INDEX jedi_tasks_status3attr_idx ON jedi_tasks (status, workqueue_id, prodsourcelabel, jeditaskid);
CREATE INDEX jedi_upper_tasks_name_idx ON jedi_tasks (upper(taskname));
CREATE INDEX jedi_tasks_realmodtime_idx ON jedi_tasks (realmodificationtime);
ALTER TABLE jedi_tasks ADD PRIMARY KEY (jeditaskid);
ALTER TABLE jedi_tasks ALTER COLUMN CREATIONDATE SET NOT NULL;
ALTER TABLE jedi_tasks ALTER COLUMN JEDITASKID SET NOT NULL;
Expand Down
30 changes: 30 additions & 0 deletions schema/postgres/sqls/pg_PANDA_TRIGGER.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SET client_encoding TO 'UTF8';

SET search_path = doma_panda,public;

\set ON_ERROR_STOP ON

SET check_function_bodies = false;

DROP TRIGGER IF EXISTS update_realmodificationtime ON jedi_tasks CASCADE;
-- Trigger to set JEDI_TASKS.REALMODIFICATIONTIME to current UTC timestamp
CREATE OR REPLACE FUNCTION update_realmodificationtime_trg() RETURNS trigger AS $BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
NEW.realmodificationtime := CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
ELSIF (TG_OP = 'UPDATE') THEN
IF NEW.modificationtime <> OLD.modificationtime THEN
NEW.realmodificationtime := CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
END IF;
END IF;
RETURN NEW;
END
$BODY$
LANGUAGE 'plpgsql';

ALTER FUNCTION update_realmodificationtime_trg() OWNER TO panda;

CREATE TRIGGER update_realmodificationtime
BEFORE INSERT OR UPDATE ON jedi_tasks FOR EACH ROW
EXECUTE PROCEDURE update_realmodificationtime_trg();
/
2 changes: 1 addition & 1 deletion schema/postgres/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.15
0.0.16

0 comments on commit 61a85f8

Please sign in to comment.