Remove database schema updates and migrations; simplify entrypoint script and related commands

This commit is contained in:
Arunavo Ray
2025-05-19 09:02:39 +05:30
parent 8a9acd4bf7
commit e1faea72d5
5 changed files with 5 additions and 163 deletions

View File

@@ -124,17 +124,8 @@ else
node dist/scripts/manage-db.js fix node dist/scripts/manage-db.js fix
fi fi
# Update the database schema # Since the application is not used by anyone yet, we've removed the schema updates and migrations
echo "Updating database schema..." echo "Database already exists, no migrations needed."
if [ -f "dist/scripts/manage-db.js" ]; then
node dist/scripts/manage-db.js update-schema
fi
# Run migrations
echo "Running database migrations..."
if [ -f "dist/scripts/run-migrations.js" ]; then
node dist/scripts/run-migrations.js
fi
fi fi
# Start the application # Start the application

View File

@@ -16,9 +16,6 @@
"check-db": "tsx scripts/manage-db.ts check", "check-db": "tsx scripts/manage-db.ts check",
"fix-db": "tsx scripts/manage-db.ts fix", "fix-db": "tsx scripts/manage-db.ts fix",
"reset-users": "tsx scripts/manage-db.ts reset-users", "reset-users": "tsx scripts/manage-db.ts reset-users",
"update-schema": "tsx scripts/manage-db.ts update-schema",
"db-auto": "tsx scripts/manage-db.ts auto",
"run-migrations": "tsx scripts/run-migrations.ts",
"preview": "astro preview", "preview": "astro preview",
"start": "node dist/server/entry.mjs", "start": "node dist/server/entry.mjs",
"start:fresh": "pnpm cleanup-db && pnpm manage-db init && node dist/server/entry.mjs", "start:fresh": "pnpm cleanup-db && pnpm manage-db init && node dist/server/entry.mjs",

View File

