geokrety schema¶
geokrety is the operational source of truth. The current stats branch did not move write ownership into stats; instead, it added source-side columns, functions, and triggers so analytics state is updated where the original business event occurs.
Table of contents¶
- Role
- Stats-critical objects
- Core tables
- Trigger ownership
- Read surfaces and helper objects
- Operational cautions
Role¶
Three source tables matter most to the current branch:
gk_moves: the event stream for movement, comments, seen logs, archives, and dipsgk_geokrety: GeoKret identity and owner stategk_users,gk_pictures,gk_loves: supporting event sources for user, content, and engagement counters
The live database shows gk_moves at roughly 6.9M estimated rows and 17 GB, making it the dominant source relation for analytics cost.
Stats-critical objects¶
gk_moves¶
The March 2026 chain added and now depends on:
previous_move_idprevious_position_idkm_distance
These columns support chain traversal, deterministic distance calculation, and snapshot backfills. They are maintained by:
fn_set_previous_move_id_and_distance()fn_refresh_previous_move_ids_after_insert()fn_refresh_previous_move_ids_after_update()fn_rewire_previous_move_ids_after_delete()
gk_geokrety¶
The key branch addition here is live first-finder reconciliation. The trigger:
tr_gk_geokrety_after_first_finder
fires fn_gk_geokrety_first_finder() on owner or creation-time changes and on delete.
Core tables¶
Movement and GeoKret domain¶
gk_geokrety: main GK identity, ownership, holder, counters, and lifecycle fieldsgk_moves: movement log and analytics event sourcegk_moves_comments: comment and missing-report domain attached to movesgk_pictures: picture uploads linked to GK, move, or usergk_loves: lightweight engagement tablegk_watched: watchlist subscriptionsvw_geokret_move_history: human-readable move-chain diagnostic view added on this branch
User and authentication domain¶
gk_usersgk_account_activationgk_email_activationgk_email_revalidategk_password_tokensgk_users_authentication_historygk_users_settingsandgk_users_settings_parametersgk_users_social_authgk_users_username_history
Content, messaging, and community domain¶
gk_news,gk_news_comments,gk_news_comments_accessgk_mailsgk_labelsgk_awards,gk_awards_group,gk_awards_won,gk_yearly_ranking
Waypoints and geospatial source domain¶
gk_waypoints_gcgk_waypoints_ocgk_waypoints_countrygk_waypoints_syncgk_waypoints_types
Operational and metadata tables¶
phinxlogschema_migrationsscriptssessionsgk_site_settingsandgk_site_settings_parametersgk_rate_limit_overrides
Trigger ownership¶
The current branch relies on these gk_moves triggers in particular:
tr_gk_moves_before_prev_movetr_gk_moves_after_prev_move_inserttr_gk_moves_after_prev_move_updatetr_gk_moves_after_prev_move_deletetr_gk_moves_after_daily_activitytr_gk_moves_after_sharded_counterstr_gk_moves_after_country_rollupstr_gk_moves_after_country_historytr_gk_moves_after_waypoint_visitstr_gk_moves_after_relationstr_gk_moves_after_milestonestr_gk_moves_after_first_finder
This matters operationally: if a bulk load disables trigger semantics or bypasses application writes, the analytics surfaces in stats will drift unless a targeted rebuild or snapshot is run afterward.
Read surfaces and helper objects¶
Useful live read helpers include:
vw_geokret_move_history: move chain inspection with human labelsgk_geokrety_with_details: denormalized current GK viewgk_geokrety_in_caches: materialized subset for cache-located GKsgk_statistics_country_trendsandgk_statistics_daily_counters: older statistics still present outside the canonicalstatsschema
Operational cautions¶
- Do not treat
distanceongk_movesas a replacement forkm_distance; the branch standardized deterministic numeric distance through the new lineage columns. - Trigger ordering matters. The source schema now owns a substantial part of analytics correctness.
- For bulk repair work, prefer session flags and dedicated repair functions over disabling triggers globally. If trigger semantics were bypassed and
statsdrifted, recover through the stats snapshot and backfill workflow. - When changing source function signatures, explicitly drop stale overloads. PostgreSQL will otherwise keep older wrappers alive.