Share Pastebin
Guest
Public paste!

mtigas

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