Skip to content

Commit

Permalink
Merge pull request #16 from titouanfreville/issue-6-APIimpl
Browse files Browse the repository at this point in the history
Seems correct with volumes ...
  • Loading branch information
titouanfreville authored Feb 26, 2017
2 parents d460798 + eba1c40 commit f6ad816
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
33 changes: 21 additions & 12 deletions datastores/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import (
"github.com/titouanfreville/popcubeapi/models"
u "github.com/titouanfreville/popcubeapi/utils"
// Importing sql driver. They are used by gorm package and used by default from blank.
"log"

_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
)

// Store interface the Stores and usefull DB functions
// StoreInterface interface the Stores and usefull DB functions
type StoreInterface interface {
Avatar() AvatarStore
Channel() ChannelStore
Expand Down Expand Up @@ -62,6 +64,11 @@ func (store StoreImpl) InitConnection(user string, dbname string, password strin
db.Callback().Update().Remove("gorm:update_time_stamp")
db.Callback().Update().Remove("gorm:save_associations")

if err := db.DB().Ping(); err != nil {
log.Print("Can't connect to database")
log.Print(host)
return nil
}
return db
}

Expand All @@ -86,7 +93,7 @@ func (store StoreImpl) roleInitSave(role models.Role, db *gorm.DB) *u.AppError {
// InitDatabase initialise a connection to the database and the database.
func (store StoreImpl) InitDatabase(user string, dbname string, password string, host string, port string) {
db := store.InitConnection(user, dbname, password, host, port)

db.Debug().DB().Ping()
// Create correct tables
// db.AutoMigrate(&models.Avatar{}, &models.Channel{}, &models.Emoji{}, &models.Folder{},
// models.Member{}, &models.Message{}, &models.Organisation{}, &models.Parameter{},
Expand All @@ -99,16 +106,18 @@ func (store StoreImpl) InitDatabase(user string, dbname string, password string,
// Will not update LastUpdate on .Save() call
db.Callback().Update().Remove("gorm:update_time_stamp")
db.Callback().Update().Remove("gorm:save_associations")
/*
if db.NewRecord(models.Owner) {
store.roleInitSave(models.Owner, db)
}
if db.NewRecord(&models.Admin) {
store.roleInitSave(models.Admin, db)
}
if db.NewRecord(&models.Standart) {
store.roleInitSave(models.Standart, db)
}*/

db.Debug().DB().Ping()

if db.NewRecord(models.Owner) {
store.roleInitSave(models.Owner, db)
}
if db.NewRecord(&models.Admin) {
store.roleInitSave(models.Admin, db)
}
if db.NewRecord(&models.Standart) {
store.roleInitSave(models.Standart, db)
}
}

// CloseConnection close database connection
Expand Down
9 changes: 8 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ services:
image: registry.le-corre.eu:5000/innerapi:slate-alpha-doc
volumes:
- "./swagger.json:/tmp/swagger"
# - "./docker_resources/slate_resources:/home/slate"
ports:
- 4567:4567
back:
build:
context: .
dockerfile: docker/gobase.Dockerfile
env_file: .env
volumes:
- "./api:/go/src/github.com/titouanfreville/popcubeapi/api"
- "./datastores:/go/src/github.com/titouanfreville/popcubeapi/datastores"
- "./models:/go/src/github.com/titouanfreville/popcubeapi/models"
- "./utils:/go/src/github.com/titouanfreville/popcubeapi/utils"
- "./main.go:/go/src/github.com/titouanfreville/popcubeapi/main.go"
image: registry.le-corre.eu:5000/go:base
ports:
- 3000:3000
Expand All @@ -30,6 +35,7 @@ services:
- "./datastores:/go/src/github.com/titouanfreville/popcubeapi/datastores"
- "./models:/go/src/github.com/titouanfreville/popcubeapi/models"
- "./utils:/go/src/github.com/titouanfreville/popcubeapi/utils"
- "./main.go:/go/src/github.com/titouanfreville/popcubeapi/main.go"
ports:
- 8082:8080
golint:
Expand All @@ -42,6 +48,7 @@ services:
- "./datastores:/go/src/github.com/titouanfreville/popcubeapi/datastores"
- "./models:/go/src/github.com/titouanfreville/popcubeapi/models"
- "./utils:/go/src/github.com/titouanfreville/popcubeapi/utils"
- "./main.go:/go/src/github.com/titouanfreville/popcubeapi/main.go"
database:
image: mariadb:10.1
env_file: .env
Expand Down

0 comments on commit f6ad816

Please sign in to comment.