Commit 200e6f48 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

TEIS-1784: generate created_at and modified_at values in existing records, if null.

parent 9d40caeb
theGroup=ee.sm.ti.teis
theVersion=1.9.0
theVersion=1.10.0-SNAPSHOT
commonsVersion=1.14.0
officeApiGatewayVersion=1.14.0
pluginVersion=1.2.0
--liquibase formatted sql
--changeset enriko:2021-01-20.TEIS-1784.generate-created_at-values.sql splitStatements:false
create or replace function fill_created_at_value(tableName varchar, idType varchar)
returns void
as $$
declare
createdAt timestamp;
rec record;
begin
select to_timestamp('2020-03-31 08:00:00', 'YYYY-MM-DD HH24:MI:SS') into createdAt;
for rec in execute 'select * from ' || quote_ident(tableName) || ' where created_at is null' LOOP
select createdAt + interval '1 second' into createdAt;
if idType = 'uuid' then
-- RAISE NOTICE 'ID= "%"', rec.id::text;
execute 'update ' || quote_ident(tableName) || ' set created_by = ''SYSTEM'', created_at = ''' || createdAt || ''', modified_at = ''' || createdAt || ''' where id=''' || rec.id::text || '''';
else
-- RAISE NOTICE 'ID str= "%"', rec.id;
execute 'update ' || quote_ident(tableName) || ' set created_by = ''SYSTEM'', created_at = ''' || createdAt || ''', modified_at = ''' || createdAt || ''' where id=''' || rec.id || '''';
end if;
-- RAISE NOTICE 'createdAt "%"', createdAt;
end loop;
end $$
language plpgsql;
select fill_created_at_value('office', 'uuid');
drop function fill_created_at_value(varchar, varchar);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment