[Phase 0 Reset]
- 清除舊版 app/、alembic/versions/、雜亂測試腳本
- 新 requirements.txt (移除 caldav/redis/keycloak-lib,加入 apscheduler/croniter/docker/paramiko/ping3/dnspython)
[Phase 1 資料庫]
- 9 張資料表 SQLAlchemy Models:tenants / accounts / schedules / schedule_logs /
tenant_schedule_results / account_schedule_results / servers / server_status_logs / system_status_logs
- Alembic migration 001_create_all_tables (已套用到 10.1.0.20:5433/virtual_mis)
- seed.py:schedules 初始 3 筆 / servers 初始 4 筆
[Phase 2 CRUD API]
- GET/POST/PUT/DELETE: /api/v1/tenants / accounts / servers / schedules
- /api/v1/system-status
- 帳號編碼自動產生 (prefix + seq_no 4碼左補0)
- 燈號 (lights) 從最新排程結果取得
[Phase 3 Watchdog]
- APScheduler interval 3分鐘,原子 UPDATE status=Going 防重複執行
- 手動觸發 API: POST /api/v1/schedules/{id}/run
[Phase 4 Service Clients]
- KeycloakClient:vmis-admin realm,REST API (不用 python-keycloak)
- MailClient:Docker Mailserver @ 10.1.0.254:8080,含 MX DNS 驗證
- DockerClient:docker-py 本機 + paramiko SSH 遠端 compose
- NextcloudClient:OCS API user/quota
- SystemChecker:功能驗證 (traefik routers>0 / keycloak token / SMTP EHLO / DB SELECT 1 / ping)
[TDD]
- 37 tests / 37 passed (2.11s)
- SQLite in-memory + StaticPool,無需外部 DB
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
from datetime import datetime
|
|
from sqlalchemy import Boolean, Column, Integer, String, Text, DateTime, Date
|
|
from sqlalchemy.orm import relationship
|
|
from app.core.database import Base
|
|
|
|
|
|
class Tenant(Base):
|
|
__tablename__ = "tenants"
|
|
|
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
|
code = Column(String(50), unique=True, nullable=False, index=True)
|
|
prefix = Column(String(20), nullable=False, default="")
|
|
name = Column(String(200), nullable=False)
|
|
name_eng = Column(String(200))
|
|
tax_id = Column(String(20))
|
|
domain = Column(String(200), unique=True, nullable=False, index=True)
|
|
address = Column(String(500))
|
|
tel = Column(String(50))
|
|
contact = Column(String(100))
|
|
contact_mobile = Column(String(50))
|
|
contact_email = Column(String(200))
|
|
keycloak_realm = Column(String(100))
|
|
plan_code = Column(String(50))
|
|
employee_limit = Column(Integer)
|
|
trial_start_date = Column(Date)
|
|
trial_end_date = Column(Date)
|
|
quota_per_user = Column(Integer, nullable=False, default=20) # GB
|
|
total_quota = Column(Integer, nullable=False, default=200) # GB
|
|
is_manager = Column(Boolean, nullable=False, default=False)
|
|
is_active = Column(Boolean, nullable=False, default=True)
|
|
status = Column(String(20), nullable=False, default="trial") # trial / active / inactive
|
|
note = Column(Text)
|
|
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
accounts = relationship("Account", back_populates="tenant", cascade="all, delete-orphan")
|
|
schedule_results = relationship("TenantScheduleResult", back_populates="tenant")
|