Skip to content

chore: Remove unused SQL functions #5857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,33 +283,6 @@ func (q *fakeQuerier) InsertAgentStat(_ context.Context, p database.InsertAgentS
return stat, nil
}

func (q *fakeQuerier) GetLatestAgentStat(_ context.Context, agentID uuid.UUID) (database.AgentStat, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

found := false
latest := database.AgentStat{}
for _, agentStat := range q.agentStats {
if agentStat.AgentID != agentID {
continue
}
if !found {
latest = agentStat
found = true
continue
}
if agentStat.CreatedAt.After(latest.CreatedAt) {
latest = agentStat
found = true
continue
}
}
if !found {
return database.AgentStat{}, sql.ErrNoRows
}
return latest, nil
}

func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, templateID uuid.UUID) ([]database.GetTemplateDAUsRow, error) {
q.mutex.Lock()
defer q.mutex.Unlock()
Expand Down Expand Up @@ -1305,22 +1278,6 @@ func (q *fakeQuerier) GetWorkspaceBuildByID(_ context.Context, id uuid.UUID) (da
return database.WorkspaceBuild{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetWorkspaceCountByUserID(_ context.Context, id uuid.UUID) (int64, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
var count int64
for _, workspace := range q.workspaces {
if workspace.OwnerID == id {
if workspace.Deleted {
continue
}

count++
}
}
return count, nil
}

func (q *fakeQuerier) GetWorkspaceBuildByJobID(_ context.Context, jobID uuid.UUID) (database.WorkspaceBuild, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down Expand Up @@ -2289,19 +2246,6 @@ func (q *fakeQuerier) GetWorkspaceAppByAgentIDAndSlug(_ context.Context, arg dat
return database.WorkspaceApp{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetProvisionerDaemonByID(_ context.Context, id uuid.UUID) (database.ProvisionerDaemon, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, provisionerDaemon := range q.provisionerDaemons {
if provisionerDaemon.ID != id {
continue
}
return provisionerDaemon, nil
}
return database.ProvisionerDaemon{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetProvisionerJobByID(_ context.Context, id uuid.UUID) (database.ProvisionerJob, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down Expand Up @@ -3238,26 +3182,6 @@ func (q *fakeQuerier) UpdateTemplateVersionDescriptionByJobID(_ context.Context,
return sql.ErrNoRows
}

func (q *fakeQuerier) UpdateProvisionerDaemonByID(_ context.Context, arg database.UpdateProvisionerDaemonByIDParams) error {
if err := validateDatabaseType(arg); err != nil {
return err
}

q.mutex.Lock()
defer q.mutex.Unlock()

for index, daemon := range q.provisionerDaemons {
if arg.ID != daemon.ID {
continue
}
daemon.UpdatedAt = arg.UpdatedAt
daemon.Provisioners = arg.Provisioners
q.provisionerDaemons[index] = daemon
return nil
}
return sql.ErrNoRows
}

func (q *fakeQuerier) UpdateWorkspaceAgentConnectionByID(_ context.Context, arg database.UpdateWorkspaceAgentConnectionByIDParams) error {
if err := validateDatabaseType(arg); err != nil {
return err
Expand Down Expand Up @@ -4046,10 +3970,6 @@ func (q *fakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
return group, nil
}

func (*fakeQuerier) GetUserGroups(_ context.Context, _ uuid.UUID) ([]database.Group, error) {
panic("not implemented")
}

func (q *fakeQuerier) GetGroupMembers(_ context.Context, groupID uuid.UUID) ([]database.User, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down
5 changes: 0 additions & 5 deletions coderd/database/querier.go

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

126 changes: 1 addition & 125 deletions coderd/database/queries.sql.go

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

5 changes: 1 addition & 4 deletions coderd/database/queries/agentstats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ INSERT INTO
VALUES
($1, $2, $3, $4, $5, $6, $7) RETURNING *;

-- name: GetLatestAgentStat :one
SELECT * FROM agent_stats WHERE agent_id = $1 ORDER BY created_at DESC LIMIT 1;

-- name: GetTemplateDAUs :many
SELECT
SELECT
(created_at at TIME ZONE 'UTC')::date as date,
user_id
FROM
Expand Down
12 changes: 0 additions & 12 deletions coderd/database/queries/groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ AND
LIMIT
1;

-- name: GetUserGroups :many
SELECT
groups.*
FROM
groups
JOIN
group_members
ON
groups.id = group_members.group_id
WHERE
group_members.user_id = $1;

-- name: GetGroupMembers :many
SELECT
users.*
Expand Down
17 changes: 0 additions & 17 deletions coderd/database/queries/provisionerdaemons.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
-- name: GetProvisionerDaemonByID :one
SELECT
*
FROM
provisioner_daemons
WHERE
id = $1;

-- name: GetProvisionerDaemons :many
SELECT
*
Expand All @@ -23,12 +15,3 @@ INSERT INTO
)
VALUES
($1, $2, $3, $4, $5) RETURNING *;

-- name: UpdateProvisionerDaemonByID :exec
UPDATE
provisioner_daemons
SET
updated_at = $2,
provisioners = $3
WHERE
id = $1;
10 changes: 0 additions & 10 deletions coderd/database/queries/workspaces.sql
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,6 @@ WHERE
GROUP BY
template_id;

-- name: GetWorkspaceCountByUserID :one
SELECT
COUNT(id)
FROM
workspaces
WHERE
owner_id = @owner_id
-- Ignore deleted workspaces
AND deleted != true;

-- name: InsertWorkspace :one
INSERT INTO
workspaces (
Expand Down