Skip to content

Instantly share code, notes, and snippets.

@untainsYD
Created June 10, 2025 03:40
Show Gist options
  • Save untainsYD/5c07e0a03964e74d58d2ae7d6d2fdfa5 to your computer and use it in GitHub Desktop.
Save untainsYD/5c07e0a03964e74d58d2ae7d6d2fdfa5 to your computer and use it in GitHub Desktop.
Physical DB model representation
erDiagram
    USERS {
        bigint id PK "nextval('users_id_seq')"
        character_varying first_name
        character_varying last_name  
        character_varying email
        character_varying phone_number
        character_varying phone_number_country_code
        boolean phone_number_verified
        character_varying preferred_locale
        character_varying x_token_user
        character_varying stripe_customer_id
        boolean freezed "DEFAULT false"
        character_varying freeze_reason
        integer earned_amount "DEFAULT 0"
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
        boolean deleted "DEFAULT false"
    }
    
    VISITORS {
        bigint id PK "nextval('visitors_id_seq')"
        character_varying x_token_visitor
        character_varying contact_email
        timestamp_without_time_zone expires_at
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    CITIES {
        bigint id PK "nextval('cities_id_seq')"
        character_varying name
        character_varying country_code
        character_varying currency
        character_varying manager_name
        character_varying manager_email
        character_varying manager_phone_number
        boolean open
        character_varying manager_picture
        character_varying default_background_image
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    HOMIE_SERVICES {
        bigint id PK "nextval('homie_services_id_seq')"
        character_varying name
        text_array opening_days "DEFAULT '{}'"
        integer opening_hour
        integer closing_hour
        integer minimum_bookable_hour
        bigint city_id FK
        boolean open
        integer position
        character_varying icon_image
        character_varying header_background_image
        character_varying icon_hex_color
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    HOMIES {
        bigint id PK "nextval('homies_id_seq')"
        character_varying first_name
        character_varying last_name
        character_varying phone_number
        character_varying email
        bigint city_id FK
        integer homie_service_id FK
        character_varying gender
        character_varying profile_picture
        date birthdate
        boolean driving_licence
        text_array languages "DEFAULT '{}'"
        text_array commuting_ways "DEFAULT '{}'"
        boolean is_hidden "DEFAULT false"
        character_varying password
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    ADDRESSES {
        bigint id PK "nextval('addresses_id_seq')"
        character_varying name
        character_varying line1
        character_varying line2
        character_varying street_number
        character_varying house_number
        character_varying city
        character_varying zip_code
        character_varying state
        character_varying country
        character_varying country_code
        character_varying additional_information
        bigint user_id FK
        integer visitor_id FK
        boolean deleted "DEFAULT false"
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    ORDERS {
        bigint id PK "nextval('orders_id_seq')"
        bigint user_id FK
        bigint visitor_id FK
        bigint city_id FK
        timestamp_without_time_zone expires_at
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    SERVICES {
        bigint id PK "nextval('services_id_seq')"
        character_varying type
        character_varying frequency
        character_varying status
        character_varying frequent_mission_day
        integer frequent_mission_time
        timestamp_without_time_zone mission_date
        character_varying plan
        integer quantity
        bigint user_id FK
        bigint visitor_id FK
        bigint order_id FK
        bigint city_id FK
        integer homie_service_id FK
        bigint address_id FK
        character_varying user_comment
        integer fixed_price
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    MISSIONS {
        bigint id PK "nextval('missions_id_seq')"
        timestamp_without_time_zone meeting_date
        bigint service_id FK
        integer homie_service_id FK
        bigint homie_id FK
        integer original_price
        integer price
        bigint user_id FK
        character_varying status
        integer address_id FK
        character_varying plan
        integer quantity
        character_varying payment_method "DEFAULT 'card'"
        character_varying payment_recovery_uid
        integer payment_attempts_count "DEFAULT 0"
        timestamp_without_time_zone last_payment_attempt_at
        character_varying user_comment
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    PAYMENTS {
        bigint id PK "nextval('payments_id_seq')"
        bigint user_id FK
        bigint mission_id FK
        character_varying stripe_charge_id
        integer amount "DEFAULT 0"
        character_varying currency
        character_varying status
        character_varying stripe_receipt_url
        character_varying stripe_card_id
        character_varying invoice
        integer invoice_number
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    CARDS {
        bigint id PK "nextval('cards_id_seq')"
        character_varying last4
        character_varying brand
        integer exp_month
        integer exp_year
        character_varying fingerprint
        character_varying funding
        bigint user_id FK
        boolean default "DEFAULT false"
        character_varying stripe_id
        boolean deleted "DEFAULT false"
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    COUPONS {
        bigint id PK "nextval('coupons_id_seq')"
        character_varying name
        character_varying type
        timestamp_without_time_zone starts_at
        timestamp_without_time_zone expires_at
        integer discount
        integer amount
        integer sponsor_id FK
        boolean code_is_uniq "DEFAULT false"
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    COUPON_ENTRIES {
        bigint id PK "nextval('coupon_entries_id_seq')"
        bigint coupon_id FK
        bigint user_id FK
        character_varying code_name
        boolean consummed "DEFAULT false"
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }
    
    COUPON_LABELS {
        bigint id PK "nextval('coupon_labels_id_seq')"
        character_varying code
        bigint coupon_id FK
        timestamp_without_time_zone created_at "NOT NULL"
        timestamp_without_time_zone updated_at "NOT NULL"
    }

    %% Foreign Key Relationships
    CITIES ||--o{ HOMIE_SERVICES : city_id
    CITIES ||--o{ HOMIES : city_id
    CITIES ||--o{ ORDERS : city_id
    CITIES ||--o{ SERVICES : city_id
    
    HOMIE_SERVICES ||--o{ HOMIES : homie_service_id
    HOMIE_SERVICES ||--o{ SERVICES : homie_service_id
    HOMIE_SERVICES ||--o{ MISSIONS : homie_service_id
    
    USERS ||--o{ ADDRESSES : user_id
    USERS ||--o{ CARDS : user_id
    USERS ||--o{ ORDERS : user_id
    USERS ||--o{ SERVICES : user_id
    USERS ||--o{ MISSIONS : user_id
    USERS ||--o{ PAYMENTS : user_id
    USERS ||--o{ COUPON_ENTRIES : user_id
    USERS ||--o{ COUPONS : sponsor_id
    
    VISITORS ||--o{ ADDRESSES : visitor_id
    VISITORS ||--o{ ORDERS : visitor_id
    VISITORS ||--o{ SERVICES : visitor_id
    
    ORDERS ||--o{ SERVICES : order_id
    
    SERVICES ||--|| MISSIONS : service_id
    SERVICES }o--|| ADDRESSES : address_id
    
    MISSIONS ||--o{ PAYMENTS : mission_id
    MISSIONS }o--|| HOMIES : homie_id
    MISSIONS }o--|| ADDRESSES : address_id
    
    COUPONS ||--o{ COUPON_ENTRIES : coupon_id
    COUPONS ||--o{ COUPON_LABELS : coupon_id
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment