FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
tijs
tijslocation-feed-generator
This is the Anchor AppView - location based feed generator
Public
Like
1
location-feed-generator
Home
Code
21
.claude
1
.github
1
backend
10
coverage
database
2
docs
2
frontend
5
scripts
17
shared
static
tests
4
.gitignore
.vtignore
ATProto-OAuth-Guide.md
CLAUDE.md
DATABASE_AUDIT.md
README.md
deno.json
deno.test.json
H
main.tsx
opinionated-val-town.md
Branches
1
Pull requests
Remixes
History
Environment variables
7
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
DATABASE_AUDIT.md
Code
/
DATABASE_AUDIT.md
Search
8/11/2025
Viewing readonly version of main branch: v615
View latest version
DATABASE_AUDIT.md

Database Schema Audit Report

Overview

This document audits every database table and field against actual code usage to identify what's truly needed vs unused/legacy code.

Tables Found in Codebase

Core Tables (from schema.ts)

  1. checkins - Main check-in records
  2. address_cache - Cached address data
  3. profile_cache - User profile data
  4. user_follows - Following relationships
  5. anchor_users - User tracking for crawling
  6. processing_log - Processing statistics
  7. oauth_sessions - Authentication sessions
  8. display_names - Display name tracking

Legacy/Version Tables

  1. checkins_v1 - Legacy version
  2. address_cache_v1 - Legacy version
  3. user_pdses - PDS tracking
  4. migrations - Migration tracking

Detailed Field Analysis

Table 1: checkins - Main check-in records

Status: āœ… ACTIVE - Core table used extensively by API

Fields Analysis:

  • id (TEXT, PRIMARY KEY) - āœ… USED - Required for record identification
  • uri (TEXT, UNIQUE) - āœ… USED - AT Protocol record URI, used in API responses
  • rkey (TEXT) - āœ… USED - Record key, used for queries
  • did (TEXT) - āœ… USED - Author DID, used for user filtering and queries
  • handle (TEXT) - āœ… USED - Author handle, displayed in API responses
  • display_name (TEXT) - āœ… USED - Author display name, used in API responses
  • avatar (TEXT) - āœ… USED - Author avatar URL, used in API responses
  • text (TEXT) - āœ… USED - Check-in message, core content
  • created_at (TEXT) - āœ… USED - Timestamp for sorting and cursors
  • latitude (REAL) - āœ… USED - Location coordinate, used for distance calculations
  • longitude (REAL) - āœ… USED - Location coordinate, used for distance calculations
  • venue_name (TEXT) - āœ… USED - UNIFIED FIELD - Venue name displayed in API
  • category (TEXT) - šŸ¤” STORED - Place category, not currently used in API responses
  • category_group (TEXT) - šŸ¤” STORED - Category group, not currently used in API responses
  • category_icon (TEXT) - šŸ¤” STORED - Category icon, not currently used in API responses
  • address_street (TEXT) - āœ… USED - Street address, used in API responses
  • address_locality (TEXT) - āœ… USED - City, used in API responses
  • address_region (TEXT) - āœ… USED - State/province, used in API responses
  • address_country (TEXT) - āœ… USED - Country, used in API responses
  • address_postal_code (TEXT) - āœ… USED - Postal code, used in API responses
  • indexed_at (TEXT) - āœ… USED - Metadata timestamp

Migration Impact: Migration 005 removed these unused fields:

  • address_ref_uri - āŒ REMOVED - StrongRef URI, not used in API
  • address_ref_cid - āŒ REMOVED - StrongRef CID, not used in API
  • address_full - āŒ REMOVED - JSON field causing parsing issues
  • address_resolved_at - āŒ REMOVED - Resolution timestamp, not used
  • place_name - āŒ REMOVED - Migrated to unified venue_name
  • cached_address_name - āŒ REMOVED - Migrated to unified venue_name

Table 2: address_cache - Cached address data

Status: ā“ UNCLEAR - Table exists but usage uncertain

Fields Analysis:

  • uri (TEXT, PRIMARY KEY) - ā“ UNKNOWN - Address record URI
  • cid (TEXT) - ā“ UNKNOWN - Content hash
  • name (TEXT) - ā“ UNKNOWN - Venue name
  • street (TEXT) - ā“ UNKNOWN - Street address
  • locality (TEXT) - ā“ UNKNOWN - City
  • region (TEXT) - ā“ UNKNOWN - State/province
  • country (TEXT) - ā“ UNKNOWN - Country
  • postal_code (TEXT) - ā“ UNKNOWN - Postal code
  • latitude (REAL) - ā“ UNKNOWN - Location coordinate
  • longitude (REAL) - ā“ UNKNOWN - Location coordinate
  • resolved_at (TEXT) - ā“ UNKNOWN - Resolution timestamp

