Developer Scripts
The Visita codebase includes a suite of utility scripts located in the /scripts directory. These scripts are essential for maintaining database integrity, seeding data, and verifying features without manual UI testing.
Execution: Most scripts are TypeScript and should be run using npx tsx scripts/script-name.ts.
Bash scripts (.sh) should be run directly.
๐ Database Integrity & Checks
These scripts verify the structural integrity of the database, check for missing data, or validate schema compliance.
| Script | Purpose |
|---|
check-tables.js | Verifies the existence and basic record counts of core tables (Provinces, Municipalities, Wards). |
check-civic-tables.ts | Validates the structure and content of civic engagement tables. |
check-columns-vds.ts | Checks specific columns in Voting District tables. |
check-constraint.ts | Verifies database constraints are active and valid. |
check-links.ts | Validates foreign key relationships and link integrity. |
check-mapping.ts | Verifies logical mappings between different geographic entities. |
check-myward-schema.ts | specific validation for the MyWard feature schema. |
check-nulls.ts | Scans for unexpected NULL values in critical columns. |
check-policies.ts | Audits Row Level Security (RLS) policies. |
check-vd-link.ts | Checks links between Wards and Voting Districts. |
cross-check.ts | Performs multi-table cross-reference validation. |
final-check.ts | A pre-deployment or pre-migration final sanity check. |
validate-2026-ward-data.sh | Bash script to validate MDB spatial data for the 2026 ward release. |
codebase-audit.js | General audit tool for the codebase structure. |
Usage Example
# Check basic table health
node scripts/check-tables.js
# Audit RLS policies
npx tsx scripts/check-policies.ts
๐งช Feature Testing
Scripts designed to simulate user actions or test specific feature flows end-to-end.
| Script | Purpose |
|---|
test-voting-system.ts | Comprehensive E2E test of the tender voting logic (Residency logic, Vote counting, Price deviation). |
test-rag-pipeline.ts | Tests the RAG (Retrieval-Augmented Generation) pipeline for intelligence query accuracy. |
test-db-query.ts | Generic database query performance and correctness test. |
test-db-query-civic.ts | Specific queries for civic data structures. |
test-anon-access.ts | Verifies public/anonymous access permissions (RLS verification). |
test-weather-cron.js | Simulates the weather logic cron job. |
Usage Example
# Run the voting system test suite
npx tsx scripts/test-voting-system.ts
๐ฑ Migration & Seeding
Tools for populating the database with initial data or migrating between versions.
| Script | Purpose |
|---|
seed-community-feed.ts | Populates the community feed with dummy/staging data. |
seed-marketplace.ts | Seeds the seller dashboard and marketplace with products/sellers. |
seed-algolia.ts | Pushes database records to the Algolia search index. |
sync-algolia.ts | Synchronizes updates to Algolia. |
run-civic-migration.ts | Orchestrator for civic data migrations. |
import-legacy-users.ts | Migration script for legacy user data. |
ingest-docs.ts | Ingestion pipeline for documentation into the knowledge base. |
ingest-tenders.ts | Ingestion script for tender data. |
migrate-vd-data.ts | Specialized migration for Voting District data. |
๐ ๏ธ Maintenance & Repair
Utilities for fixing data anomalies or managing administrative tasks.
| Script | Purpose |
|---|
repair-wards-safe.ts | Safely attempts to repair corrupted ward data. |
repair-ward-data.js | Legacy repair script (JS). |
admin_reset.js | DANGER: Resets admin state or data (Check script before running). |
manage-moderators.ts | Tooling for adding/removing moderator privileges. |
organize-supabase-types.ts | Helper to reorganize generated Supabase type definitions. |
search-schemas.ts | Inspects database schemas for specific patterns. |
find-ward-by-code.ts | Utility to lookup ward details by unique code. |
find-user-row.ts | Locates specific user records for debugging. |
Best Practices
- Read Before Run: Always inspect the script source before running against production.
- Use
tsx: Prefer npx tsx for TypeScript files to avoid compilation steps.
- Environment Variables: Ensure local
.env files are configured, as most scripts utilize dotenv.
- Gold Standard: Use
test-voting-system.ts as a template for writing new feature tests.