ALTER TABLE "training_records" ADD COLUMN "course_name" text;
--> statement-breakpoint
UPDATE "training_records" AS "tr"
SET "course_name" = "c"."name"
FROM "courses" AS "c"
WHERE "tr"."course_id" = "c"."id"
  AND "tr"."course_name" IS NULL;
--> statement-breakpoint
UPDATE "training_records"
SET "course_name" = 'External course'
WHERE "course_name" IS NULL;
--> statement-breakpoint
ALTER TABLE "training_records" ALTER COLUMN "course_name" SET NOT NULL;
--> statement-breakpoint
ALTER TABLE "training_records" ALTER COLUMN "course_id" DROP NOT NULL;
