feat: RRBEC Local Server - Go backend with Django sync
- Implement local-first architecture with SQLite - Add bidirectional sync with Django via ChangeLog - JWT authentication with auto-refresh token - REST API for products, orders, commands, payments - Stock management with automatic deduction
This commit is contained in:
40
rrbec_server/internal/database/database.go
Normal file
40
rrbec_server/internal/database/database.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"log"
|
||||
"rrbec_server/internal/models"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
|
||||
func InitDB(dataSourceName string) *gorm.DB {
|
||||
var err error
|
||||
DB, err = gorm.Open(sqlite.Open(dataSourceName), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to connect database: %v", err)
|
||||
}
|
||||
|
||||
// Auto Migration
|
||||
err = DB.AutoMigrate(
|
||||
&models.Mesa{},
|
||||
&models.Client{},
|
||||
&models.Category{},
|
||||
&models.Product{},
|
||||
&models.ProductComponent{},
|
||||
&models.Comanda{},
|
||||
&models.ProductComanda{},
|
||||
&models.Order{},
|
||||
&models.TypePay{},
|
||||
&models.Payment{},
|
||||
&models.User{},
|
||||
&models.SyncState{},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to migrate database: %v", err)
|
||||
}
|
||||
|
||||
return DB
|
||||
}
|
||||
Reference in New Issue
Block a user