Created
August 12, 2011 06:32
-
-
Save cjheath/1141578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Table "public.users" | |
| Column | Type | Modifiers | |
| --------+-----------------------+----------- | |
| id | character varying(36) | not null | |
| Indexes: | |
| "users_pkey" PRIMARY KEY, btree (id) | |
| Referenced by: | |
| TABLE "authentications" CONSTRAINT "authentications_user_fk" FOREIGN KEY (user_id) REFERENCES users(id) | |
| TABLE "delta" CONSTRAINT "delta_user_fk" FOREIGN KEY (user_id) REFERENCES users(id) | |
| TABLE "projects" CONSTRAINT "projects_user_fk" FOREIGN KEY (user_id) REFERENCES users(id) | |
| Table "public.projects" | |
| Column | Type | Modifiers | |
| ---------+-----------------------+----------- | |
| id | character varying(36) | not null | |
| name | character varying(50) | not null | |
| user_id | character varying(36) | not null | |
| Indexes: | |
| "projects_pkey" PRIMARY KEY, btree (id) | |
| "unique_projects_user_project" UNIQUE, btree (name) | |
| "index_projects_user" btree (user_id) | |
| Foreign-key constraints: | |
| "projects_user_fk" FOREIGN KEY (user_id) REFERENCES users(id) | |
| Referenced by: | |
| TABLE "branches" CONSTRAINT "branches_project_fk" FOREIGN KEY (project_id) REFERENCES projects(id) | |
| Table "public.branches" | |
| Column | Type | Modifiers | |
| ----------------+-----------------------+----------- | |
| id | character varying(36) | not null | |
| name | character varying(50) | not null | |
| project_id | character varying(36) | not null | |
| forked_from_id | character varying(36) | | |
| Indexes: | |
| "branches_pkey" PRIMARY KEY, btree (id) | |
| "unique_branches_project_version" UNIQUE, btree (name) | |
| "index_branches_forked_from" btree (forked_from_id) | |
| "index_branches_project" btree (project_id) | |
| Foreign-key constraints: | |
| "branches_forked_from_fk" FOREIGN KEY (forked_from_id) REFERENCES revisions(id) | |
| "branches_project_fk" FOREIGN KEY (project_id) REFERENCES projects(id) | |
| Referenced by: | |
| TABLE "revisions" CONSTRAINT "revisions_branch_fk" FOREIGN KEY (branch_id) REFERENCES branches(id) | |
| Table "public.revisions" | |
| Column | Type | Modifiers | |
| -------------+-----------------------------+----------- | |
| id | character varying(36) | not null | |
| created_at | timestamp without time zone | not null | |
| branch_id | character varying(36) | not null | |
| merge_of_id | character varying(36) | | |
| Indexes: | |
| "revisions_pkey" PRIMARY KEY, btree (id) | |
| "index_revisions_branch" btree (branch_id) | |
| "index_revisions_merge_of" btree (merge_of_id) | |
| Foreign-key constraints: | |
| "revisions_branch_fk" FOREIGN KEY (branch_id) REFERENCES branches(id) | |
| "revisions_merge_of_fk" FOREIGN KEY (merge_of_id) REFERENCES revisions(id) | |
| Referenced by: | |
| TABLE "branches" CONSTRAINT "branches_forked_from_fk" FOREIGN KEY (forked_from_id) REFERENCES revisions(id) | |
| TABLE "delta" CONSTRAINT "delta_revision_fk" FOREIGN KEY (revision_id) REFERENCES revisions(id) | |
| TABLE "revisions" CONSTRAINT "revisions_merge_of_fk" FOREIGN KEY (merge_of_id) REFERENCES revisions(id) | |
| Table "public.delta" | |
| Column | Type | Modifiers | |
| -------------+-----------------------+---------------------------------------------------------- | |
| id | character varying(36) | not null | |
| sequence | integer | not null default nextval('delta_sequence_seq'::regclass) | |
| revision_id | character varying(36) | not null | |
| user_id | character varying(36) | not null | |
| Indexes: | |
| "delta_pkey" PRIMARY KEY, btree (id) | |
| "index_delta_revision" btree (revision_id) | |
| "index_delta_user" btree (user_id) | |
| Foreign-key constraints: | |
| "delta_revision_fk" FOREIGN KEY (revision_id) REFERENCES revisions(id) | |
| "delta_user_fk" FOREIGN KEY (user_id) REFERENCES users(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'uuidtools' | |
| class User | |
| include DataMapper::Resource | |
| property :id, UUID, :key => true, :required => true, :default => proc { UUIDTools::UUID.random_create } | |
| has n, :projects | |
| has n, :deltas | |
| end | |
| class Project | |
| include DataMapper::Resource | |
| property :id, UUID, :key => true, :required => true, :default => proc { UUIDTools::UUID.random_create.to_s } | |
| property :name, String, :required => true, :unique_index => :user_project | |
| belongs_to :user, :unique_index => :user_project | |
| has n, :branches # Project has Branch | |
| def master | |
| Branch.first_or_create(:project => self, :name => 'master') | |
| end | |
| end | |
| class Branch | |
| include DataMapper::Resource | |
| property :id, UUID, :key => true, :required => true, :default => proc { UUIDTools::UUID.random_create.to_s } | |
| belongs_to :project, :unique_index => :project_version | |
| property :name, String, :required => true, :unique_index => :project_version | |
| has n, :revisions # Branch has Revision | |
| # Branch but may originate as a fork of another user's revision of a different project: | |
| belongs_to :forked_from, 'Revision', :required => false | |
| end | |
| class Revision | |
| include DataMapper::Resource | |
| property :id, UUID, :key => true, :required => true, :default => proc { UUIDTools::UUID.random_create.to_s } | |
| property :created_at, DateTime, :required => true | |
| belongs_to :branch # Revision belongs to Branch | |
| belongs_to :merge_of, Revision, :required => false | |
| has n, :deltas # Revision includes Delta | |
| has n, :forks, 'Branch'# Branch is forked from Revision | |
| # In GIT, a revision may merge multiple other revisions in one go; not here | |
| belongs_to :merge_of, 'Revision', :required => false | |
| end | |
| class Delta | |
| include DataMapper::Resource | |
| property :id, UUID, :key => true, :required => true, :default => proc { UUIDTools::UUID.random_create } | |
| property :sequence, Serial, :key => false, :required => true | |
| belongs_to :revision # Delta adds to Revision | |
| belongs_to :user # Delta was made by User | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment