text: # Generated by Django 3.1 on 2020-08-19 12:20
  
  from django.db import migrations
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
      ]
  
      operations = [
                      migrations.RunSQL(
                              ("CREATE OR REPLACE FUNCTION jsonb_diff_val(val1 JSONB, val2 JSONB)"
                                 " RETURNS JSONB AS $$"
                                 " DECLARE"
                                 "   result JSONB;"
                                 "   v RECORD;"
                                 " BEGIN"
                                 "    result = val1;"
                                 "    FOR v IN SELECT * FROM jsonb_each(val2) LOOP"
                                 "      IF result @> jsonb_build_object(v.key,v.value)"
                                 "         THEN result = result - v.key;"
                                 "      ELSIF result ? v.key THEN CONTINUE;"
                                 "      ELSE"
                                 "         result = result || jsonb_build_object(v.key, NULL);"
                                 "      END IF;"
                                 "    END LOOP;"
                                 "    RETURN result;"
                                 " END;"
                                 " $$ LANGUAGE plpgsql;"),
                              ('DROP FUNCTION IF EXISTS jsonb_diff_val(val1 JSONB, val2 JSONB);')
              )
      ]
  