views:

81

answers:

1

I have a pretty primitive table schema now ( in Postgres ):

CREATE TABLE "public"."sandbox_demo" (
    "id" int4 DEFAULT nextval('sandbox_demo_id_seq'::regclass) NOT NULL,
    "source" text DEFAULT NULL NOT NULL,
    "created" timestamptz(6) DEFAULT NULL NOT NULL,
    "modified" timestamptz(6) DEFAULT NULL NOT NULL
)

However, this table only supports plain entries and there's no parent child relationship or a mapping table so I could have revisions of the initial code snippet.

What would be an ideal way of making it so that revisions per initial code snippet are supported?

+1  A: 

Add a nullable parent_id so you can keep track of the original snippet?

WoLpH
I was thinking of that exactly, but I'm wondering how I'd be able to use a url pattern such as `/initial-bug-id/revision-id/`? If I was given say, `/204/3` then I would grab all rows where the `parent_id` is `204` and then sort by the created date and grab the 3rd one? Or would it be easier with mapping+extra tables?
meder
@meder: use [recursive/hierarchical syntax](http://www.postgresql.org/docs/8.4/static/queries-with.html)
OMG Ponies
@Meder: getting the 3rd row is an option, but it depends on wheter you want to save a complete tree or not. In that case you'll need a recursive query to get the 3rd revision of a bug.
WoLpH