danial 9366fd2a90 fix(ci): 修复 Docker 镜像构建与推送的标签问题
- 移除镜像标签中的分支变量,使用固定的 latest 标签
- 修正构建和推送命令格式,使其符合预期逻辑
- 保持登录登出流程不变,保障登录状态正确管理
2025-12-13 21:50:07 +08:00

Atlas 数据库迁移(声明式)

文件说明

  • atlas.hcl - Atlas 配置文件
  • schema.sql - 数据库 schema 定义(声明式)
  • .env.local - 本地环境配置
  • .env.example - 生产环境配置示例
  • generate-migration.sh - 从本地数据库导出 schema.sql
  • migrate.sh - 生产环境迁移脚本
  • test-local.sh - 本地测试脚本
  • Dockerfile - Docker 镜像配置
  • docker-compose.yml - Docker Compose 配置

使用步骤

1. 导出当前数据库 schema

./generate-migration.sh

2. 本地测试

./test-local.sh

3. 生产环境部署

方式一Docker Compose推荐

# 1. 复制环境变量配置
cp .env.example .env

# 2. 修改 .env 文件,填入生产数据库信息
# DB_USER=root
# DB_PASSWORD=your_password
# DB_HOST=mysql_host
# DB_PORT=3306
# DB_NAME=production_db

# 3. 执行迁移
docker-compose up db-migrate

方式二Docker Run

docker build -t db-migrate:latest .
docker run --rm \
  -e DB_URL="mysql://user:password@host:3306/database" \
  db-migrate:latest

注意事项

  1. 本地测试需修改 .env.local 中的 MYSQL_CONTAINER 为实际容器名称
  2. 生产环境需配置 .env 文件或设置环境变量
  3. 使用声明式迁移schema.sql 是数据库最终状态
  4. Atlas 自动计算并执行差异变更
Description
No description provided
Readme 59 KiB
Languages
HCL 57.6%
Dockerfile 26.7%
Shell 15.7%