mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-08 20:46:44 +03:00
feat: remove Redis dependencies and cleanup scripts after migrating to SQLite
This commit is contained in:
@@ -8,7 +8,6 @@ NODE_ENV=production
|
|||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
PORT=4321
|
PORT=4321
|
||||||
DATABASE_URL=sqlite://data/gitea-mirror.db
|
DATABASE_URL=sqlite://data/gitea-mirror.db
|
||||||
# Note: Redis is no longer required as SQLite is used for all functionality
|
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
JWT_SECRET=change-this-to-a-secure-random-string-in-production
|
JWT_SECRET=change-this-to-a-secure-random-string-in-production
|
||||||
|
|||||||
5
.github/workflows/docker-build.yml
vendored
5
.github/workflows/docker-build.yml
vendored
@@ -18,11 +18,6 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
services:
|
|
||||||
redis:
|
|
||||||
image: redis:7-alpine
|
|
||||||
ports: ['6379:6379']
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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
|
- Bun 1.2.9 or later
|
||||||
- A GitHub account with a personal access token
|
- A GitHub account with a personal access token
|
||||||
@@ -116,7 +116,7 @@ docker compose -f docker-compose.dev.yml up -d
|
|||||||
|
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!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]
|
> [!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`)
|
- `HOST`: Host to bind to (default: `0.0.0.0`)
|
||||||
- `PORT`: Port to listen on (default: `4321`)
|
- `PORT`: Port to listen on (default: `4321`)
|
||||||
- `JWT_SECRET`: Secret key for JWT token generation (important for security)
|
- `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
|
#### Manual Installation
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
"check-db": "bun scripts/manage-db.ts check",
|
"check-db": "bun scripts/manage-db.ts check",
|
||||||
"fix-db": "bun scripts/manage-db.ts fix",
|
"fix-db": "bun scripts/manage-db.ts fix",
|
||||||
"reset-users": "bun scripts/manage-db.ts reset-users",
|
"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",
|
"cleanup-events": "bun scripts/cleanup-events.ts",
|
||||||
"preview": "bunx --bun astro preview",
|
"preview": "bunx --bun astro preview",
|
||||||
"start": "bun dist/server/entry.mjs",
|
"start": "bun dist/server/entry.mjs",
|
||||||
|
|||||||
@@ -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");
|
|
||||||
@@ -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");
|
|
||||||
Reference in New Issue
Block a user