Migration Impact: Migration 006 removed:

  • full_data - āŒ REMOVED - JSON field causing parsing issues
  • failed_at - āŒ REMOVED - Failure timestamp, not used

Table 3: profile_cache - User profile data

Status: āœ… ACTIVE - Used by ProfileResolver in API

Fields Analysis:

  • did (TEXT, PRIMARY KEY) - āœ… USED - User DID, key for profile lookups
  • handle (TEXT) - āœ… USED - User handle, displayed in API
  • display_name (TEXT) - āœ… USED - Display name, shown in API responses
  • avatar_url (TEXT) - āœ… USED - Avatar URL, used in API responses
  • description (TEXT) - šŸ¤” STORED - Profile description, not used in API responses
  • followers_count (INTEGER) - šŸ¤” STORED - Follower count, not used in API responses
  • following_count (INTEGER) - šŸ¤” STORED - Following count, not used in API responses
  • posts_count (INTEGER) - šŸ¤” STORED - Post count, not used in API responses
  • indexed_at (TEXT) - āœ… USED - Cache timestamp
  • updated_at (TEXT) - āœ… USED - Update timestamp

Table 4: user_follows - Following relationships

Status: āœ… ACTIVE - Used for following feed functionality

Fields Analysis:

  • follower_did (TEXT, PRIMARY KEY) - āœ… USED - Follower DID, used in following queries
  • following_did (TEXT, PRIMARY KEY) - āœ… USED - Following DID, used in following queries
  • created_at (TEXT) - šŸ¤” STORED - Relationship creation time, not used in API
  • synced_at (TEXT) - āœ… USED - Last sync timestamp

Table 5: anchor_users - User tracking for crawling

Status: ā“ UNCLEAR - Defined in schema but usage uncertain

Fields Analysis:

  • did (TEXT, PRIMARY KEY) - ā“ UNKNOWN - User DID
  • handle (TEXT) - ā“ UNKNOWN - User handle
  • pds (TEXT) - ā“ UNKNOWN - PDS URL
  • last_checkin_crawl (TEXT) - ā“ UNKNOWN - Last crawl timestamp
  • last_follower_crawl (TEXT) - ā“ UNKNOWN - Last follower crawl
  • added_at (TEXT) - ā“ UNKNOWN - Added timestamp
  • updated_at (TEXT) - ā“ UNKNOWN - Update timestamp

Table 6: processing_log - Processing statistics

Status: āœ… ACTIVE - Used in stats API endpoint

Fields Analysis:

  • id (INTEGER, PRIMARY KEY) - āœ… USED - Record ID
  • run_at (TEXT) - āœ… USED - Processing run timestamp
  • events_processed (INTEGER) - āœ… USED - Event count
  • errors (INTEGER) - āœ… USED - Error count
  • duration_ms (INTEGER) - āœ… USED - Processing duration

Table 7: oauth_sessions - Authentication sessions

Status: ā“ UNCLEAR - Table exists but usage uncertain in current API

Fields Analysis:

  • did (TEXT, PRIMARY KEY) - ā“ UNKNOWN - User DID
  • handle (TEXT) - ā“ UNKNOWN - User handle
  • pds_url (TEXT) - ā“ UNKNOWN - PDS URL
  • access_token (TEXT) - ā“ UNKNOWN - OAuth access token
  • refresh_token (TEXT) - ā“ UNKNOWN - OAuth refresh token
  • dpop_private_key (TEXT) - ā“ UNKNOWN - DPoP private key
  • dpop_public_key (TEXT) - ā“ UNKNOWN - DPoP public key
  • session_id (TEXT) - ā“ UNKNOWN - Session cookie ID
  • created_at (INTEGER) - ā“ UNKNOWN - Creation timestamp
  • updated_at (INTEGER) - ā“ UNKNOWN - Update timestamp

Table 8: display_names - Display name tracking

Status: ā“ UNCLEAR - Table exists but usage uncertain

Fields Analysis:

  • did (TEXT, PRIMARY KEY) - ā“ UNKNOWN - User DID
  • display_name (TEXT) - ā“ UNKNOWN - Display name
  • updated_at (TEXT) - ā“ UNKNOWN - Update timestamp

