From 4aa7e665acc51ef3257e985b1509e588291899a3 Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Wed, 21 May 2025 11:31:22 +0530 Subject: [PATCH] feat: remove Redis dependencies and cleanup scripts after migrating to SQLite --- .env.example | 1 - .github/workflows/docker-build.yml | 5 --- README.md | 7 ++-- package.json | 2 -- scripts/cleanup-redis.ts | 33 ------------------- scripts/migrate-db.ts | 53 ------------------------------ 6 files changed, 3 insertions(+), 98 deletions(-) delete mode 100644 scripts/cleanup-redis.ts delete mode 100644 scripts/migrate-db.ts diff --git a/.env.example b/.env.example index 292522d..4d6d768 100644 --- a/.env.example +++ b/.env.example @@ -8,7 +8,6 @@ NODE_ENV=production HOST=0.0.0.0 PORT=4321 DATABASE_URL=sqlite://data/gitea-mirror.db -# Note: Redis is no longer required as SQLite is used for all functionality # Security JWT_SECRET=change-this-to-a-secure-random-string-in-production diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index c6d615d..7367c2f 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -18,11 +18,6 @@ jobs: contents: write packages: write - services: - redis: - image: redis:7-alpine - ports: ['6379:6379'] - steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index a161749..3a1b671 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Easily configure your GitHub and Gitea connections, set up automatic mirroring s See the [Quick Start Guide](docs/quickstart.md) for detailed instructions on getting up and running quickly. --### Prerequisites +### Prerequisites - Bun 1.2.9 or later - A GitHub account with a personal access token @@ -116,7 +116,7 @@ docker compose -f docker-compose.dev.yml up -d > [!IMPORTANT] -> **Docker Compose is the recommended method for running Gitea Mirror** as it automatically sets up the required Redis sidecar service that the application depends on. +> **Docker Compose is the recommended method for running Gitea Mirror** as it provides a consistent environment with proper volume management for the SQLite database. > [!NOTE] @@ -191,7 +191,6 @@ The Docker container can be configured with the following environment variables: - `HOST`: Host to bind to (default: `0.0.0.0`) - `PORT`: Port to listen on (default: `4321`) - `JWT_SECRET`: Secret key for JWT token generation (important for security) -- `REDIS_URL`: URL for Redis connection (required, default: none). When using Docker Compose, this should be set to `redis://redis:6379` to connect to the Redis container. #### Manual Installation @@ -355,7 +354,7 @@ docker compose -f docker-compose.dev.yml up -d ## Technologies Used - **Frontend**: Astro, React, Shadcn UI, Tailwind CSS v4 - - **Backend**: Bun +- **Backend**: Bun - **Database**: SQLite (handles both data storage and event notifications) - **API Integration**: GitHub API (Octokit), Gitea API diff --git a/package.json b/package.json index 791e179..3903398 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,6 @@ "check-db": "bun scripts/manage-db.ts check", "fix-db": "bun scripts/manage-db.ts fix", "reset-users": "bun scripts/manage-db.ts reset-users", - "migrate-db": "bun scripts/migrate-db.ts", - "cleanup-redis": "bun scripts/cleanup-redis.ts", "cleanup-events": "bun scripts/cleanup-events.ts", "preview": "bunx --bun astro preview", "start": "bun dist/server/entry.mjs", diff --git a/scripts/cleanup-redis.ts b/scripts/cleanup-redis.ts deleted file mode 100644 index dfa0146..0000000 --- a/scripts/cleanup-redis.ts +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bun -/** - * Cleanup script to remove Redis-related files and code - * This script should be run when migrating from Redis to SQLite - */ - -import fs from "fs"; -import path from "path"; - -// Files to remove -const filesToRemove = [ - "src/lib/redis.ts" -]; - -// Remove files -console.log("Removing Redis-related files..."); -for (const file of filesToRemove) { - const filePath = path.join(process.cwd(), file); - if (fs.existsSync(filePath)) { - fs.unlinkSync(filePath); - console.log(`Removed: ${file}`); - } else { - console.log(`File not found: ${file}`); - } -} - -console.log("\nRedis cleanup completed successfully"); -console.log("\nReminder: You should also remove Redis from your Docker Compose files and environment variables."); -console.log("The following files have been updated to use SQLite instead of Redis:"); -console.log("- src/lib/helpers.ts"); -console.log("- src/pages/api/sse/index.ts"); -console.log("\nNew files created:"); -console.log("- src/lib/events.ts"); diff --git a/scripts/migrate-db.ts b/scripts/migrate-db.ts deleted file mode 100644 index 03d9d09..0000000 --- a/scripts/migrate-db.ts +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bun -/** - * Database migration script to add the events table - * This script should be run when upgrading from a version that used Redis - */ - -import { Database } from "bun:sqlite"; -import fs from "fs"; -import path from "path"; - -// Define the database path -const dataDir = path.join(process.cwd(), "data"); -if (!fs.existsSync(dataDir)) { - fs.mkdirSync(dataDir, { recursive: true }); -} - -const dbPath = path.join(dataDir, "gitea-mirror.db"); -if (!fs.existsSync(dbPath)) { - console.error("Database file not found:", dbPath); - process.exit(1); -} - -// Open the database -const db = new Database(dbPath); - -// Check if the events table already exists -const tableExists = db.query("SELECT name FROM sqlite_master WHERE type='table' AND name='events'").get(); - -if (tableExists) { - console.log("Events table already exists, skipping migration"); - process.exit(0); -} - -// Create the events table -console.log("Creating events table..."); -db.exec(` -CREATE TABLE events ( - id TEXT PRIMARY KEY, - user_id TEXT NOT NULL, - channel TEXT NOT NULL, - payload TEXT NOT NULL, - read INTEGER NOT NULL DEFAULT 0, - created_at INTEGER NOT NULL DEFAULT (unixepoch()), - FOREIGN KEY (user_id) REFERENCES users(id) -); - --- Create indexes for efficient querying -CREATE INDEX idx_events_user_channel ON events(user_id, channel); -CREATE INDEX idx_events_created_at ON events(created_at); -CREATE INDEX idx_events_read ON events(read); -`); - -console.log("Migration completed successfully");