Initial commit including .env

This commit is contained in:
2026-06-22 17:43:40 +05:30
commit c577d47b75
286 changed files with 85878 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq"
)
func main() {
dsn := "host=31.97.228.132 user=admin password=Package@321# dbname=logistics port=5433 sslmode=disable"
db, err := sql.Open("postgres", dsn)
if err != nil {
log.Fatalf("Open failed: %v", err)
}
defer db.Close()
if err := db.Ping(); err != nil {
log.Fatalf("Ping failed: %v", err)
}
fmt.Println("Connected OK")
// Drop the old constraint
_, err = db.Exec(`ALTER TABLE pickupbookings DROP CONSTRAINT IF EXISTS pickupbookings_status_check`)
if err != nil {
log.Fatalf("Drop constraint failed: %v", err)
}
fmt.Println("Old constraint dropped.")
// Recreate with all status values from constants
_, err = db.Exec(`
ALTER TABLE pickupbookings ADD CONSTRAINT pickupbookings_status_check
CHECK (status IN (
'Pending_Pickup',
'Created',
'Miler_Assigned',
'Pickup_Scheduled',
'Picked_Up',
'Converted_To_Consignment',
'Cancelled'
))
`)
if err != nil {
log.Fatalf("Add constraint failed: %v", err)
}
fmt.Println("New constraint added with Pending_Pickup included.")
// Verify
var def string
db.QueryRow(`
SELECT pg_get_constraintdef(con.oid)
FROM pg_constraint con
JOIN pg_class rel ON rel.oid = con.conrelid
WHERE rel.relname = 'pickupbookings' AND con.contype = 'c'
`).Scan(&def)
fmt.Println("Current constraint:", def)
}