Legacy Tables (Should be removed)

  • checkins_v1 - āŒ LEGACY - Old version, still referenced in legacy code but main API uses checkins
  • address_cache_v1 - āŒ LEGACY - Old version, still used by address resolver but should migrate

Active System Tables (Keep)

  • user_pdses - āœ… ACTIVE - CRITICAL PDS CRAWLER TABLE - Tracks PDS reference counting and crawling coordination

Summary of Findings

Currently Used Fields (API Active)

  • checkins: 16/21 fields actively used
  • profile_cache: 6/10 fields actively used
  • user_follows: 3/4 fields actively used
  • processing_log: All 5 fields used

Questionable Fields (Stored but unused)

  • checkins: category, category_group, category_icon (not in API responses)
  • profile_cache: description, followers_count, following_count, posts_count
  • user_follows: created_at

Unclear Tables (Need investigation)

  • address_cache: Entire table usage unclear
  • anchor_users: Entire table usage unclear
  • oauth_sessions: Entire table usage unclear
  • display_names: Entire table usage unclear

Legacy Tables to Remove

  • checkins_v1
  • address_cache_v1

Active System Tables (KEEP - Not Legacy)

  • user_pdses - āœ… CRITICAL PDS crawler infrastructure

āš ļø CRITICAL FINDINGS FROM REVERSE CODE AUDIT

MAJOR FIELD NAME INCONSISTENCIES DISCOVERED - This likely explains the venue name issues!

Field Name Mismatches Found:

  1. Address fields in checkins table:

    • API code (anchor-api.ts) uses: addressStreet, addressLocality, addressRegion, etc.
    • Backend code (queries.ts) uses: cached_address_street, cached_address_locality, etc.
    • Schema defines: address_street, address_locality, etc.
  2. Author fields:

    • API code uses: did, handle
    • Legacy code uses: author_did, author_handle

ACTUAL Tables Found in Backend Code:

āœ… CONFIRMED ACTIVE:

  • checkins (new API format)
  • checkins_v1 (legacy - universal-storage.ts, address-resolver.ts)
  • profile_cache (storage-provider.ts, queries.ts)
  • address_cache_v1 (universal-storage.ts, address-resolver.ts)
  • user_follows (followers-processor.ts, API)
  • anchor_users (user-tracking.ts, followers-processor.ts)
  • user_pdses (user-tracking.ts - PDS crawler)
  • oauth_sessions (oauth/session.ts, oauth/dpop.ts, oauth/endpoints.ts)
  • processing_log (API stats)

āŒ NOT FOUND IN ACTIVE CODE:

  • address_cache (only in schema/migrations)
  • display_names (only in schema/migrations)

āœ… ACTIONS COMPLETED:

  1. āœ… Fixed field name inconsistencies - All code now uses consistent venueName field
  2. āœ… Unified API queries - All endpoints use same Drizzle queries with consistent field names
  3. āœ… Removed duplicate endpoints - Eliminated /api/feed, consolidated to /api/global
  4. āœ… Cleaned up unused functions - Removed getRecentCheckins() after endpoint consolidation
  5. āœ… Fixed TypeScript errors - Resolved Drizzle query builder issues preventing deployment
  6. āœ… Verified venue name resolution - Field name inconsistencies that caused venue name issues are resolved

Current Status (Updated August 11, 2025):

  • Database Schema: Fully migrated to Drizzle with type safety
  • Field Names: All unified (venueName, addressStreet, etc.)
  • API Endpoints: Single set serves both web and mobile clients
  • Query Consistency: All feeds use same Drizzle queries and field names
  • Deployment: Successfully deployed and tested at dropanchor.app

āœ… ADDITIONAL ACTIONS COMPLETED:

  1. āœ… Removed unused tables - Successfully dropped address_cache and display_names tables
    • Migration 007_remove_unused_tables executed successfully
    • Verified removal via admin endpoint /api/admin/check-unused-tables

Remaining Recommendations

  1. Migrate legacy tables - Update remaining code to use current schemas instead of v1 tables
    • checkins_v1: Still used by universal-storage.ts and address-resolver.ts
    • address_cache_v1: Still used by address resolver system
  2. Continue migration system - Current Drizzle migration approach is working well

Architecture Status: āœ… STABLE

All critical field name inconsistencies have been resolved. The venue name issues that prompted this audit are now fixed.

Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
Ā© 2025 Val Town, Inc.