post_images.kind is image or video. A post can keep one video alongside up to four images. Reviewed-on: #21 Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #21.
This commit is contained in:
@@ -87,6 +87,12 @@ CREATE TABLE users (
|
||||
if err := migrateDiscordPostLinks(ctx, conn); err != nil {
|
||||
t.Fatalf("discord post links migration is not idempotent: %v", err)
|
||||
}
|
||||
if err := migratePostImageVideo(ctx, conn); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := migratePostImageVideo(ctx, conn); err != nil {
|
||||
t.Fatalf("post image video migration is not idempotent: %v", err)
|
||||
}
|
||||
if _, err := conn.ExecContext(ctx, `
|
||||
INSERT INTO users (id, name, role)
|
||||
VALUES ('homeowner', 'Home Owner', 'user'), ('plumber', 'The Plumber', 'admin');
|
||||
@@ -118,9 +124,9 @@ VALUES ('homeowner', 'root-1', 1);`); err != nil {
|
||||
}
|
||||
imageQueries := sqlc.New(conn)
|
||||
for _, image := range []sqlc.CreatePostImageParams{
|
||||
{ID: "root-image-1", PostID: "root-1", ObjectKey: "posts/root-1/1.jpg", PublicUrl: "https://cdn.example/root-1.jpg", Description: "Valve", Position: 0, Width: 1200, Height: 900, CreatedAt: "2026-08-26T08:00:00Z"},
|
||||
{ID: "root-image-2", PostID: "root-1", ObjectKey: "posts/root-1/2.png", PublicUrl: "https://cdn.example/root-2.png", Position: 1, Width: 900, Height: 1200, CreatedAt: "2026-08-26T08:00:00Z"},
|
||||
{ID: "reply-image-1", PostID: "reply-1", ObjectKey: "posts/reply-1/1.jpg", PublicUrl: "https://cdn.example/reply-1.jpg", Description: "Cartridge", Position: 0, Width: 1000, Height: 1000, CreatedAt: "2026-08-26T09:00:00Z"},
|
||||
{ID: "root-image-1", PostID: "root-1", ObjectKey: "posts/root-1/1.jpg", PublicUrl: "https://cdn.example/root-1.jpg", Description: "Valve", Kind: "image", Position: 0, Width: 1200, Height: 900, CreatedAt: "2026-08-26T08:00:00Z"},
|
||||
{ID: "root-image-2", PostID: "root-1", ObjectKey: "posts/root-1/2.png", PublicUrl: "https://cdn.example/root-2.png", Kind: "image", Position: 1, Width: 900, Height: 1200, CreatedAt: "2026-08-26T08:00:00Z"},
|
||||
{ID: "reply-image-1", PostID: "reply-1", ObjectKey: "posts/reply-1/1.jpg", PublicUrl: "https://cdn.example/reply-1.jpg", Description: "Cartridge", Kind: "image", Position: 0, Width: 1000, Height: 1000, CreatedAt: "2026-08-26T09:00:00Z"},
|
||||
} {
|
||||
if err := imageQueries.CreatePostImage(ctx, image); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -144,10 +150,24 @@ VALUES ('homeowner', 'root-1', 1);`); err != nil {
|
||||
}
|
||||
if err := imageQueries.CreatePostImage(ctx, sqlc.CreatePostImageParams{
|
||||
ID: "too-many", PostID: "root-1", ObjectKey: "posts/root-1/5.jpg",
|
||||
PublicUrl: "https://cdn.example/root-5.jpg", Position: 4,
|
||||
PublicUrl: "https://cdn.example/root-5.jpg", Kind: "image", Position: 5,
|
||||
Width: 100, Height: 100, CreatedAt: "2026-08-26T08:00:00Z",
|
||||
}); err == nil {
|
||||
t.Fatal("fifth image position unexpectedly succeeded")
|
||||
t.Fatal("position 5 unexpectedly succeeded")
|
||||
}
|
||||
if err := imageQueries.CreatePostImage(ctx, sqlc.CreatePostImageParams{
|
||||
ID: "root-video-1", PostID: "root-1", ObjectKey: "posts/root-1/clip.mp4",
|
||||
PublicUrl: "https://cdn.example/clip.mp4", Kind: "video", Position: 2,
|
||||
Width: 0, Height: 0, CreatedAt: "2026-08-26T08:00:00Z",
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := imageQueries.CreatePostImage(ctx, sqlc.CreatePostImageParams{
|
||||
ID: "root-video-2", PostID: "root-1", ObjectKey: "posts/root-1/clip-2.mp4",
|
||||
PublicUrl: "https://cdn.example/clip-2.mp4", Kind: "video", Position: 3,
|
||||
Width: 0, Height: 0, CreatedAt: "2026-08-26T08:00:00Z",
|
||||
}); err == nil {
|
||||
t.Fatal("second video unexpectedly succeeded")
|
||||
}
|
||||
if err := imageQueries.UpsertDiscordPostLink(ctx, sqlc.UpsertDiscordPostLinkParams{
|
||||
PostID: "root-1",
|
||||
|
||||
Reference in New Issue
Block a user