Hello community,
I have a store procedure that I run daily in snowflake with the help of a task where I perform some transformation involving 2 tables I have in my production environment only. This transformation involve deleting rows with todays date from my main table and then inserting rows that are from table B to table A. Rows that are in table B are updated every 3 hours. Below is the code I use:
--Delete tickets from current day
delete from PRD_EVOLUTIONER.DATA_ANALYTICS.TICKET_DASHBOARD_GAVATAR_HISTORICAL2 WHERE DATE = CURRENT_DATE;
--Copy tickets from Hana's Gavatar table into Historical table and store them with current date, period and fiscal year
INSERT INTO "PRD_EVOLUTIONER"."DATA_ANALYTICS"."TICKET_DASHBOARD_GAVATAR_HISTORICAL2" (
DATE,
ID ,
TYPEOFREQUEST_MAPPED ,
CLIENT ,
WORKBASKET ,
TICKETOWNER ,
TICKET_OWNER_EMAIL ,
URGENCY ,
SURVEYRESPONSE ,
SHORTCOUNTRY ,
CASEID ,
DASHBOARD_STATUS ,
ELAPSED_IN_NEW_TOTAL_DAYS ,
ELAPSED_IN_OPEN_TOTAL_DAYS ,
ELAPSED_IN_PENDING_TOTAL_DAYS ,
NUMBER_STATUS_CHANGES ,
EMAIL ,
CC ,
SUBJECT ,
ACTIONDATE_FORMATTED,
EFFECTIVEDATE_FORMATTED,
CLOSUREDATE_FORMATTED,
USECASEID_TITLE ,
REQUEST_DESTINATION ,
LOCATION_CODE ,
LOCATION_MANAGER_GID ,
PRIORITY ,
PORTFOLIO_TYPE ,
LAST_MODIFICATION_DATE ,
PERIOD,
FISCAL_YEAR,
CREATED_DATE ,
CLOSED_DATE ,
CREATED_DATE_YTD ,
CLOSED_DATE_YTD
)
SELECT
CURRENT_DATE ,
ID ,
TYPEOFREQUEST_MAPPED ,
CLIENT ,
WORKBASKET ,
TICKETOWNER ,
TICKET_OWNER_EMAIL ,
URGENCY ,
SURVEYRESPONSE ,
SHORTCOUNTRY ,
CASEID ,
DASHBOARD_STATUS ,
ELAPSED_IN_NEW_TOTAL_DAYS ,
ELAPSED_IN_OPEN_TOTAL_DAYS ,
ELAPSED_IN_PENDING_TOTAL_DAYS ,
NUMBER_STATUS_CHANGES ,
EMAIL ,
CC ,
SUBJECT ,
TO_CHAR(TO_DATE(ACTIONDATE_FORMATTED, 'YYYY-MM-DD'), 'DD/MM/YYYY'),
TO_CHAR(TO_DATE(EFFECTIVEDATE_FORMATTED, 'YYYY-MM-DD'), 'DD/MM/YYYY'),
TO_CHAR(TO_DATE(CLOSUREDATE_FORMATTED, 'YYYY-MM-DD'), 'DD/MM/YYYY'),
USECASEID_TITLE ,
REQUEST_DESTINATION ,
LOCATION_CODE ,
LOCATION_MANAGER_GID ,
PRIORITY ,
PORTFOLIO_TYPE,
TO_CHAR(TO_DATE(LEFT(LAST_MODIFICATION_DATE,10), 'YYYY-MM-DD'), 'DD/MM/YYYY'),
(CASE WHEN MONTH(CURRENT_DATE) BETWEEN 1 AND 9 THEN MONTH(CURRENT_DATE)+3 ELSE MONTH(CURRENT_DATE)-9 END), --Period
(CASE WHEN MONTH(CURRENT_DATE) BETWEEN 1 AND 9 THEN YEAR(CURRENT_DATE) ELSE YEAR(CURRENT_DATE)+1 END), --Fiscal Year
0 ,
0 ,
0 ,
0
FROM "PRD_EVOLUTIONER"."POSTGRES"."TICKET_DASHBOARD_GAVATAR";
That is the code I have to run daily and I am wondering what is the best way I can adapt this to dbt so then I can create a job to run it daily.