feat(seeder): add phone, operating_hours, is_24_hours to companies table
- Updated SeedLean and SeedFull CREATE TABLE statements - Added new fields to INSERT statements - Updated generateTenants to include phone (random), operating_hours, is_24_hours - Fixes 404 on /api/v1/companies/me due to missing columns
This commit is contained in:
parent
8d4731268e
commit
15eb6d42e5
1 changed files with 26 additions and 17 deletions
|
|
@ -112,6 +112,9 @@ func SeedLean(dsn string) (string, error) {
|
||||||
longitude DOUBLE PRECISION NOT NULL DEFAULT 0,
|
longitude DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
city TEXT NOT NULL DEFAULT '',
|
city TEXT NOT NULL DEFAULT '',
|
||||||
state TEXT NOT NULL DEFAULT '',
|
state TEXT NOT NULL DEFAULT '',
|
||||||
|
phone TEXT NOT NULL DEFAULT '',
|
||||||
|
operating_hours TEXT NOT NULL DEFAULT '',
|
||||||
|
is_24_hours BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
created_at TIMESTAMPTZ NOT NULL,
|
created_at TIMESTAMPTZ NOT NULL,
|
||||||
updated_at TIMESTAMPTZ NOT NULL
|
updated_at TIMESTAMPTZ NOT NULL
|
||||||
)`)
|
)`)
|
||||||
|
|
@ -260,9 +263,9 @@ func SeedLean(dsn string) (string, error) {
|
||||||
// 1. Create Company
|
// 1. Create Company
|
||||||
companyID := uuid.Must(uuid.NewV7())
|
companyID := uuid.Must(uuid.NewV7())
|
||||||
_, err = db.ExecContext(ctx, `
|
_, err = db.ExecContext(ctx, `
|
||||||
INSERT INTO companies (id, cnpj, corporate_name, category, license_number, is_verified, latitude, longitude, city, state, created_at, updated_at)
|
INSERT INTO companies (id, cnpj, corporate_name, category, license_number, is_verified, latitude, longitude, city, state, phone, operating_hours, is_24_hours, created_at, updated_at)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)`,
|
||||||
companyID, ph.CNPJ, ph.Name, "farmacia", fmt.Sprintf("CRF-GO-%s", ph.Suffix), true, ph.Lat, ph.Lng, "Anápolis", "GO", now, now,
|
companyID, ph.CNPJ, ph.Name, "farmacia", fmt.Sprintf("CRF-GO-%s", ph.Suffix), true, ph.Lat, ph.Lng, "Anápolis", "GO", "(62) 99999-00"+ph.Suffix, "Seg-Sex: 08:00-18:00, Sáb: 08:00-12:00", false, now, now,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("create library %s: %v", ph.Name, err)
|
return "", fmt.Errorf("create library %s: %v", ph.Name, err)
|
||||||
|
|
@ -454,6 +457,9 @@ func SeedFull(dsn string) (string, error) {
|
||||||
longitude DOUBLE PRECISION NOT NULL DEFAULT 0,
|
longitude DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
city TEXT NOT NULL DEFAULT '',
|
city TEXT NOT NULL DEFAULT '',
|
||||||
state TEXT NOT NULL DEFAULT '',
|
state TEXT NOT NULL DEFAULT '',
|
||||||
|
phone TEXT NOT NULL DEFAULT '',
|
||||||
|
operating_hours TEXT NOT NULL DEFAULT '',
|
||||||
|
is_24_hours BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
created_at TIMESTAMPTZ NOT NULL,
|
created_at TIMESTAMPTZ NOT NULL,
|
||||||
updated_at TIMESTAMPTZ NOT NULL
|
updated_at TIMESTAMPTZ NOT NULL
|
||||||
)`)
|
)`)
|
||||||
|
|
@ -491,8 +497,8 @@ func SeedFull(dsn string) (string, error) {
|
||||||
// Insert tenants
|
// Insert tenants
|
||||||
for _, t := range tenants {
|
for _, t := range tenants {
|
||||||
_, err := db.NamedExecContext(ctx, `
|
_, err := db.NamedExecContext(ctx, `
|
||||||
INSERT INTO companies (id, cnpj, corporate_name, category, license_number, is_verified, latitude, longitude, city, state, created_at, updated_at)
|
INSERT INTO companies (id, cnpj, corporate_name, category, license_number, is_verified, latitude, longitude, city, state, phone, operating_hours, is_24_hours, created_at, updated_at)
|
||||||
VALUES (:id, :cnpj, :corporate_name, :category, :license_number, :is_verified, :latitude, :longitude, :city, :state, :created_at, :updated_at)
|
VALUES (:id, :cnpj, :corporate_name, :category, :license_number, :is_verified, :latitude, :longitude, :city, :state, :phone, :operating_hours, :is_24_hours, :created_at, :updated_at)
|
||||||
ON CONFLICT (cnpj) DO NOTHING`, t)
|
ON CONFLICT (cnpj) DO NOTHING`, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("insert tenant %s: %v", t["corporate_name"], err)
|
log.Printf("insert tenant %s: %v", t["corporate_name"], err)
|
||||||
|
|
@ -563,18 +569,21 @@ func generateTenants(rng *rand.Rand, count int) []map[string]interface{} {
|
||||||
lngOffset := (rng.Float64() - 0.5) * 0.09
|
lngOffset := (rng.Float64() - 0.5) * 0.09
|
||||||
|
|
||||||
tenants = append(tenants, map[string]interface{}{
|
tenants = append(tenants, map[string]interface{}{
|
||||||
"id": id,
|
"id": id,
|
||||||
"cnpj": cnpj,
|
"cnpj": cnpj,
|
||||||
"corporate_name": name,
|
"corporate_name": name,
|
||||||
"category": "farmacia",
|
"category": "farmacia",
|
||||||
"license_number": fmt.Sprintf("CRF-GO-%05d", rng.Intn(99999)),
|
"license_number": fmt.Sprintf("CRF-GO-%05d", rng.Intn(99999)),
|
||||||
"is_verified": rng.Float32() > 0.3, // 70% verified
|
"is_verified": rng.Float32() > 0.3, // 70% verified
|
||||||
"latitude": AnapolisLat + latOffset,
|
"latitude": AnapolisLat + latOffset,
|
||||||
"longitude": AnapolisLng + lngOffset,
|
"longitude": AnapolisLng + lngOffset,
|
||||||
"city": "Anápolis",
|
"city": "Anápolis",
|
||||||
"state": "GO",
|
"state": "GO",
|
||||||
"created_at": now,
|
"phone": fmt.Sprintf("(62) 9%04d-%04d", rng.Intn(9999), rng.Intn(9999)),
|
||||||
"updated_at": now,
|
"operating_hours": "Seg-Sex: 08:00-18:00",
|
||||||
|
"is_24_hours": rng.Float32() < 0.1, // 10% are 24h
|
||||||
|
"created_at": now,
|
||||||
|
"updated_at": now,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return tenants
|
return tenants
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue