Skip to content

chore: split queries.sql into files by table #762

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 9 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: split queries.sql into files by table
  • Loading branch information
coadler committed Apr 1, 2022
commit 8f65e1022bb0304bda4687ac4f13d74faf0ef233
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
.PHONY: coderd/database/dump.sql

# Generates Go code for querying the database.
coderd/database/generate: fmt/sql coderd/database/dump.sql coderd/database/query.sql
coderd/database/generate: fmt/sql coderd/database/dump.sql $(wildcard coderd/database/queries/*.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
Expand All @@ -31,13 +31,17 @@ else
endif
.PHONY: fmt/prettier

fmt/sql: ./coderd/database/query.sql
npx sql-formatter \
--language postgresql \
--lines-between-queries 2 \
./coderd/database/query.sql \
--output ./coderd/database/query.sql
sed -i 's/@ /@/g' ./coderd/database/query.sql
fmt/sql: $(wildcard coderd/database/queries/*.sql)
for fi in coderd/database/queries/*.sql; do \
npx sql-formatter \
--language postgresql \
--lines-between-queries 2 \
--tab-indent \
$$fi \
--output $$fi; \
done

sed -i 's/@ /@/g' ./coderd/database/queries/*.sql

fmt: fmt/prettier fmt/sql
.PHONY: fmt
Expand Down
173 changes: 173 additions & 0 deletions coderd/database/api_keys.sql.go

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

4 changes: 4 additions & 0 deletions coderd/database/dump.sql

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

67 changes: 67 additions & 0 deletions coderd/database/files.sql.go

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

1 change: 1 addition & 0 deletions coderd/database/migrations/000002_projects.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CREATE TABLE projects (

-- Enforces no active projects have the same name.
CREATE UNIQUE INDEX ON projects (organization_id, name) WHERE deleted = FALSE;
CREATE UNIQUE INDEX idx_projects_name_lower ON projects USING btree (lower(name));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylecarbs we seemed to be querying these by their lowercase names so I added indexes for them as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh wise. Good change!


-- Project Versions store historical project data. When a Project Version is imported,
-- an "import" job is queued to parse parameters. A Project Version
Expand Down
3 changes: 2 additions & 1 deletion coderd/database/migrations/000003_workspaces.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CREATE TABLE workspaces (
);

-- Enforces no active workspaces have the same name.
CREATE UNIQUE INDEX ON workspaces (owner_id, name) WHERE deleted = FALSE;
CREATE UNIQUE INDEX ON workspaces USING btree (owner_id, name) WHERE deleted = FALSE;
CREATE UNIQUE INDEX idx_workspaces_name_lower ON workspaces USING btree (lower(name));

CREATE TYPE workspace_transition AS ENUM (
'start',
Expand Down
81 changes: 81 additions & 0 deletions coderd/database/organization_members.sql.go

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

Loading