feat: initialize project structure with SQLite database, crawler framework, and LLM-based JD analysis integration
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type DB struct {
|
||||
*sql.DB
|
||||
}
|
||||
|
||||
func InitDB(dbPath string) (*DB, error) {
|
||||
if dbPath == "" {
|
||||
dbPath = "data/db/hireme.db"
|
||||
}
|
||||
|
||||
conn, err := sql.Open("sqlite3", dbPath+"?_foreign_keys=on")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sqlite database: %w", err)
|
||||
}
|
||||
|
||||
if err := conn.Ping(); err != nil {
|
||||
return nil, fmt.Errorf("failed to ping sqlite database: %w", err)
|
||||
}
|
||||
|
||||
database := &DB{DB: conn}
|
||||
if err := database.migrate(); err != nil {
|
||||
return nil, fmt.Errorf("failed to run sqlite migrations: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("[DB] SQLite database initialized successfully at %s", dbPath)
|
||||
return database, nil
|
||||
}
|
||||
|
||||
func (db *DB) migrate() error {
|
||||
schema := `
|
||||
CREATE TABLE IF NOT EXISTS search_targets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
target_url TEXT NOT NULL,
|
||||
platform TEXT NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT 1,
|
||||
last_crawled_at DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS raw_jobs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
canonical_id TEXT UNIQUE NOT NULL,
|
||||
target_id INTEGER REFERENCES search_targets(id),
|
||||
title TEXT NOT NULL,
|
||||
company TEXT NOT NULL,
|
||||
location TEXT,
|
||||
apply_url TEXT NOT NULL,
|
||||
raw_content TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'PENDING',
|
||||
crawled_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS job_analyses (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
raw_job_id INTEGER UNIQUE NOT NULL REFERENCES raw_jobs(id) ON DELETE CASCADE,
|
||||
score REAL DEFAULT 0.0,
|
||||
is_qualified BOOLEAN NOT NULL DEFAULT 0,
|
||||
matched_highlights JSON,
|
||||
missing_highlights JSON,
|
||||
tailoring_suggestions JSON,
|
||||
status TEXT NOT NULL DEFAULT 'PENDING',
|
||||
analyzed_at DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS job_applications (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
raw_job_id INTEGER UNIQUE NOT NULL REFERENCES raw_jobs(id) ON DELETE CASCADE,
|
||||
status TEXT NOT NULL DEFAULT 'SAVED',
|
||||
notes TEXT,
|
||||
applied_at DATETIME,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`
|
||||
|
||||
_, err := db.Exec(schema)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user