feat: add personal repositories organization override and update related configurations

This commit is contained in:
Arunavo Ray
2025-06-24 11:02:57 +05:30
parent d2bec1d56e
commit 68108b8383
12 changed files with 274 additions and 22 deletions

View File

@@ -28,11 +28,34 @@ try {
// Ensure all required tables exist
ensureTablesExist(sqlite);
// Run migrations
runMigrations(sqlite);
} catch (error) {
console.error("Error opening database:", error);
throw error;
}
/**
* Run database migrations
*/
function runMigrations(db: Database) {
try {
// Migration 1: Add destination_org column to organizations table
const orgTableInfo = db.query("PRAGMA table_info(organizations)").all() as Array<{name: string}>;
const hasDestinationOrg = orgTableInfo.some(col => col.name === 'destination_org');
if (!hasDestinationOrg) {
console.log("🔄 Running migration: Adding destination_org column to organizations table");
db.exec("ALTER TABLE organizations ADD COLUMN destination_org TEXT");
console.log("✅ Migration completed: destination_org column added");
}
} catch (error) {
console.error("❌ Error running migrations:", error);
// Don't throw - migrations should be non-breaking
}
}
/**
* Ensure all required tables exist in the database
*/
@@ -159,6 +182,7 @@ function createTable(db: Database, tableName: string) {
last_mirrored INTEGER,
error_message TEXT,
repository_count INTEGER NOT NULL DEFAULT 0,
destination_org TEXT,
created_at INTEGER NOT NULL DEFAULT (strftime('%s','now')),
updated_at INTEGER NOT NULL DEFAULT (strftime('%s','now')),
FOREIGN KEY (user_id) REFERENCES users(id),
@@ -437,6 +461,9 @@ export const organizations = sqliteTable("organizations", {
.notNull()
.default(true),
// Override destination organization for this GitHub org's repos
destinationOrg: text("destination_org"),
status: text("status").notNull().default("imported"),
lastMirrored: integer("last_mirrored", { mode: "timestamp" }),
errorMessage: text("error_message"),