From ef5404f95b30b50232a0d291fcfb756018fb096d Mon Sep 17 00:00:00 2001 From: Eric Hanson Date: Wed, 30 Aug 2017 12:15:34 -0700 Subject: [PATCH] fix bug in handling nulls in bundles --- core/006-bundle/000-data_model.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/006-bundle/000-data_model.sql b/core/006-bundle/000-data_model.sql index 0893ee53..6130f829 100644 --- a/core/006-bundle/000-data_model.sql +++ b/core/006-bundle/000-data_model.sql @@ -65,8 +65,12 @@ create table blob ( value text ); -create function blob_hash_gen_trigger() returns trigger as $$ +create or replace function blob_hash_gen_trigger() returns trigger as $$ begin + if NEW.value = NULL then + return NULL; + end if; + NEW.hash = public.digest(NEW.value, 'sha256'); if exists (select 1 from bundle.blob b where b.hash = NEW.hash) then return NULL; @@ -105,7 +109,7 @@ create table rowset_row_field ( id uuid default public.uuid_generate_v4() primary key, rowset_row_id uuid references rowset_row(id) on delete cascade, field_id meta.field_id, - value_hash text not null references blob(hash) on delete cascade, + value_hash text references blob(hash) on delete cascade, unique(rowset_row_id, field_id) );