3.3 KiB
3.3 KiB
Backend Updates Summary
Database Schema Changes
Posts Table - New Fields Added
-
ghost_slug(VARCHAR(255), nullable)- Stores the Ghost post slug for association
- Used to link VoxBlog posts with their Ghost counterparts
-
ghost_published_at(DATETIME(3), nullable)- Timestamp when the post was published to Ghost
- Helps track publication history
-
selected_image_keys(TEXT, nullable)- JSON array of selected image keys for the post
- Persists user's image selection for the Generate step
- Stored as JSON string, parsed on retrieval
Migration File
- Location:
apps/api/drizzle/0001_jittery_revanche.sql - Status: ✅ Migration has been generated and applied
ALTER TABLE `posts` ADD `ghost_slug` varchar(255);
ALTER TABLE `posts` ADD `ghost_published_at` datetime(3);
ALTER TABLE `posts` ADD `selected_image_keys` text;
To apply this migration (if needed on other environments):
cd apps/api
pnpm drizzle:migrate
API Endpoint Changes
1. GET /api/posts/:id
Added Response Fields:
ghostPostId: string | nullghostSlug: string | nullghostPublishedAt: Date | nullghostUrl: string | nullselectedImageKeys: string[] (parsed from JSON)
2. POST /api/posts
Added Request Body Fields:
selectedImageKeys: string[] (optional)ghostPostId: string (optional)ghostSlug: string (optional)ghostPublishedAt: string (optional, ISO date string)ghostUrl: string (optional)
Behavior:
selectedImageKeysis serialized to JSON before storage- Ghost fields are only updated if provided in the request
- All fields are nullable and optional
3. GET /api/media/list
Added Query Parameters:
page: number (default: 1, min: 1)pageSize: number (default: 50, min: 1, max: 200)
Updated Response:
{
"items": [...],
"total": number,
"page": number,
"pageSize": number
}
Note: Due to S3 limitations, pagination fetches page * pageSize items and slices them. For large datasets, consider implementing cursor-based pagination or caching.
Files Modified
-
apps/api/src/db/schema.ts- Added new fields to posts table definition
-
apps/api/src/posts.ts- Updated GET endpoint to return new fields
- Updated POST endpoint to accept and store new fields
- Added JSON serialization/deserialization for
selectedImageKeys
-
apps/api/src/media.ts- Added pagination support to
/listendpoint - Implemented page and pageSize query parameters
- Added pagination support to
Testing Checklist
- Run database migration ✅
- Test POST
/api/postswithselectedImageKeysarray - Test GET
/api/posts/:idreturnsselectedImageKeysas array - Test POST
/api/postswith Ghost fields - Test GET
/api/media/list?page=1&pageSize=50 - Test GET
/api/media/list?page=2&pageSize=50 - Verify
selectedImageKeyspersists across save/load cycles - Verify Ghost fields update correctly on publish
Frontend Integration
The frontend has been updated to:
- Send
selectedImageKeyswhen saving posts - Load
selectedImageKeyswhen opening posts - Use pagination for media library
- Update post status after Ghost publish
- Auto-upload audio recordings
All frontend changes are complete and ready to work with these backend updates.