-ALTER table project_widgets ADD COLUMN widget_bk jsonb;
-
+-- Reset id numbers. about 25 projects have duplicate ids
 UPDATE project_widgets p
 SET widget = nw.new_widget
 FROM (SELECT widget_uid,

))
WHERE widget->'gridcolumn' is NOT NULL;

UPDATE project_widgets
SET widget = jsonb_set(widget, '{"layout"}', jsonb_build_object(
    'x', 0,

    AND widget->'layout' is NULL
    AND widget->'width' is NOT NULL;

-- Remove all unused params
UPDATE project_widgets
SET widget = widget - 'width' - 'position' - 'gridcolumn' - 'gridrow'
WHERE widget->'layout' is NOT NULL;

UPDATE project_widgets
SET widget = jsonb_set(widget, '{"layout"}', jsonb_build_object(
    'h', widget->'layout'->'h',
    'i', widget->'layout'->'i',
    'w', widget->'layout'->'w',
    'x', widget->'layout'->'x',
    'y', widget->'layout'->'y'
))

-- Check all widget
SELECT widget
