BEGIN;

-- Remove separate grading table and move grading details into recording_eggs
DROP INDEX IF EXISTS idx_grading_eggs_recording_egg;
DROP TABLE IF EXISTS grading_eggs;

ALTER TABLE recording_eggs
    ADD COLUMN IF NOT EXISTS weight NUMERIC(10,3);

ALTER TABLE recording_eggs
    DROP CONSTRAINT IF EXISTS chk_recording_eggs_qty;

ALTER TABLE recording_eggs
    ADD CONSTRAINT chk_recording_eggs_qty CHECK (
        qty >= 0 AND (weight IS NULL OR weight >= 0)
    );

COMMIT;
