START TRANSACTION;

ALTER TABLE quota
    RENAME COLUMN actual_value TO own_actual_value;

ALTER TABLE quota
    ADD COLUMN own_max_value BIGINT NOT NULL DEFAULT 0;

ALTER TABLE quota
    ALTER COLUMN own_max_value DROP DEFAULT;

UPDATE quota
SET own_max_value = max_value
FROM project p1
         LEFT JOIN project p2 ON p1.id = p2.parent_id AND p2.person_id IS NULL
WHERE quota.project_id = p1.id
  AND p2.id is NULL;

COMMIT;