mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
models migrated and data insert success with dbeaver
This commit is contained in:
+12
-1
@@ -40,8 +40,19 @@ func InitDB(shouldMigrate bool) *gorm.DB {
|
||||
if err := db.AutoMigrate(&models.APIKey{}); err != nil {
|
||||
log.Fatalf("migrate APIKey: %v", err)
|
||||
}
|
||||
// Game Models
|
||||
if err := db.AutoMigrate(
|
||||
&models.Game{},
|
||||
&models.LineScore{},
|
||||
&models.PlayerGameBasicStat{},
|
||||
&models.PlayerGameAdvStat{},
|
||||
&models.TeamGameBasicStat{},
|
||||
&models.TeamGameAdvStat{},
|
||||
); err != nil {
|
||||
log.Fatalf("migrate game models: %v", err)
|
||||
}
|
||||
metrics.DBOperationsTotal.WithLabelValues("migrate", "database").Inc()
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ services:
|
||||
db-init:
|
||||
build: .
|
||||
env_file: .env
|
||||
command: ["/nba_go"]
|
||||
command: ["/nba_go", "import-data"]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// importPlayerAdvanced fetches and stores advanced stats for seasons 2017–2025
|
||||
func importPlayerAdvanced(db *gorm.DB) {
|
||||
for season := 2024; season <= 2025; season++ {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, false); err != nil {
|
||||
log.Printf("advanced import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func importPlayerAdvanced(db *gorm.DB) {
|
||||
|
||||
// importPlayerAdvancedPlayoffs fetches and stores advanced stats for playoffs seasons 2023–2025
|
||||
func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
||||
for season := 2024; season <= 2025; season++ {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, true); err != nil {
|
||||
log.Printf("advanced import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
||||
|
||||
// importPlayerTotalsScrape fetches & stores scraped regular-season total stats
|
||||
func importPlayerTotalsScrape(db *gorm.DB) {
|
||||
for season := 2024; season <= 2025; season++ {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil {
|
||||
log.Printf("scraped totals import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func importPlayerTotalsScrape(db *gorm.DB) {
|
||||
|
||||
// importPlayerPlayoffsScrape fetches & stores scraped playoff total stats
|
||||
func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
||||
for season := 2024; season <= 2025; season++ {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil {
|
||||
log.Printf("scraped playoffs import failed for %d: %v", season, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user