Skip to content

refactor(coderd/database): generate dbresetpw with queries for reset-password command #9519

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ coderd/database/dump.sql: coderd/database/gen/dump/main.go $(wildcard coderd/dat
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
./coderd/database/generate.sh

coderd/database/dbresetpw/users_resetpw.sql.go: coderd/database/querier.go coderd/database/dbresetpw/sqlc.yaml
sqlc generate -f ./coderd/database/dbresetpw/sqlc.yaml

coderd/database/dbmock/dbmock.go: coderd/database/db.go coderd/database/querier.go
go generate ./coderd/database/dbmock/

Expand Down
8 changes: 4 additions & 4 deletions cli/resetpassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbresetpw"
"github.com/coder/coder/v2/coderd/database/migrations"
"github.com/coder/coder/v2/coderd/userpassword"
)
Expand Down Expand Up @@ -37,9 +37,9 @@ func (*RootCmd) resetPassword() *clibase.Cmd {
if err != nil {
return xerrors.Errorf("database needs migration: %w", err)
}
db := database.New(sqlDB)
db := dbresetpw.New(sqlDB)

user, err := db.GetUserByEmailOrUsername(inv.Context(), database.GetUserByEmailOrUsernameParams{
user, err := db.GetUserByEmailOrUsername(inv.Context(), dbresetpw.GetUserByEmailOrUsernameParams{
Username: username,
})
if err != nil {
Expand Down Expand Up @@ -73,7 +73,7 @@ func (*RootCmd) resetPassword() *clibase.Cmd {
return xerrors.Errorf("hash password: %w", err)
}

err = db.UpdateUserHashedPassword(inv.Context(), database.UpdateUserHashedPasswordParams{
err = db.UpdateUserHashedPassword(inv.Context(), dbresetpw.UpdateUserHashedPasswordParams{
ID: user.ID,
HashedPassword: []byte(hashedPassword),
})
Expand Down
31 changes: 31 additions & 0 deletions coderd/database/dbresetpw/db.go

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

121 changes: 121 additions & 0 deletions coderd/database/dbresetpw/models.go

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

13 changes: 13 additions & 0 deletions coderd/database/dbresetpw/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This sqlc.yaml file is used by sqlc to generate a subset of the coderd
# database interface that can be used for the reset-password command.
version: "2"

sql:
- schema: "../dump.sql"
queries: "../queries/users_resetpw.sql"
engine: "postgresql"
gen:
go:
package: "dbresetpw"
out: "."
omit_unused_structs: true
75 changes: 75 additions & 0 deletions coderd/database/dbresetpw/users_resetpw.sql.go

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

Loading