File size: 1,555 Bytes
2b18225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- organizations.sheet_url: each university's own published Google Sheet.
--
-- Until now the Sheet source was a single KNOWLEDGE_JSON_URL environment
-- variable — one Sheet, feeding one collection. That works for one university
-- and cannot work for several: a second university's rows would land in the
-- first university's collection and answer the wrong students.
--
-- Storing the URL here puts it beside the rest of that organization's tenant
-- configuration (name, email_domain, plan_tier), so the sync can walk the
-- organizations table and give each university its own Sheet feeding its own
-- collection.
--
-- The URL is the Apps Script "published JSON" endpoint for that university's
-- Sheet, not the Sheet's edit link — see sheet_integration/apps_script/Code.gs.
--
-- Run once against the live Aurora cluster (CloudShell + psql) before
-- deploying the code that reads it. Safe to re-run (IF NOT EXISTS).
ALTER TABLE organizations
    ADD COLUMN IF NOT EXISTS sheet_url text;

-- Nullable on purpose: an organization without a Sheet is a normal, supported
-- state. It simply has no Sheet-sourced content — its knowledge base can still
-- be filled by document upload. The sync skips organizations with no URL
-- rather than treating the absence as an error.

-- Partial index: the sync loop only ever asks for organizations that actually
-- have a Sheet, so the index only needs to cover those rows.
CREATE INDEX IF NOT EXISTS idx_organizations_sheet_url
    ON organizations (id)
    WHERE sheet_url IS NOT NULL AND is_active;