We have identified a bug in our 3.34 and 3.34.1 release that can cause some repositories from older Sourcegraph versions to have an unexpected NULL value in one of their columns in the database. We are sorry for the inconvenience and confusion this bug may have caused.
If you have already upgraded to 3.34 or 3.34.1, you can either upgrade to 3.34.2 or manually fix this by running the following SQL commands in your Postgres instance (see documentation if you need help connecting to it).
Please run the following SQL statements one-at-a-time. They have been designed to minimize the impact on your Sourcegraph instance while they execute.
Declare a procedure which, when invoked, will incrementally update any repository that has a NULL entry in its stars column to 0 instead:
CREATEORREPLACEPROCEDURE set_repo_stars_null_to_zero() AS $BODY$ DECLARE done boolean; total integer=0; updated integer=0; BEGIN SELECTCOUNT(*) INTO total FROM repo WHERE stars ISNULL; RAISE NOTICE 'repo_stars_null_to_zero: updating % rows', total; done := total =0; WHILENOT done LOOP UPDATE repo SET stars =0 FROM ( SELECTidFROM repo WHERE stars ISNULL LIMIT10000 FORUPDATESKIPLOCKED ) s WHERE repo.id= s.id; COMMIT; SELECTCOUNT(*) =0INTO done FROM repo WHERE stars ISNULLLIMIT1; updated := updated +10000; RAISE NOTICE 'repo_stars_null_to_zero: updated % of % rows', updated, total; ENDLOOP; END $BODY$ LANGUAGE plpgsql;
Call the procedure that was declared in the previous step:
CALL set_repo_stars_null_to_zero();
Change the repo table to make the stars column not nullable: