Skip to content

Commit

Permalink
a8n: Introduce Threads in Store (sourcegraph#5509)
Browse files Browse the repository at this point in the history
* a8n: Add threads table migration

* a8n: Implement Store.{Create,Count,List}Thread(s)

* Update schema.md

* a8n: Implement filtering by Campaign in Store.ListThreads

* a8n: Implement filtering support in Store.CountThreads
  • Loading branch information
tsenart authored Sep 9, 2019
1 parent d7874c1 commit 5c85ed1
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 49 deletions.
23 changes: 23 additions & 0 deletions cmd/frontend/db/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Foreign-key constraints:
"campaigns_author_id_fkey" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE DEFERRABLE
"campaigns_namespace_org_id_fkey" FOREIGN KEY (namespace_org_id) REFERENCES orgs(id) ON DELETE CASCADE DEFERRABLE
"campaigns_namespace_user_id_fkey" FOREIGN KEY (namespace_user_id) REFERENCES users(id) ON DELETE CASCADE DEFERRABLE
Referenced by:
TABLE "threads" CONSTRAINT "threads_campaign_id_fkey" FOREIGN KEY (campaign_id) REFERENCES campaigns(id) ON DELETE CASCADE DEFERRABLE
```

Expand Down Expand Up @@ -468,6 +470,7 @@ Check constraints:
Referenced by:
TABLE "default_repos" CONSTRAINT "default_repos_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id)
TABLE "discussion_threads_target_repo" CONSTRAINT "discussion_threads_target_repo_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE
TABLE "threads" CONSTRAINT "threads_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE DEFERRABLE
```

Expand Down Expand Up @@ -570,6 +573,26 @@ Foreign-key constraints:
```

# Table "public.threads"
```
Column | Type | Modifiers
-------------+--------------------------+------------------------------------------------------
id | bigint | not null default nextval('threads_id_seq'::regclass)
campaign_id | integer | not null
repo_id | integer | not null
created_at | timestamp with time zone | not null default now()
updated_at | timestamp with time zone | not null default now()
metadata | jsonb | not null default '{}'::jsonb
Indexes:
"threads_pkey" PRIMARY KEY, btree (id)
Check constraints:
"threads_metadata_check" CHECK (jsonb_typeof(metadata) = 'object'::text)
Foreign-key constraints:
"threads_campaign_id_fkey" FOREIGN KEY (campaign_id) REFERENCES campaigns(id) ON DELETE CASCADE DEFERRABLE
"threads_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE DEFERRABLE
```

# Table "public.user_emails"
```
Column | Type | Modifiers
Expand Down
6 changes: 6 additions & 0 deletions migrations/1528395586_add_threads_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

DROP TABLE IF EXISTS threads;

COMMIT;

14 changes: 14 additions & 0 deletions migrations/1528395586_add_threads_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BEGIN;

CREATE TABLE IF NOT EXISTS threads (
id bigserial PRIMARY KEY,
campaign_id integer NOT NULL REFERENCES campaigns(id)
ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE,
repo_id integer NOT NULL REFERENCES repo(id)
ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE,
created_at timestamp with time zone NOT NULL DEFAULT now(),
updated_at timestamp with time zone NOT NULL DEFAULT now(),
metadata jsonb NOT NULL DEFAULT '{}' CHECK (jsonb_typeof(metadata) = 'object')
);

COMMIT;
48 changes: 48 additions & 0 deletions migrations/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c85ed1

Please sign in to comment.