mtigas
By: a guest | May 27th, 2009 | Syntax:
SQL | Size: 0.84 KB | Hits: 19 | Expires: Never
-- remove the implicit one-to-one since we dont want to inherit anymore
ALTER TABLE "places2_places" DROP CONSTRAINT "places2_places_location_ptr_id_fkey";
-- convert the current inherit one-to-one into an ID field with a counter sequence
ALTER TABLE "places2_places" RENAME "location_ptr_id" TO "id";
CREATE SEQUENCE "places2_places_id_seq";
SELECT SETVAL('places2_places_id_seq',(SELECT "last_value" FROM "places2_location_id_seq")+1);
ALTER TABLE "places2_places" ALTER "id" SET DEFAULT NEXTVAL('places2_places_id_seq'::regclass);
-- since the existing publicplaces' IDs are actually also FKs to a Location,
-- copy the ID over to the location_id field.
ALTER TABLE "places2_places" ADD COLUMN "location_id" integer REFERENCES "places2_location" ("id") DEFERRABLE INITIALLY DEFERRED;
UPDATE "places2_places" SET "location_id"="places2_places"."id";