feat(05-01): add aws-sdk-go-v2 modules, 0005_files migration, sqlc queries, and files.Store
- Add four aws-sdk-go-v2 modules: core, config, credentials, service/s3
- Write 0005_files.sql migration (tablo_files table with ON DELETE CASCADE)
- Write internal/db/queries/files.sql with InsertTabloFile, ListFilesByTablo, GetTabloFileByID, DeleteTabloFile
- Implement internal/files/store.go: FileStorer interface, Store struct, NewStore (UsePathStyle for MinIO), Upload (sniff+stream+bytecount), Delete, PresignDownload
- sqlc generate produces files.sql.go + TabloFile model (gitignored, regeneratable)
2026-05-15 10:18:16 +00:00
|
|
|
-- name: InsertTabloFile :one
|
|
|
|
|
INSERT INTO tablo_files (tablo_id, s3_key, filename, content_type, size_bytes)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
|
|
|
RETURNING id, tablo_id, s3_key, filename, content_type, size_bytes, created_at;
|
|
|
|
|
|
|
|
|
|
-- name: ListFilesByTablo :many
|
|
|
|
|
SELECT id, tablo_id, s3_key, filename, content_type, size_bytes, created_at
|
|
|
|
|
FROM tablo_files
|
|
|
|
|
WHERE tablo_id = $1
|
|
|
|
|
ORDER BY created_at DESC;
|
|
|
|
|
|
|
|
|
|
-- name: GetTabloFileByID :one
|
|
|
|
|
SELECT id, tablo_id, s3_key, filename, content_type, size_bytes, created_at
|
|
|
|
|
FROM tablo_files
|
|
|
|
|
WHERE id = $1 AND tablo_id = $2;
|
|
|
|
|
|
|
|
|
|
-- name: DeleteTabloFile :exec
|
|
|
|
|
DELETE FROM tablo_files WHERE id = $1 AND tablo_id = $2;
|
2026-05-15 14:32:48 +00:00
|
|
|
|
|
|
|
|
-- Find tablo_files rows whose owning tablo no longer exists.
|
|
|
|
|
-- Used by the orphan-file cleanup worker (Phase 6 WORK-02).
|
|
|
|
|
-- name: ListOrphanFiles :many
|
|
|
|
|
SELECT id, tablo_id, s3_key
|
|
|
|
|
FROM tablo_files tf
|
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
|
SELECT 1 FROM tablos t WHERE t.id = tf.tablo_id
|
|
|
|
|
);
|