feat: add AUR repository support for Arch Linux packages

- Extended database schema and models to include 'aur' as a valid repository type alongside 'official' and 'third-party'
- Added repository filter UI in package browser for Arch platform to distinguish between official and AUR packages
- Enhanced init-db script with migration system to track and apply schema changes automatically
This commit is contained in:
Yusuf İpek
2025-11-12 20:43:50 +03:00
parent cce1098282
commit 560e78cb96
11 changed files with 395 additions and 226 deletions
+75 -3
View File
@@ -36,7 +36,7 @@ async function main() {
await admin.end().catch(() => {})
}
// Connect to the target DB and apply schema
// Connect to the target DB and apply schema, then run migrations
const db = new Pool({
host: DB_HOST,
port: DB_PORT,
@@ -59,10 +59,82 @@ async function main() {
} else {
console.error('❌ Schema apply error:', err)
process.exitCode = 1
// continue to attempt migrations anyway
}
} finally {
await db.end().catch(() => {})
}
// Ensure schema_migrations table exists
try {
await db.query(`
CREATE TABLE IF NOT EXISTS schema_migrations (
id SERIAL PRIMARY KEY,
filename TEXT UNIQUE NOT NULL,
applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
`)
} catch (err) {
console.error('❌ Failed to ensure schema_migrations table:', err)
process.exitCode = 1
}
// Discover migration files
try {
const migrationsDir = path.join(__dirname, 'migrations')
const migrationFiles = []
if (fs.existsSync(migrationsDir)) {
for (const f of fs.readdirSync(migrationsDir)) {
if (f.endsWith('.sql')) {
migrationFiles.push({ filename: f, fullpath: path.join(migrationsDir, f) })
}
}
}
// Back-compat: also pick up legacy root-level migrations named migrate-*.sql
for (const f of fs.readdirSync(__dirname)) {
if (f.startsWith('migrate-') && f.endsWith('.sql')) {
migrationFiles.push({ filename: f, fullpath: path.join(__dirname, f) })
}
}
// Sort by filename for deterministic order (e.g., 001_*, 002_* ...)
migrationFiles.sort((a, b) => a.filename.localeCompare(b.filename))
if (migrationFiles.length) {
console.log(`🚀 Running migrations (${migrationFiles.length} found)...`)
} else {
console.log('️ No migrations found')
}
for (const m of migrationFiles) {
try {
const { rows } = await db.query('SELECT 1 FROM schema_migrations WHERE filename = $1', [m.filename])
if (rows.length) {
console.log(`↪️ Skipping already applied migration: ${m.filename}`)
continue
}
const sql = fs.readFileSync(m.fullpath, 'utf8')
console.log(`➡️ Applying migration: ${m.filename}`)
await db.query('BEGIN')
await db.query(sql)
await db.query('INSERT INTO schema_migrations (filename) VALUES ($1)', [m.filename])
await db.query('COMMIT')
console.log(`✅ Migration applied: ${m.filename}`)
} catch (err) {
console.error(`❌ Migration failed: ${m.filename}`, err)
try { await db.query('ROLLBACK') } catch {}
process.exitCode = 1
break
}
}
} catch (err) {
console.error('❌ Failed during migration discovery/execution:', err)
process.exitCode = 1
}
// Done
await db.end().catch(() => {})
}
main().catch((e) => {
@@ -0,0 +1,5 @@
-- Add 'aur' to repository check constraint
ALTER TABLE packages DROP CONSTRAINT IF EXISTS packages_repository_check;
ALTER TABLE packages
ADD CONSTRAINT packages_repository_check
CHECK (repository IN ('official','third-party','aur'));