Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: Move httpapi, httpmw, & database into coderd #568

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 11 commits into from
Mar 25, 2022
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generated files
database/dump.sql linguist-generated=true
coderd/database/dump.sql linguist-generated=true
peerbroker/proto/*.go linguist-generated=true
provisionerd/proto/*.go linguist-generated=true
provisionersdk/proto/*.go linguist-generated=true
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ build: site/out bin
.PHONY: build

# Runs migrations to output a dump of the database.
database/dump.sql: $(wildcard database/migrations/*.sql)
go run database/dump/main.go
coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
go run coderd/database/dump/main.go

# Generates Go code for querying the database.
database/generate: fmt/sql database/dump.sql database/query.sql
cd database && sqlc generate && rm db_tmp.go
cd database && gofmt -w -r 'Querier -> querier' *.go
cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go
.PHONY: database/generate
coderd/database/generate: fmt/sql coderd/database/dump.sql coderd/database/query.sql
cd coderd/database && sqlc generate && rm db_tmp.go
cd coderd/database && gofmt -w -r 'Querier -> querier' *.go
cd coderd/database && gofmt -w -r 'Queries -> sqlQuerier' *.go
.PHONY: coderd/database/generate

fmt/prettier:
@echo "--- prettier"
Expand All @@ -30,18 +30,18 @@ else
endif
.PHONY: fmt/prettier

fmt/sql: ./database/query.sql
fmt/sql: ./coderd/database/query.sql
npx sql-formatter \
--language postgresql \
--lines-between-queries 2 \
./database/query.sql \
--output ./database/query.sql
sed -i 's/@ /@/g' ./database/query.sql
./coderd/database/query.sql \
--output ./coderd/database/query.sql
sed -i 's/@ /@/g' ./coderd/database/query.sql

fmt: fmt/prettier fmt/sql
.PHONY: fmt

gen: database/generate peerbroker/proto provisionersdk/proto provisionerd/proto
gen: coderd/database/generate peerbroker/proto provisionersdk/proto provisionerd/proto
.PHONY: gen

install: bin
Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

type JobOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion cli/parametercreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"
"golang.org/x/xerrors"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func parameterCreate() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cli/projectcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"golang.org/x/xerrors"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
"github.com/coder/coder/provisionerd"
"github.com/coder/coder/provisionersdk"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/projectcreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/database"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/pty/ptytest"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/spf13/cobra"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func projects() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cli/projectupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/spf13/cobra"
"golang.org/x/xerrors"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
"github.com/coder/coder/provisionersdk"
)

Expand Down
2 changes: 1 addition & 1 deletion cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"golang.org/x/term"
"golang.org/x/xerrors"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func workspaceSSH() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/cli/config"
"github.com/coder/coder/coderd"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/tunnel"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
"github.com/coder/coder/database/databasefake"
"github.com/coder/coder/provisioner/terraform"
"github.com/coder/coder/provisionerd"
"github.com/coder/coder/provisionersdk"
Expand Down
2 changes: 1 addition & 1 deletion cli/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/database/postgres"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database/postgres"
)

func TestStart(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cli/workspacecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"golang.org/x/xerrors"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func workspaceCreate() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cli/workspacedelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func workspaceDelete() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cli/workspacestart.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func workspaceStart() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cli/workspacestop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func workspaceStop() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cliui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"golang.org/x/xerrors"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/templater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
"github.com/coder/coder/coderd"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/tunnel"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
"github.com/coder/coder/database/databasefake"
"github.com/coder/coder/provisioner/terraform"
"github.com/coder/coder/provisionerd"
"github.com/coder/coder/provisionersdk"
Expand Down
10 changes: 5 additions & 5 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ coverage:

ignore:
# This is generated code.
- database/models.go
- database/query.sql.go
- database/databasefake
- coderd/database/models.go
- coderd/database/query.sql.go
- coderd/database/databasefake
# These are generated or don't require tests.
- cmd
- coderd/tunnel
- database/dump
- database/postgres
- coderd/database/dump
- coderd/database/postgres
- peerbroker/proto
- provisionerd/proto
- provisionersdk/proto
Expand Down
6 changes: 3 additions & 3 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"google.golang.org/api/idtoken"

"cdr.dev/slog"
"github.com/coder/coder/database"
"github.com/coder/coder/httpapi"
"github.com/coder/coder/httpmw"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/site"
)

Expand Down
6 changes: 3 additions & 3 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"cdr.dev/slog"
"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/coderd"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/postgres"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/cryptorand"
"github.com/coder/coder/database"
"github.com/coder/coder/database/databasefake"
"github.com/coder/coder/database/postgres"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionerd"
"github.com/coder/coder/provisionersdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/google/uuid"

"github.com/coder/coder/database"
"github.com/coder/coder/coderd/database"
)

// New returns an in-memory fake of the database.
Expand Down
4 changes: 2 additions & 2 deletions database/db.go → coderd/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// To modify the database schema:
// 1. Add a new migration using "create_migration.sh" in database/migrations/
// 2. Run "make database/generate" in the root to generate models.
// 3. Add/Edit queries in "query.sql" and run "make database/generate" to create Go code.
// 2. Run "make coderd/database/generate" in the root to generate models.
// 3. Add/Edit queries in "query.sql" and run "make coderd/database/generate" to create Go code.
package database

import (
Expand Down
2 changes: 1 addition & 1 deletion database/dump.sql → coderd/database/dump.sql

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

6 changes: 3 additions & 3 deletions database/dump/main.go → coderd/database/dump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"path/filepath"
"runtime"

"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/postgres"
)

func main() {
Expand Down Expand Up @@ -76,7 +76,7 @@ func main() {
}
}

dump := fmt.Sprintf("-- Code generated by 'make database/generate'. DO NOT EDIT.\n%s", output.Bytes())
dump := fmt.Sprintf("-- Code generated by 'make coderd/database/generate'. DO NOT EDIT.\n%s", output.Bytes())
_, mainPath, _, ok := runtime.Caller(0)
if !ok {
panic("couldn't get caller path")
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions database/migrate_test.go → coderd/database/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/postgres"
)

func TestMain(m *testing.M) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/coder/coder/database/postgres"
"github.com/coder/coder/coderd/database/postgres"

_ "github.com/lib/pq"
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/database"
"github.com/coder/coder/coderd/database"
)

func TestPubsubMemory(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions database/pubsub_test.go → coderd/database/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/postgres"
)

func TestPubsub(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions coderd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/database"
"github.com/coder/coder/httpapi"
"github.com/coder/coder/httpmw"
)

func (api *api) postFile(rw http.ResponseWriter, r *http.Request) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion httpapi/httpapi_test.go → coderd/httpapi/httpapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/coder/coder/httpapi"
"github.com/coder/coder/coderd/httpapi"
)

func TestWrite(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions httpmw/apikey.go → coderd/httpmw/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

"golang.org/x/oauth2"

"github.com/coder/coder/database"
"github.com/coder/coder/httpapi"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
)

// AuthCookie represents the name of the cookie the API key is stored in.
Expand Down
8 changes: 4 additions & 4 deletions httpmw/apikey_test.go → coderd/httpmw/apikey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/cryptorand"
"github.com/coder/coder/database"
"github.com/coder/coder/database/databasefake"
"github.com/coder/coder/httpapi"
"github.com/coder/coder/httpmw"
)

func randomAPIKeyParts() (id string, secret string) {
Expand Down
Loading