Compare commits
6 Commits
worktree-y
...
b1e369e9f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1e369e9f3 | ||
|
|
7305ad9ae6 | ||
|
|
fb759ebe33 | ||
|
|
b9e13105e1 | ||
|
|
70cb6759ea | ||
|
|
f94a18fee7 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -7,3 +7,7 @@ dist/
|
|||||||
build/
|
build/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.claude/
|
.claude/
|
||||||
|
|
||||||
|
# Config with secrets
|
||||||
|
config/settings.yaml
|
||||||
|
config/settings.local.yaml
|
||||||
22
README.md
22
README.md
@@ -11,3 +11,25 @@ source .venv/bin/activate # Linux/Mac
|
|||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
uvicorn app.main:app --reload
|
uvicorn app.main:app --reload
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Configuration is managed via YAML files in the `config/` directory.
|
||||||
|
|
||||||
|
### Configuration File
|
||||||
|
|
||||||
|
Edit `config/settings.yaml` to configure your environment:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
database:
|
||||||
|
sql_server:
|
||||||
|
host: your-host
|
||||||
|
port: 1433
|
||||||
|
database: your-database
|
||||||
|
username: your-username
|
||||||
|
password: your-password
|
||||||
|
```
|
||||||
|
|
||||||
|
### Local Overrides
|
||||||
|
|
||||||
|
For local development, create `config/settings.local.yaml` to override specific values without committing them.
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
from sqlalchemy.engine import URL
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
|
||||||
SQL_SERVER_HOST: str
|
|
||||||
SQL_SERVER_PORT: int = 1433
|
|
||||||
SQL_SERVER_DATABASE: str
|
|
||||||
SQL_SERVER_USERNAME: str
|
|
||||||
SQL_SERVER_PASSWORD: str
|
|
||||||
SQL_SERVER_DRIVER: str = "{ODBC Driver 18 for SQL Server}"
|
|
||||||
SQL_SERVER_TRUST_SERVER_CERTIFICATE: str = "yes"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def database_url(self) -> URL:
|
|
||||||
return URL.create(
|
|
||||||
"mssql+pyodbc",
|
|
||||||
username=self.SQL_SERVER_USERNAME,
|
|
||||||
password=self.SQL_SERVER_PASSWORD,
|
|
||||||
host=self.SQL_SERVER_HOST,
|
|
||||||
port=self.SQL_SERVER_PORT,
|
|
||||||
database=self.SQL_SERVER_DATABASE,
|
|
||||||
query={
|
|
||||||
"driver": self.SQL_SERVER_DRIVER.strip("{}"),
|
|
||||||
"TrustServerCertificate": self.SQL_SERVER_TRUST_SERVER_CERTIFICATE,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
|
||||||
14
app/main.py
14
app/main.py
@@ -1,7 +1,21 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.exceptions import RequestValidationError
|
from fastapi.exceptions import RequestValidationError
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
|
from config.settings import load_settings
|
||||||
|
|
||||||
|
# 加载配置文件,失败则退出
|
||||||
|
try:
|
||||||
|
settings = load_settings()
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(f"配置文件错误: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"加载配置失败: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
from app.api.v1.location import router as location_router
|
from app.api.v1.location import router as location_router
|
||||||
from app.api.v1.box import router as box_router
|
from app.api.v1.box import router as box_router
|
||||||
from app.services.location_service import DuplicateLocationError
|
from app.services.location_service import DuplicateLocationError
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
# 数据库配置
|
|
||||||
database:
|
|
||||||
sql_server:
|
|
||||||
host: 192.168.110.114
|
|
||||||
port: 1433
|
|
||||||
database: CompanyDB
|
|
||||||
username: peng
|
|
||||||
password: Cqbld123456.
|
|
||||||
driver: "{ODBC Driver 18 for SQL Server}"
|
|
||||||
trust_server_certificate: yes
|
|
||||||
Reference in New Issue
Block a user