Skip to content

Commit 1150e20

Browse files
committed
Migrations
Exclude system users from users.sql queries Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 2838fb1 commit 1150e20

18 files changed

+267
-37
lines changed

coderd/database/dbauthz/dbauthz.go

+8
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,14 @@ func (q *querier) GetTemplateParameterInsights(ctx context.Context, arg database
22212221
return q.db.GetTemplateParameterInsights(ctx, arg)
22222222
}
22232223

2224+
func (q *querier) GetTemplatePrebuildState(ctx context.Context, templateID uuid.UUID) ([]database.GetTemplatePrebuildStateRow, error) {
2225+
// TODO: authz
2226+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate); err != nil {
2227+
return nil, err
2228+
}
2229+
return q.db.GetTemplatePrebuildState(ctx, templateID)
2230+
}
2231+
22242232
func (q *querier) GetTemplateUsageStats(ctx context.Context, arg database.GetTemplateUsageStatsParams) ([]database.TemplateUsageStat, error) {
22252233
if err := q.authorizeTemplateInsights(ctx, arg.TemplateIDs); err != nil {
22262234
return nil, err

coderd/database/dbmem/dbmem.go

+4
Original file line numberDiff line numberDiff line change
@@ -5464,6 +5464,10 @@ func (q *FakeQuerier) GetTemplateParameterInsights(ctx context.Context, arg data
54645464
return rows, nil
54655465
}
54665466

5467+
func (q *FakeQuerier) GetTemplatePrebuildState(ctx context.Context, templateID uuid.UUID) ([]database.GetTemplatePrebuildStateRow, error) {
5468+
panic("not implemented")
5469+
}
5470+
54675471
func (q *FakeQuerier) GetTemplateUsageStats(_ context.Context, arg database.GetTemplateUsageStatsParams) ([]database.TemplateUsageStat, error) {
54685472
err := validateDatabaseType(arg)
54695473
if err != nil {

coderd/database/dbmetrics/querymetrics.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

+51-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE users
2+
DROP COLUMN IF EXISTS is_system;
3+
4+
DROP INDEX IF EXISTS user_is_system_idx;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ALTER TABLE users
2+
ADD COLUMN is_system bool DEFAULT false;
3+
4+
CREATE INDEX user_is_system_idx ON users USING btree (is_system);
5+
6+
COMMENT ON COLUMN users.is_system IS 'Determines if a user is a system user, and therefore cannot login or perform normal actions';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Revert prebuild views
2+
DROP VIEW IF EXISTS workspace_prebuild_builds;
3+
DROP VIEW IF EXISTS workspace_prebuilds;
4+
5+
-- Revert user operations
6+
DELETE FROM user_status_changes WHERE user_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0';
7+
DELETE FROM users WHERE id = 'c42fdf75-3097-471c-8c33-fb52454d81c0';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- TODO: using "none" for login type produced this error: 'unsafe use of new value "none" of enum type login_type' -> not sure why
2+
INSERT INTO users (id, email, username, name, created_at, updated_at, status, rbac_roles, hashed_password, is_system)
3+
VALUES ('c42fdf75-3097-471c-8c33-fb52454d81c0', 'prebuilds@system', 'prebuilds', 'Prebuilds Owner', now(), now(),
4+
'active', '{}', 'none', true);
5+
6+
CREATE VIEW workspace_prebuilds AS
7+
SELECT *
8+
FROM workspaces
9+
WHERE owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0';
10+
11+
CREATE VIEW workspace_prebuild_builds AS
12+
SELECT workspace_id
13+
FROM workspace_builds
14+
WHERE initiator_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0';

coderd/database/migrations/000291_preset_prebuilds.down.sql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE

coderd/database/modelqueries.go

+1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func (q *sqlQuerier) GetAuthorizedUsers(ctx context.Context, arg GetUsersParams,
422422
&i.GithubComUserID,
423423
&i.HashedOneTimePasscode,
424424
&i.OneTimePasscodeExpiresAt,
425+
&i.IsSystem,
425426
&i.Count,
426427
); err != nil {
427428
return nil, err

coderd/database/models.go

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)