Files
photography/backend/migrations/004_create_photos.sql
xujiang c57ec3aa82 feat: 实现后端和管理后台基础架构
## 后端架构 (Go + Gin + GORM)
-  完整的分层架构 (API/Service/Repository)
-  PostgreSQL数据库设计和迁移脚本
-  JWT认证系统和权限控制
-  用户、照片、分类、标签等核心模型
-  中间件系统 (认证、CORS、日志)
-  配置管理和环境变量支持
-  结构化日志和错误处理
-  Makefile构建和部署脚本

## 管理后台架构 (React + TypeScript)
-  Vite + React 18 + TypeScript现代化架构
-  路由系统和状态管理 (Zustand + TanStack Query)
-  基于Radix UI的组件库基础
-  认证流程和权限控制
-  响应式设计和主题系统

## 数据库设计
-  用户表 (角色权限、认证信息)
-  照片表 (元数据、EXIF、状态管理)
-  分类表 (层级结构、封面图片)
-  标签表 (使用统计、标签云)
-  关联表 (照片-标签多对多)

## 技术特点
- 🚀 高性能: Gin框架 + GORM ORM
- 🔐 安全: JWT认证 + 密码加密 + 权限控制
- 📊 监控: 结构化日志 + 健康检查
- 🎨 现代化: React 18 + TypeScript + Vite
- 📱 响应式: Tailwind CSS + Radix UI

参考文档: docs/development/saved-docs/
2025-07-09 14:56:22 +08:00

55 lines
1.8 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- +migrate Up
CREATE TABLE photos (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
filename VARCHAR(255) NOT NULL,
file_path VARCHAR(500) NOT NULL,
file_size BIGINT,
mime_type VARCHAR(100),
width INTEGER,
height INTEGER,
category_id INTEGER REFERENCES categories(id),
exif JSONB,
taken_at TIMESTAMP,
location VARCHAR(255),
is_public BOOLEAN DEFAULT true,
status VARCHAR(20) DEFAULT 'draft',
view_count INTEGER DEFAULT 0,
like_count INTEGER DEFAULT 0,
user_id INTEGER NOT NULL REFERENCES users(id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP
);
-- 创建照片标签关联表
CREATE TABLE photo_tags (
photo_id INTEGER REFERENCES photos(id) ON DELETE CASCADE,
tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE,
PRIMARY KEY (photo_id, tag_id)
);
-- 创建索引
CREATE INDEX idx_photos_category_id ON photos(category_id);
CREATE INDEX idx_photos_user_id ON photos(user_id);
CREATE INDEX idx_photos_status ON photos(status);
CREATE INDEX idx_photos_is_public ON photos(is_public);
CREATE INDEX idx_photos_taken_at ON photos(taken_at);
CREATE INDEX idx_photos_created_at ON photos(created_at);
CREATE INDEX idx_photos_view_count ON photos(view_count);
CREATE INDEX idx_photos_like_count ON photos(like_count);
CREATE INDEX idx_photos_deleted_at ON photos(deleted_at);
-- 为JSONB字段创建GIN索引支持高效的JSON查询
CREATE INDEX idx_photos_exif_gin ON photos USING GIN (exif);
-- 全文搜索索引
CREATE INDEX idx_photos_title_gin ON photos USING GIN (to_tsvector('english', title));
CREATE INDEX idx_photos_description_gin ON photos USING GIN (to_tsvector('english', description));
-- +migrate Down
DROP TABLE IF EXISTS photo_tags;
DROP TABLE IF EXISTS photos;