mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'development' of https://gitlab.com/mbugroup/lti-api into dev/teguh
This commit is contained in:
@@ -2,6 +2,7 @@ package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/config"
|
||||
@@ -13,10 +14,25 @@ import (
|
||||
)
|
||||
|
||||
func Connect(dbHost, dbName string) *gorm.DB {
|
||||
dsn := fmt.Sprintf(
|
||||
"host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
|
||||
dbHost, config.DBUser, config.DBPassword, dbName, config.DBPort,
|
||||
)
|
||||
parts := []string{
|
||||
fmt.Sprintf("host=%s", dbHost),
|
||||
fmt.Sprintf("user=%s", config.DBUser),
|
||||
fmt.Sprintf("password=%s", config.DBPassword),
|
||||
fmt.Sprintf("dbname=%s", dbName),
|
||||
fmt.Sprintf("port=%d", config.DBPort),
|
||||
fmt.Sprintf("sslmode=%s", config.DBSSLMode),
|
||||
"TimeZone=Asia/Shanghai",
|
||||
}
|
||||
if config.DBSSLRootCert != "" {
|
||||
parts = append(parts, fmt.Sprintf("sslrootcert=%s", config.DBSSLRootCert))
|
||||
}
|
||||
if config.DBSSLCert != "" {
|
||||
parts = append(parts, fmt.Sprintf("sslcert=%s", config.DBSSLCert))
|
||||
}
|
||||
if config.DBSSLKey != "" {
|
||||
parts = append(parts, fmt.Sprintf("sslkey=%s", config.DBSSLKey))
|
||||
}
|
||||
dsn := strings.Join(parts, " ")
|
||||
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
|
||||
@@ -9,13 +9,9 @@ CREATE TABLE users (
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX users_id_user_unique ON users (id_user)
|
||||
WHERE
|
||||
deleted_at IS NULL;
|
||||
CREATE UNIQUE INDEX users_id_user_unique ON users (id_user) WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE UNIQUE INDEX users_email_unique ON users (email)
|
||||
WHERE
|
||||
deleted_at IS NULL;
|
||||
CREATE UNIQUE INDEX users_email_unique ON users (email) WHERE deleted_at IS NULL;
|
||||
|
||||
-- FLAGS
|
||||
CREATE TABLE flags (
|
||||
@@ -334,4 +330,4 @@ CREATE INDEX stock_logs_created_by_idx ON stock_logs (created_by);
|
||||
|
||||
CREATE INDEX stock_logs_created_at_idx ON stock_logs (created_at);
|
||||
|
||||
CREATE INDEX stock_logs_deleted_at_idx ON stock_logs (deleted_at);
|
||||
CREATE INDEX stock_logs_deleted_at_idx ON stock_logs (deleted_at);
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE users
|
||||
DROP CONSTRAINT IF EXISTS users_id_user_key;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE users
|
||||
ADD CONSTRAINT users_id_user_key UNIQUE (id_user);
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE kandangs
|
||||
DROP COLUMN IF EXISTS capacity;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE kandangs
|
||||
ADD COLUMN capacity NUMERIC(15,3) NOT NULL;
|
||||
@@ -235,13 +235,14 @@ func seedKandangs(tx *gorm.DB, createdBy uint, locations map[string]uint, users
|
||||
seeds := []struct {
|
||||
Name string
|
||||
Status utils.KandangStatus
|
||||
Capacity float64
|
||||
Location string
|
||||
PicKey string
|
||||
}{
|
||||
{Name: "Singaparna 1", Status: utils.KandangStatusNonActive, Location: "Singaparna", PicKey: "admin"},
|
||||
{Name: "Singaparna 2", Status: utils.KandangStatusNonActive, Location: "Singaparna", PicKey: "admin"},
|
||||
{Name: "Cikaum 1", Status: utils.KandangStatusNonActive, Location: "Cikaum", PicKey: "admin"},
|
||||
{Name: "Cikaum 2", Status: utils.KandangStatusNonActive, Location: "Cikaum", PicKey: "admin"},
|
||||
{Name: "Singaparna 1", Status: utils.KandangStatusNonActive, Capacity: 50000, Location: "Singaparna", PicKey: "admin"},
|
||||
{Name: "Singaparna 2", Status: utils.KandangStatusNonActive, Capacity: 50000, Location: "Singaparna", PicKey: "admin"},
|
||||
{Name: "Cikaum 1", Status: utils.KandangStatusNonActive, Capacity: 50000, Location: "Cikaum", PicKey: "admin"},
|
||||
{Name: "Cikaum 2", Status: utils.KandangStatusNonActive, Capacity: 50000, Location: "Cikaum", PicKey: "admin"},
|
||||
}
|
||||
|
||||
result := make(map[string]uint, len(seeds))
|
||||
|
||||
Reference in New Issue
Block a user