Skip to content

refactor: Generalize log ownership to allow for scratch jobs #182

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 5 commits into from
Feb 7, 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
Prev Previous commit
Next Next commit
Improve file table schema by using hash
  • Loading branch information
kylecarbs committed Feb 7, 2022
commit 6e6beb471c9f8517f1088993199aa42a4024079c
7 changes: 4 additions & 3 deletions database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func (q *fakeQuerier) GetAPIKeyByID(_ context.Context, id string) (database.APIK
return database.APIKey{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetFileByID(_ context.Context, id uuid.UUID) (database.File, error) {
func (q *fakeQuerier) GetFileByHash(_ context.Context, hash string) (database.File, error) {
q.mutex.Lock()
defer q.mutex.Unlock()

for _, file := range q.files {
if file.ID.String() == id.String() {
if file.Hash == hash {
return file, nil
}
}
Expand Down Expand Up @@ -588,8 +588,9 @@ func (q *fakeQuerier) InsertFile(_ context.Context, arg database.InsertFileParam

//nolint:gosimple
file := database.File{
ID: arg.ID,
Hash: arg.Hash,
CreatedAt: arg.CreatedAt,
Mimetype: arg.Mimetype,
Data: arg.Data,
}
q.files = append(q.files, file)
Expand Down
9 changes: 5 additions & 4 deletions database/dump.sql

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

5 changes: 3 additions & 2 deletions database/migrations/000002_projects.up.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
-- Store arbitrary data like project source code or avatars.
CREATE TABLE files (
id uuid NOT NULL UNIQUE,
CREATE TABLE file (
hash varchar(32) NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
mimetype varchar(64) NOT NULL,
data bytea NOT NULL
);

Expand Down
3 changes: 2 additions & 1 deletion database/models.go

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

2 changes: 1 addition & 1 deletion database/querier.go

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

10 changes: 5 additions & 5 deletions database/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ WHERE
LIMIT
1;

-- name: GetFileByID :one
-- name: GetFileByHash :one
SELECT
*
FROM
files
file
WHERE
id = $1
hash = $1
LIMIT
1;

Expand Down Expand Up @@ -364,9 +364,9 @@ VALUES

-- name: InsertFile :one
INSERT INTO
files (id, created_at, data)
file (hash, created_at, mimetype, data)
VALUES
($1, $2, $3) RETURNING *;
($1, $2, $3, $4) RETURNING *;

-- name: InsertProvisionerJobLogs :many
INSERT INTO
Expand Down
40 changes: 28 additions & 12 deletions database/query.sql.go

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