This migration adds soft delete functionality to the blog posts system. Instead of permanently deleting posts, they are now marked as deleted and hidden from public view.
- Added
is_deletedcolumn toblog_poststable (BOOLEAN, default: false) - Added index on
is_deletedcolumn for better query performance
deletePost()now performs soft delete (setsis_deleted = true)getAllPosts()excludes deleted posts from public queriesgetPost()excludes deleted posts from public queries- New functions for admin:
getAllPostsIncludingDeleted()- Admin can see all postsgetPostIncludingDeleted()- Admin can access deleted posts
- Admin dashboard now shows "Deleted" badge for soft-deleted posts
The initDatabase() function has been updated to include the is_deleted column automatically. No manual migration needed.
Run the migration script:
npm run db:migrateThis script:
- Checks if
is_deletedcolumn exists - Adds the column if it doesn't exist (safe to run multiple times)
- Creates an index for better query performance
After applying the migration, verify:
-
Public View: Deleted posts should NOT appear on:
- Homepage (
/) - Individual post pages (
/blog/[id])
- Homepage (
-
Admin View: Deleted posts SHOULD appear with:
- "Deleted" badge in red
- Strikethrough title styling
- Still editable by the owner
-
Deletion Flow:
- Delete a post in admin dashboard
- Post shows as "Deleted" in admin
- Post is hidden from public pages
- Post data is preserved in database
If you need to revert the changes:
-- Remove the column (will lose soft delete data)
ALTER TABLE blog_posts DROP COLUMN is_deleted;
-- Remove the index
DROP INDEX IF EXISTS idx_blog_posts_deleted;Note: Rolling back will NOT restore hard-deleted posts. Only posts that were soft-deleted will remain.
Consider adding:
- "Restore" button in admin to un-delete posts
- Permanent delete option for admins
- Auto-purge of deleted posts after X days
- Bulk delete/restore operations