-
Notifications
You must be signed in to change notification settings - Fork 937
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
Changes from all commits
8f65e10
b479668
03b8005
2ef8d8a
7e32318
5aeb544
449abba
303297c
55476d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 resolved
Hide resolved
|
||
|
||
first=true | ||
for fi in 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
The biggest problem is that it has to attempt to install via
npx
every time, otherwise it's pretty fast! Cannpx
be called concurrently?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhhhhh. I say we require
sql-formatter
installed globally then.