Merge pull request #76 from rede5/codex/update-company_id-and-user_id-to-uuid-v7

Adopt UUIDv7 aliases and default user role 'PHARMACY'
This commit is contained in:
Tiago Yamamoto 2026-02-07 11:31:44 -03:00 committed by GitHub
commit bbab9cfbb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View file

@ -6,9 +6,13 @@ import (
"github.com/gofrs/uuid/v5"
)
// CompanyID and UserID are UUIDv7 identifiers for performance-friendly indexing.
type CompanyID = uuid.UUID
type UserID = uuid.UUID
// Tenant represents a B2B actor (pharmacy/distributor) in the marketplace.
type Tenant struct {
ID uuid.UUID `db:"id" json:"id"`
ID CompanyID `db:"id" json:"id"`
CNPJ string `db:"cnpj" json:"cnpj"`
CorporateName string `db:"corporate_name" json:"corporate_name"`
Category string `db:"category" json:"category"` // farmacia, distribuidora
@ -46,8 +50,8 @@ const (
// User represents an authenticated actor inside a company.
type User struct {
ID uuid.UUID `db:"id" json:"id"`
CompanyID uuid.UUID `db:"company_id" json:"company_id"`
ID UserID `db:"id" json:"id"`
CompanyID CompanyID `db:"company_id" json:"company_id"`
Role string `db:"role" json:"role"`
Name string `db:"name" json:"name"`
Username string `db:"username" json:"username"`
@ -67,7 +71,7 @@ type User struct {
// UserFilter captures listing constraints.
type UserFilter struct {
CompanyID *uuid.UUID
CompanyID *CompanyID
Limit int
Offset int
}
@ -498,7 +502,7 @@ type Review struct {
// CompanyRating exposes the aggregate score for a seller or pharmacy.
type CompanyRating struct {
CompanyID uuid.UUID `json:"company_id"`
CompanyID CompanyID `json:"company_id"`
AverageScore float64 `json:"average_score"`
TotalReviews int64 `json:"total_reviews"`
}
@ -530,7 +534,7 @@ type AdminDashboard struct {
// CompanyDocument represents a KYC/KYB document (CNPJ card, Permit).
type CompanyDocument struct {
ID uuid.UUID `db:"id" json:"id"`
CompanyID uuid.UUID `db:"company_id" json:"company_id"`
CompanyID CompanyID `db:"company_id" json:"company_id"`
Type string `db:"type" json:"type"` // CNPJ, PERMIT, IDENTITY
URL string `db:"url" json:"url"`
Status string `db:"status" json:"status"` // PENDING, APPROVED, REJECTED
@ -542,7 +546,7 @@ type CompanyDocument struct {
// LedgerEntry represents an immutable financial record.
type LedgerEntry struct {
ID uuid.UUID `db:"id" json:"id"`
CompanyID uuid.UUID `db:"company_id" json:"company_id"`
CompanyID CompanyID `db:"company_id" json:"company_id"`
AmountCents int64 `db:"amount_cents" json:"amount_cents"`
Type string `db:"type" json:"type"` // SALE, FEE, WITHDRAWAL, REFUND
Description string `db:"description" json:"description"`
@ -553,7 +557,7 @@ type LedgerEntry struct {
// Withdrawal represents a payout request.
type Withdrawal struct {
ID uuid.UUID `db:"id" json:"id"`
CompanyID uuid.UUID `db:"company_id" json:"company_id"`
CompanyID CompanyID `db:"company_id" json:"company_id"`
AmountCents int64 `db:"amount_cents" json:"amount_cents"`
Status string `db:"status" json:"status"` // PENDING, APPROVED, PAID, REJECTED
BankAccountInfo string `db:"bank_account_info" json:"bank_account_info"`

View file

@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS companies (
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY,
company_id UUID NOT NULL REFERENCES companies(id),
role TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'PHARMACY',
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,