feat: refactor skills API and database schema
- Replaced file-based skill category loading with API calls in the GET and POST methods of the skills route. - Added new `SkillsService` for handling skill category operations. - Updated SQL initialization script to create `skill_categories`, `skills`, and `skill_links` tables with appropriate relationships. - Enhanced `ApiClient` with methods for loading skill categories and creating new skills, improving API interaction. - Introduced error handling for skill category creation and loading processes.
This commit is contained in:
52
app/api/skills/migrate/route.ts
Normal file
52
app/api/skills/migrate/route.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { SkillsService } from "@/services";
|
||||
import { loadSkillCategoriesFromFiles } from "@/lib/skill-file-loader";
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
console.log("🚀 Starting skills migration via API...");
|
||||
|
||||
// Load all skill categories from JSON files
|
||||
const skillCategories = loadSkillCategoriesFromFiles();
|
||||
|
||||
console.log(`📊 Found ${skillCategories.length} categories`);
|
||||
|
||||
const totalSkills = skillCategories.reduce(
|
||||
(sum, cat) => sum + cat.skills.length,
|
||||
0
|
||||
);
|
||||
console.log(`🎯 Total skills to migrate: ${totalSkills}`);
|
||||
|
||||
// Bulk insert into database
|
||||
await SkillsService.bulkInsertSkillsFromJSON(skillCategories);
|
||||
|
||||
console.log("✅ Skills migration completed successfully!");
|
||||
|
||||
// Verify the migration
|
||||
const categoriesFromDb = await SkillsService.getSkillCategories();
|
||||
const totalSkillsInDb = categoriesFromDb.reduce(
|
||||
(sum, cat) => sum + cat.skills.length,
|
||||
0
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Skills migration completed successfully",
|
||||
stats: {
|
||||
categoriesMigrated: skillCategories.length,
|
||||
skillsMigrated: totalSkills,
|
||||
categoriesInDb: categoriesFromDb.length,
|
||||
skillsInDb: totalSkillsInDb,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("❌ Migration failed:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: "Failed to migrate skills",
|
||||
details: error instanceof Error ? error.message : "Unknown error",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user