From 34d5dc37db9ef880c9dbb5e280f17431ea42757f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Wed, 2 Jul 2025 20:44:46 +0800 Subject: [PATCH] Revert Gemini Changes. --- Dockerfile | 46 +++++++++++++--------------- package.json | 1 - scripts/db/export.ts | 73 -------------------------------------------- 3 files changed, 22 insertions(+), 98 deletions(-) delete mode 100644 scripts/db/export.ts diff --git a/Dockerfile b/Dockerfile index b062631..9837bf6 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,36 @@ # If you have customized your output directory, please just remove it. :) - FROM oven/bun:latest as builder +FROM oven/bun:latest as builder - WORKDIR /app +WORKDIR /app - # Copy package files - COPY package.json ./ - COPY bun.lock* package-lock.json* yarn.lock* ./ +# Copy package files +COPY package.json ./ +COPY bun.lock* package-lock.json* yarn.lock* ./ - # Install dependencies - RUN bun pm untrusted +# Install dependencies +RUN bun pm untrusted RUN bun install -RUN apt-get update && apt-get install -y postgresql-client +# Copy source files +COPY . . +RUN bun run generateVersionTag +# Build the application +RUN bun run build - # Copy source files - COPY . . - RUN bun run generateVersionTag - # Build the application - RUN bun run build +# Production stage +FROM oven/bun:latest - # Production stage - FROM oven/bun:latest +WORKDIR /app - WORKDIR /app +# Copy package files for production +COPY --from=builder /app/package.json ./ - # Copy package files for production - COPY --from=builder /app/package.json ./ +# Copy build outputs from builder +COPY --from=builder /app/.output /app/.output - # Copy build outputs from builder - COPY --from=builder /app/.output /app/.output +RUN bun install --production - RUN bun install --production +EXPOSE 3000 - EXPOSE 3000 - - CMD ["bun", "run", "start"] +CMD ["bun", "run", "start"] diff --git a/package.json b/package.json index cd588bc..e792e11 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "docs:preview": "vitepress preview docs", "wipedev": "./clean-dev-env.sh", "generateVersionTag": "bun run versionTagGenerate.ts", - "db:export": "bun run scripts/db/export.ts" }, "dependencies": { "@fontsource-variable/noto-sans-tc": "^5.2.6", diff --git a/scripts/db/export.ts b/scripts/db/export.ts deleted file mode 100644 index 3a96f43..0000000 --- a/scripts/db/export.ts +++ /dev/null @@ -1,73 +0,0 @@ - -import { exec } from 'child_process'; -import { promises as fs } from 'fs'; -import path from 'path'; - -// Function to get current date in YYYY-MM-DD format -function getCurrentDate() { - const date = new Date(); - const year = date.getFullYear(); - const month = (date.getMonth() + 1).toString().padStart(2, '0'); - const day = date.getDate().toString().padStart(2, '0'); - return `${year}-${month}-${day}`; -} - -// Main function to export the database -async function exportDatabase() { - try { - // Database connection details from environment variables - const dbName = process.env.POSTGRES_DB; - const dbUser = process.env.POSTGRES_USER; - const dbHost = process.env.POSTGRES_HOST; - const dbPort = process.env.POSTGRES_PORT; - - // Check if required environment variables are set - if (!dbName || !dbUser || !dbHost || !dbPort) { - console.error('Error: Missing required environment variables for database connection.'); - console.error('Please ensure POSTGRES_DB, POSTGRES_USER, POSTGRES_HOST, and POSTGRES_PORT are set.'); - return; - } - - // Tables to exclude from the export - const excludedTables = ['users', 'user_sessions']; // Add any other tables to exclude here - - // Path to the output directory - const outputDir = path.join(process.cwd(), 'exported_db'); - await fs.mkdir(outputDir, { recursive: true }); - - // Path for the output SQL file - const currentDate = getCurrentDate(); - const outputFilePath = path.join(outputDir, `db_export_${currentDate}.sql`); - - // Construct the pg_dump command - let command = `pg_dump "postgresql://${dbUser}:${process.env.POSTGRES_PASSWORD}@${dbHost}:${dbPort}/${dbName}" -F c -f "${outputFilePath}"`; - - // Add exclude-table flags for each table to be excluded - for (const table of excludedTables) { - command += ` --exclude-table-data=${table}`; - } - - console.log('Starting database export...'); - console.log(`Exporting to: ${outputFilePath}`); - console.log(`Excluding tables: ${excludedTables.join(', ')}`); - - // Execute the pg_dump command - exec(command, (error, stdout, stderr) => { - if (error) { - console.error(`Export failed: ${error.message}`); - return; - } - if (stderr) { - console.error(`pg_dump stderr: ${stderr}`); - } - console.log('Database export completed successfully.'); - console.log(`File saved to: ${outputFilePath}`); - }); - - } catch (err) { - console.error('An unexpected error occurred:', err); - } -} - -// Run the export function -exportDatabase();