Mhamdans17 commited on
Commit ·
ba6431a
1
Parent(s): 4d76e48
fix: remove temporary debug files that break build
Browse files- check.go +0 -16
- debug_db.go +0 -31
- fixdb.go +0 -52
- test_insert.go +0 -41
- test_raw.go +0 -24
check.go
DELETED
|
@@ -1,16 +0,0 @@
|
|
| 1 |
-
package main
|
| 2 |
-
import (
|
| 3 |
-
"fmt"
|
| 4 |
-
"gorm.io/driver/postgres"
|
| 5 |
-
"gorm.io/gorm"
|
| 6 |
-
)
|
| 7 |
-
func main() {
|
| 8 |
-
dsn := "postgresql://postgres.gmzonnwzocuhtjhywtdd:Imtoky0d3vjava@aws-1-ap-south-1.pooler.supabase.com:5432/postgres"
|
| 9 |
-
db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
| 10 |
-
var dataType string
|
| 11 |
-
db.Raw("SELECT data_type FROM information_schema.columns WHERE table_name = 'members' AND column_name = 'member_id';").Scan(&dataType)
|
| 12 |
-
fmt.Println("TYPE:", dataType)
|
| 13 |
-
var constraints []string
|
| 14 |
-
db.Raw("SELECT conname FROM pg_constraint c JOIN pg_namespace n ON n.oid = c.connamespace WHERE conrelid = 'members'::regclass;").Scan(&constraints)
|
| 15 |
-
fmt.Println("CONSTRAINTS:", constraints)
|
| 16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_db.go
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
package main
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
"log"
|
| 6 |
-
|
| 7 |
-
"gorm.io/driver/postgres"
|
| 8 |
-
"gorm.io/gorm"
|
| 9 |
-
)
|
| 10 |
-
|
| 11 |
-
func main() {
|
| 12 |
-
dsn := "postgresql://postgres.gmzonnwzocuhtjhywtdd:Imtoky0d3vjava@aws-1-ap-south-1.pooler.supabase.com:5432/postgres"
|
| 13 |
-
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
| 14 |
-
if err != nil {
|
| 15 |
-
log.Fatal("failed to connect database", err)
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
var results []map[string]interface{}
|
| 19 |
-
err = db.Raw("SELECT conname, pg_get_constraintdef(c.oid) FROM pg_constraint c JOIN pg_namespace n ON n.oid = c.connamespace WHERE conrelid = 'members'::regclass;").Scan(&results).Error
|
| 20 |
-
if err != nil {
|
| 21 |
-
log.Println("Err checking constraints:", err)
|
| 22 |
-
}
|
| 23 |
-
fmt.Printf("Constraints on members: %+v\n", results)
|
| 24 |
-
|
| 25 |
-
var indexes []map[string]interface{}
|
| 26 |
-
err = db.Raw("SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'members';").Scan(&indexes).Error
|
| 27 |
-
if err != nil {
|
| 28 |
-
log.Println("Err checking indexes:", err)
|
| 29 |
-
}
|
| 30 |
-
fmt.Printf("Indexes on members: %+v\n", indexes)
|
| 31 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fixdb.go
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
package main
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
"log"
|
| 6 |
-
"service-warungpos-go/models"
|
| 7 |
-
|
| 8 |
-
"gorm.io/driver/postgres"
|
| 9 |
-
"gorm.io/gorm"
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
func main() {
|
| 13 |
-
dsn := "postgresql://postgres.gmzonnwzocuhtjhywtdd:Imtoky0d3vjava@aws-1-ap-south-1.pooler.supabase.com:5432/postgres"
|
| 14 |
-
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
| 15 |
-
if err != nil {
|
| 16 |
-
log.Fatal("failed to connect database", err)
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
// 1. Drop bogus constraint
|
| 20 |
-
db.Exec("ALTER TABLE members DROP CONSTRAINT IF EXISTS fk_orders_member;")
|
| 21 |
-
|
| 22 |
-
// 2. Force member_id to varchar
|
| 23 |
-
db.Exec("ALTER TABLE members ALTER COLUMN member_id TYPE VARCHAR(50) USING member_id::VARCHAR(50);")
|
| 24 |
-
|
| 25 |
-
// 3. Run AutoMigrate just like the main app does
|
| 26 |
-
err = db.AutoMigrate(
|
| 27 |
-
&models.Company{},
|
| 28 |
-
&models.Branch{},
|
| 29 |
-
&models.User{},
|
| 30 |
-
&models.Category{},
|
| 31 |
-
&models.Product{},
|
| 32 |
-
&models.BranchProduct{},
|
| 33 |
-
&models.Member{},
|
| 34 |
-
&models.Order{},
|
| 35 |
-
&models.OrderItem{},
|
| 36 |
-
&models.OTP{},
|
| 37 |
-
&models.Setting{},
|
| 38 |
-
)
|
| 39 |
-
if err != nil {
|
| 40 |
-
log.Fatal("AutoMigrate failed: ", err)
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
// 4. Verify constraints
|
| 44 |
-
var results []map[string]interface{}
|
| 45 |
-
db.Raw("SELECT conname FROM pg_constraint c JOIN pg_namespace n ON n.oid = c.connamespace WHERE conrelid = 'members'::regclass;").Scan(&results)
|
| 46 |
-
fmt.Printf("Constraints on members AFTER AutoMigrate: %+v\n", results)
|
| 47 |
-
|
| 48 |
-
// 5. Verify column type
|
| 49 |
-
var dataType string
|
| 50 |
-
db.Raw("SELECT data_type FROM information_schema.columns WHERE table_name = 'members' AND column_name = 'member_id';").Scan(&dataType)
|
| 51 |
-
fmt.Printf("DataType of member_id AFTER AutoMigrate: %s\n", dataType)
|
| 52 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_insert.go
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
package main
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
"log"
|
| 6 |
-
|
| 7 |
-
"gorm.io/driver/postgres"
|
| 8 |
-
"gorm.io/gorm"
|
| 9 |
-
)
|
| 10 |
-
|
| 11 |
-
type Member struct {
|
| 12 |
-
CompanyID uint
|
| 13 |
-
MemberCode string `gorm:"column:member_id"`
|
| 14 |
-
Name string
|
| 15 |
-
Phone string
|
| 16 |
-
Points int
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
func main() {
|
| 20 |
-
dsn := "postgresql://postgres.gmzonnwzocuhtjhywtdd:Imtoky0d3vjava@aws-1-ap-south-1.pooler.supabase.com:5432/postgres"
|
| 21 |
-
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
| 22 |
-
if err != nil {
|
| 23 |
-
log.Fatal("failed to connect database", err)
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
// Try inserting BG123 manually
|
| 27 |
-
newMember := Member{
|
| 28 |
-
CompanyID: 6,
|
| 29 |
-
MemberCode: "BG123",
|
| 30 |
-
Name: "Test Joko",
|
| 31 |
-
Phone: "08123456",
|
| 32 |
-
Points: 0,
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
err = db.Table("members").Create(&newMember).Error
|
| 36 |
-
if err != nil {
|
| 37 |
-
log.Fatal("Insert failed: ", err)
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
fmt.Println("Insert success! ID:", newMember.CompanyID)
|
| 41 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_raw.go
DELETED
|
@@ -1,24 +0,0 @@
|
|
| 1 |
-
package main
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
"log"
|
| 6 |
-
|
| 7 |
-
"gorm.io/driver/postgres"
|
| 8 |
-
"gorm.io/gorm"
|
| 9 |
-
)
|
| 10 |
-
|
| 11 |
-
func main() {
|
| 12 |
-
dsn := "postgresql://postgres.gmzonnwzocuhtjhywtdd:Imtoky0d3vjava@aws-1-ap-south-1.pooler.supabase.com:5432/postgres"
|
| 13 |
-
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
| 14 |
-
if err != nil {
|
| 15 |
-
log.Fatal("failed to connect database", err)
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
err = db.Exec(`INSERT INTO "members" ("company_id","member_id","name","phone","points","created_at") VALUES (6,'BG123','Joko','08123456',0,'2026-06-10 05:23:01.49') RETURNING "id"`).Error
|
| 19 |
-
if err != nil {
|
| 20 |
-
log.Println("Insert failed:", err)
|
| 21 |
-
} else {
|
| 22 |
-
fmt.Println("Insert success!")
|
| 23 |
-
}
|
| 24 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|