Skip to content

Commit

Permalink
Update MySQL TimeZone
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmmdriz committed Jun 25, 2024
1 parent 2e0ea2f commit 64ae6bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ WORKDIR /app

COPY . .

RUN apk add --no-cache tzdata

RUN go mod download

RUN go build -o /goapp
Expand All @@ -12,6 +14,7 @@ FROM alpine:3.19 AS build-release-stage

WORKDIR /

COPY --from=build-stage /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build-stage /goapp /goapp
COPY --from=build-stage /app/templates ./templates

Expand Down
10 changes: 9 additions & 1 deletion drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"e-complaint-api/drivers/mysql/seeder"
"e-complaint-api/entities"
"fmt"
"time"

"gorm.io/driver/mysql"
"gorm.io/gorm"
Expand All @@ -19,12 +20,19 @@ type Config struct {
}

func ConnectDB(config Config) *gorm.DB {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
loc, err := time.LoadLocation("Asia/Jakarta")
if err != nil {
panic(err)
}

// Creating the DSN with loc parameter
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=%s",
config.DB_USERNAME,
config.DB_PASSWORD,
config.DB_HOST,
config.DB_PORT,
config.DB_NAME,
loc.String(),
)
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion entities/complaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Complaint struct {
ID string `gorm:"primaryKey;type:varchar;size:15;"`
ID string `gorm:"primaryKey;type:varchar(15)"`
UserID int `gorm:"not null"`
CategoryID int `gorm:"not null"`
RegencyID string `gorm:"not null;type:varchar;size:4;"`
Expand Down

0 comments on commit 64ae6bd

Please sign in to comment.