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:
54
scripts/migrate-skills.ts
Normal file
54
scripts/migrate-skills.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { SkillsService } from "../services/skills-service";
|
||||
import { loadSkillCategoriesFromFiles } from "../lib/skill-file-loader";
|
||||
|
||||
async function migrateSkillsToDatabase() {
|
||||
console.log("🚀 Starting skills migration...");
|
||||
|
||||
try {
|
||||
// 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();
|
||||
console.log(
|
||||
`✨ Verification: ${categoriesFromDb.length} categories in database`
|
||||
);
|
||||
|
||||
const totalSkillsInDb = categoriesFromDb.reduce(
|
||||
(sum, cat) => sum + cat.skills.length,
|
||||
0
|
||||
);
|
||||
console.log(`✨ Verification: ${totalSkillsInDb} skills in database`);
|
||||
} catch (error) {
|
||||
console.error("❌ Migration failed:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Run if called directly
|
||||
if (require.main === module) {
|
||||
migrateSkillsToDatabase()
|
||||
.then(() => {
|
||||
console.log("🎉 Migration script completed");
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("💥 Migration script failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
export { migrateSkillsToDatabase };
|
||||
Reference in New Issue
Block a user