Skip to content

Commit 229d770

Browse files
committed
WIP
1 parent 2218160 commit 229d770

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

cli/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
607607
options.Pubsub = pubsub.NewInMemory()
608608
} else {
609609
sqlDB, err := connectToPostgres(ctx, logger, sqlDriver, cfg.PostgresURL.String())
610+
610611
if err != nil {
611612
return xerrors.Errorf("connect to postgres: %w", err)
612613
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BEGIN;
2+
3+
DROP VIEW visible_users;
4+
5+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BEGIN;
2+
3+
CREATE VIEW
4+
visible_users
5+
AS
6+
SELECT
7+
id, username, avatar_url
8+
FROM
9+
users;
10+
11+
COMMENT ON VIEW visible_users IS 'Visible fields of users are allowed to be joined with other tables for including context of other resources.';
12+
13+
CREATE VIEW
14+
template_with_users
15+
AS
16+
SELECT
17+
templates.*,
18+
visible_users.username AS created_by_username,
19+
visible_users.avatar_url AS created_by_avatar_url
20+
FROM
21+
templates
22+
LEFT JOIN
23+
visible_users
24+
ON
25+
templates.created_by = visible_users.id;
26+
27+
COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.';
28+
29+
COMMIT;

coderd/templates_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coderd_test
22

33
import (
44
"context"
5+
"database/sql"
56
"net/http"
67
"sync/atomic"
78
"testing"
@@ -29,7 +30,10 @@ func TestTemplate(t *testing.T) {
2930

3031
t.Run("Get", func(t *testing.T) {
3132
t.Parallel()
32-
client := coderdtest.New(t, nil)
33+
db, _ := sql.Open("postgres", "postgresql://postgres:postgres@localhost:5432?sslmode=disable")
34+
client := coderdtest.New(t, &coderdtest.Options{
35+
Database: database.New(db),
36+
})
3337
user := coderdtest.CreateFirstUser(t, client)
3438
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
3539
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

0 commit comments

Comments
 (0)