[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
24
backend/internal/server/database.go
Normal file
24
backend/internal/server/database.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tss-rocks-be/ent"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func InitDatabase(ctx context.Context, driver, dsn string) (*ent.Client, error) {
|
||||
client, err := ent.Open(driver, dsn)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed opening database connection")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Run the auto migration tool
|
||||
if err := client.Schema.Create(ctx); err != nil {
|
||||
log.Error().Err(err).Msg("failed creating schema resources")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue