From 87682bb7ce5992940267eb7374ddb9b54378108f Mon Sep 17 00:00:00 2001 From: yourname Date: Tue, 13 May 2025 02:38:21 +0000 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=AE=A1=E7=90=86=E5=85=A5=E5=8F=A3=E6=8C=89?= =?UTF-8?q?=E9=92=AE,=20=E6=97=A0=E9=9C=80=E7=99=BB=E5=BD=95=E5=8D=B3?= =?UTF-8?q?=E5=8F=AF=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HISTORY.md | 2 + client/migrations/migrations_app.tsx | 95 ++++++++++++++++++++++++++++ server/app.tsx | 45 ++++++++++--- 3 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 HISTORY.md create mode 100644 client/migrations/migrations_app.tsx diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 0000000..e1b633e --- /dev/null +++ b/HISTORY.md @@ -0,0 +1,2 @@ +2025.05.13 0.1.0 +首页添加了迁移管理入口按钮, 无需登录即可访问 \ No newline at end of file diff --git a/client/migrations/migrations_app.tsx b/client/migrations/migrations_app.tsx new file mode 100644 index 0000000..5afc548 --- /dev/null +++ b/client/migrations/migrations_app.tsx @@ -0,0 +1,95 @@ +import React, { useState } from 'react'; +import { createRoot } from 'react-dom/client'; +import { Button, Space, Alert, Spin, Typography } from 'antd'; +import axios from 'axios'; +import { + QueryClient, + QueryClientProvider, +} from '@tanstack/react-query'; + +const { Title } = Typography; + +// 创建QueryClient实例 +const queryClient = new QueryClient(); + +interface MigrationResponse { + success: boolean; + error?: string; + failedResult?: any; +} + +const MigrationsApp: React.FC = () => { + const [loading, setLoading] = useState(false); + const [migrationResult, setMigrationResult] = useState(null); + + const runMigrations = async () => { + try { + setLoading(true); + setMigrationResult(null); + + const response = await axios.get('/api/migrations'); + setMigrationResult(response.data); + } catch (error: any) { + setMigrationResult({ + success: false, + error: error.response?.data?.error || '数据库迁移失败', + failedResult: error.response?.data?.failedResult + }); + } finally { + setLoading(false); + } + }; + + return ( +
+ 数据库迁移管理 + + + + + {loading && } + + {migrationResult && ( + migrationResult.success ? ( + + ) : ( + +

{migrationResult.error}

+ {migrationResult.failedResult && ( +
+                      {JSON.stringify(migrationResult.failedResult, null, 2)}
+                    
+ )} + + } + type="error" + showIcon + /> + ) + )} +
+
+ ); +}; + +// 渲染应用 +const root = createRoot(document.getElementById('root') as HTMLElement); +root.render( + + + +); \ No newline at end of file diff --git a/server/app.tsx b/server/app.tsx index e9f0740..6d6d6f8 100644 --- a/server/app.tsx +++ b/server/app.tsx @@ -347,6 +347,14 @@ export default function({ apiClient, app, moduleDir }: ModuleParams) { 进入管理后台 + {/* 迁移管理入口按钮 */} + + 数据库迁移 + + {/* 移动端入口按钮 */} { return (c: HonoContext) => { const isProd = GLOBAL_CONFIG.ENV === 'production'; + const isLocalDeploy = Deno.env.get('IS_LOCAL_DEPLOY') === 'true'; return c.html( + {isProd && } {title} - {isProd ? ( + {isLocalDeploy ? ( ) : ( - + )} - {isProd ? () : ()} + {isLocalDeploy ? () : ()}