@@ -224,102 +224,8 @@ async function checkDatabase() {
} }
} }
/** // Database schema updates and migrations have been removed
* Update database schema // since the application is not used by anyone yet
*/
async function updateSchema() {
console.log(`Checking and updating database schema at ${dbPath}...`);
// Check if the database exists
if (!fs.existsSync(dataDbFile)) {
console.log(
"⚠️ Database file doesn't exist. Run 'pnpm manage-db init' first to create it."
);
return;
}
try {
console.log("Checking for missing columns in mirror_jobs table...");
// Check if repository_id column exists in mirror_jobs table
const tableInfoResult = await client.execute(
`PRAGMA table_info(mirror_jobs)`
);
// Get column names
const columns = tableInfoResult.rows.map((row) => row.name);
// Check for repository_id column
if (!columns.includes("repository_id")) {
console.log(
"Adding missing repository_id column to mirror_jobs table..."
);
await client.execute(
`ALTER TABLE mirror_jobs ADD COLUMN repository_id TEXT;`
);
console.log("✅ Added repository_id column to mirror_jobs table.");
}
// Check for repository_name column
if (!columns.includes("repository_name")) {
console.log(
"Adding missing repository_name column to mirror_jobs table..."
);
await client.execute(
`ALTER TABLE mirror_jobs ADD COLUMN repository_name TEXT;`
);
console.log("✅ Added repository_name column to mirror_jobs table.");
}
// Check for organization_id column
if (!columns.includes("organization_id")) {
console.log(
"Adding missing organization_id column to mirror_jobs table..."
);
await client.execute(
`ALTER TABLE mirror_jobs ADD COLUMN organization_id TEXT;`
);
console.log("✅ Added organization_id column to mirror_jobs table.");
}
// Check for organization_name column
if (!columns.includes("organization_name")) {
console.log(
"Adding missing organization_name column to mirror_jobs table..."
);
await client.execute(
`ALTER TABLE mirror_jobs ADD COLUMN organization_name TEXT;`
);
console.log("✅ Added organization_name column to mirror_jobs table.");
}
// Check for details column
if (!columns.includes("details")) {
console.log("Adding missing details column to mirror_jobs table...");
await client.execute(`ALTER TABLE mirror_jobs ADD COLUMN details TEXT;`);
console.log("✅ Added details column to mirror_jobs table.");
}
// Check for mirrored_location column in repositories table
const repoColumns = await client.execute(`PRAGMA table_info(repositories)`);
const repoColumnNames = repoColumns.rows.map((row: any) => row.name);
if (!repoColumnNames.includes("mirrored_location")) {
console.log(
"Adding missing mirrored_location column to repositories table..."
);
await client.execute(
`ALTER TABLE repositories ADD COLUMN mirrored_location TEXT DEFAULT '';`
);
console.log("✅ Added mirrored_location column to repositories table.");
}
console.log("✅ Schema update completed successfully.");
} catch (error) {
console.error("❌ Error updating schema:", error);
process.exit(1);
}
}
/** /**
* Initialize the database * Initialize the database
@@ -730,7 +636,7 @@ async function fixDatabaseIssues() {
// Check if we can connect to the database // Check if we can connect to the database
try { try {
// Try to query the database // Try to query the database
const configCount = await db.select().from(configs).limit(1); await db.select().from(configs).limit(1);
console.log(`✅ Successfully connected to the database.`); console.log(`✅ Successfully connected to the database.`);
} catch (error) { } catch (error) {
console.error("❌ Error connecting to the database:", error); console.error("❌ Error connecting to the database:", error);
@@ -766,17 +672,11 @@ async function main() {
case "reset-users": case "reset-users":
await resetUsers(); await resetUsers();
break; break;
case "update-schema":
await updateSchema();
break;
case "auto": case "auto":
// Auto mode: check, fix, and initialize if needed // Auto mode: check, fix, and initialize if needed
console.log("Running in auto mode: check, fix, and initialize if needed"); console.log("Running in auto mode: check, fix, and initialize if needed");
await fixDatabaseIssues(); await fixDatabaseIssues();
// Also update schema in auto mode
await updateSchema();
if (!fs.existsSync(dataDbFile)) { if (!fs.existsSync(dataDbFile)) {
await initializeDatabase(); await initializeDatabase();
} else { } else {
@@ -790,7 +690,6 @@ Available commands:
init - Initialize the database (only if it doesn't exist) init - Initialize the database (only if it doesn't exist)
fix - Fix database location issues fix - Fix database location issues
reset-users - Remove all users and their data reset-users - Remove all users and their data
update-schema - Update the database schema to the latest version
auto - Automatic mode: check, fix, and initialize if needed auto - Automatic mode: check, fix, and initialize if needed
Usage: pnpm manage-db [command] Usage: pnpm manage-db [command]

View File

@@ -1,18 +0,0 @@
import { addMirroredLocationColumn } from "../src/lib/db/migrations/add-mirrored-location";
async function runMigrations() {
try {
console.log("Running database migrations...");
// Run the migration to add the mirrored_location column
await addMirroredLocationColumn();
console.log("All migrations completed successfully");
process.exit(0);
} catch (error) {
console.error("Migration failed:", error);
process.exit(1);
}
}
runMigrations();

View File

@@ -1,27 +0,0 @@
import { client } from "@/lib/db";
/**
* Migration script to add the mirrored_location column to the repositories table
*/
export async function addMirroredLocationColumn() {
try {
console.log("Starting migration: Adding mirrored_location column to repositories table");
// Check if the column already exists
const tableInfo = await client.execute(`PRAGMA table_info(repositories)`);
const columnExists = tableInfo.rows.some((row: any) => row.name === "mirrored_location");
if (columnExists) {
console.log("Column mirrored_location already exists, skipping migration");
return;
}
// Add the mirrored_location column
await client.execute(`ALTER TABLE repositories ADD COLUMN mirrored_location TEXT DEFAULT ''`);
console.log("Migration completed successfully: mirrored_location column added");
} catch (error) {
console.error("Migration failed:", error);
throw error;
}
}