Add initial project structure with core functionality for book and stationery uploads
- Created main application entry point in `main.go`. - Added configuration management in `config/config.go` and tests in `config/config_test.go`. - Implemented handlers for book and stationery uploads in `handlers/book.go` and `handlers/stationery.go`, including validation logic. - Established database connection and services in `services/database.go` and `services/book_service.go`. - Defined models for books and stationery in `models/book.go` and `models/stationery.go`. - Set up Firebase integration for image uploads in `services/firebase.go`. - Created migration scripts for database schema in `migrations/001_create_tables.sql` and subsequent updates. - Added CORS and error handling middleware. - Included comprehensive tests for handlers, services, and utilities. - Documented API endpoints and usage in `README.md` and migration instructions in `migrations/README.md`. - Introduced `.gitignore` to exclude unnecessary files and directories. - Added Go module support with `go.mod` and `go.sum` files. - Implemented utility functions for slug generation and validation in `utils/slug.go` and `utils/validation.go`.
This commit is contained in:
43
migrations/003_add_unique_slug_constraints.sql
Normal file
43
migrations/003_add_unique_slug_constraints.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
-- Add UNIQUE constraint to slug columns in both books and stationery tables
|
||||
-- This prevents duplicate slugs and enables slug-based image filename uniqueness
|
||||
|
||||
-- First, handle any existing duplicate slugs by appending a suffix
|
||||
-- For books
|
||||
UPDATE books b1
|
||||
SET slug = slug || '-' || book_code::text
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM books b2
|
||||
WHERE b2.slug = b1.slug
|
||||
AND b2.book_code < b1.book_code
|
||||
);
|
||||
|
||||
-- For stationery
|
||||
UPDATE stationery s1
|
||||
SET slug = slug || '-' || stationery_code::text
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM stationery s2
|
||||
WHERE s2.slug = s1.slug
|
||||
AND s2.stationery_code < s1.stationery_code
|
||||
);
|
||||
|
||||
-- Add unique constraint to books.slug (if not exists)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conname = 'books_slug_unique'
|
||||
) THEN
|
||||
ALTER TABLE books ADD CONSTRAINT books_slug_unique UNIQUE (slug);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Add unique constraint to stationery.slug (if not exists)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conname = 'stationery_slug_unique'
|
||||
) THEN
|
||||
ALTER TABLE stationery ADD CONSTRAINT stationery_slug_unique UNIQUE (slug);
|
||||
END IF;
|
||||
END $$;
|
||||
Reference in New Issue
Block a user