- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
8f65e10
b479668
03b8005
2ef8d8a
7e32318
5aeb544
449abba
303297c
55476d7
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -15,10 +15,8 @@ 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 $(wildcard coderd/database/queries/*.sql) | ||
coderd/database/generate.sh | ||
.PHONY: coderd/database/generate | ||
fmt/prettier: | ||
@@ -31,13 +29,18 @@ else | ||
endif | ||
.PHONY: fmt/prettier | ||
fmt/sql: $(wildcard coderd/database/queries/*.sql) | ||
# TODO: this is slightly slow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Could we use bash wait to make this faster? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The biggest problem is that it has to attempt to install via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ohhhhhh. I say we require | ||
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 | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
# This script turns many *.sql.go files into a single queries.sql.go file. This | ||
# is due to sqlc's behavior when using multiple sql files to output them to | ||
# multiple Go files. We decided it would be cleaner to move these to a single | ||
# file for readability. We should probably contribute the option to do this | ||
# upstream instead, because this is quite janky. | ||
set -euo pipefail | ||
cd"$(dirname"$0")" | ||
sqlc generate | ||
coadler marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
first=true | ||
forfiin queries/*.sql.go;do | ||
# Find the last line from the imports section and add 1. | ||
cut=$(grep -n')'"$fi"| head -n 1| cut -d: -f1) | ||
cut=$((cut+1)) | ||
# Copy the header from the first file only, ignoring the source comment. | ||
if$first;then | ||
head -n 4<"$fi"| grep -v"source"> queries.sql.go | ||
first=false | ||
fi | ||
# Append the file past the imports section into queries.sql.go. | ||
tail -n"+$cut"<"$fi">> queries.sql.go | ||
done | ||
# Remove temporary go files. | ||
rm -f queries/*.go | ||
# Fix struct/interface names. | ||
gofmt -w -r'Querier -> querier' --*.go | ||
gofmt -w -r'Queries -> sqlQuerier' --*.go | ||
# Ensure correct imports exist. Modules must all be downloaded so we get correct | ||
# suggestions. | ||
go mod download | ||
goimports -w queries.sql.go |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Uh oh!
There was an error while loading.Please reload this page.