Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,43 @@ cd openGecko
cp backend/.env.example backend/.env
# ⚠️ 生产环境务必编辑 backend/.env,修改 JWT_SECRET_KEY 为强随机字符串

# 3. 启动
docker compose up -d
# 3. 构建并启动(首次或代码更新后必须加 --build)
docker compose up -d --build
```

启动后访问:
- 🖥️ **平台界面**:http://localhost
- 📖 **API 文档**:http://localhost:8000/docs

### 完整清理重部署

升级遇到问题或需要全量重置时,用以下命令彻底清除旧环境后重新部署:

```bash
# 停止并移除容器、网络
docker compose down

# 删除旧镜像(强制下次重新构建)
docker rmi opengecko-backend opengecko-frontend 2>/dev/null || true

# 删除持久化数据库(⚠️ 数据不可恢复,谨慎操作)
rm -f backend/opengecko.db

# 重新构建并启动
docker compose up -d --build
```

一行执行版:

```bash
docker compose down && \
docker rmi opengecko-backend opengecko-frontend 2>/dev/null; \
rm -f backend/opengecko.db && \
docker compose up -d --build
```

> **注意**:`backend/opengecko.db` 是通过 `docker-compose.override.yml` 挂载到宿主机的 SQLite 数据库文件,删除后所有数据(社区、内容、用户等)将清空,重启后重新初始化。生产环境使用 PostgreSQL 时此步骤不适用。

### 首次使用流程

1. 使用 `.env` 中配置的默认账号登录(默认 `admin` / `admin123`)
Expand Down
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ USER appuser
EXPOSE 8000

# entrypoint 先执行 alembic upgrade head,再启动应用
ENTRYPOINT ["/app/entrypoint.sh"]
ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"]
# 开发环境使用 uvicorn,生产通过 docker-compose.prod.yml 覆盖为 gunicorn
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
2 changes: 2 additions & 0 deletions backend/alembic/versions/001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def upgrade():
"publish_records",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("content_id", sa.Integer(), nullable=False),
sa.Column("community_id", sa.Integer(), nullable=True, index=True),
sa.Column("channel", sa.String(50), nullable=False),
sa.Column("status", sa.String(50), nullable=True),
sa.Column("platform_article_id", sa.String(200), nullable=True),
Expand All @@ -194,6 +195,7 @@ def upgrade():
sa.Column("error_message", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(["content_id"], ["contents.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["community_id"], ["communities.id"], ondelete="CASCADE"),
)

# ------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions backend/alembic/versions/002_schema_additions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


def upgrade() -> None:

# ── 1. contents.community_id → nullable ────────────────────────────────────
with op.batch_alter_table("contents") as batch_op:
batch_op.alter_column("community_id", existing_type=sa.Integer(), nullable=True)
Expand Down
Loading