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:
Tiago Yamamoto 2025-12-23 16:52:06 -03:00
parent 8d4731268e
commit 15eb6d42e5

View file

@ -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)
@ -573,6 +579,9 @@ func generateTenants(rng *rand.Rand, count int) []map[string]interface{} {
"longitude": AnapolisLng + lngOffset, "longitude": AnapolisLng + lngOffset,
"city": "Anápolis", "city": "Anápolis",
"state": "GO", "state": "GO",
"phone": fmt.Sprintf("(62) 9%04d-%04d", rng.Intn(9999), rng.Intn(9999)),
"operating_hours": "Seg-Sex: 08:00-18:00",
"is_24_hours": rng.Float32() < 0.1, // 10% are 24h
"created_at": now, "created_at": now,
"updated_at": now, "updated_at": now,
}) })