Changeset 1303
- Timestamp:
- 01/16/07 16:50:25 (6 years ago)
- Location:
- ccsd/trunk/dbschema
- Files:
-
- 2 edited
-
ccs_billing.schema (modified) (2 diffs)
-
radius.schema (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ccsd/trunk/dbschema/ccs_billing.schema
r1203 r1303 66 66 67 67 -- Current state of the customer 68 -- This table is updated regularly to track how much traffic the customer has 69 -- used. Only completed sessions are added to the traffic used in this table. 68 70 CREATE TABLE customer_state ( 69 71 contact_id integer NOT NULL REFERENCES contact (contact_id) … … 85 87 ON DELETE RESTRICT 86 88 ); 89 90 -- The real current state of this customer 91 -- This takes into accunt the used_mb's recorded in the above state table, plus 92 -- the number of megabytes used in the currently active session 93 CREATE VIEW current_customer_state AS SELECT 94 cs.contact_id, cs.plan_start, cs.used_mb, 95 cs.used_mb+COALESCE(t.acctinputoctets+t.acctoutputoctets,0)/1024/1024 AS 96 current_mb, ras.acctsessionid FROM customer_state cs, contact c LEFT JOIN 97 radius_active_sessions ras ON c.username=ras.username LEFT JOIN 98 radius_latest_traffic t ON ras.acctsessionid=t.acctsessionid WHERE 99 cs.contact_id=c.contact_id; 87 100 88 101 -- Billing records for the customer -
ccsd/trunk/dbschema/radius.schema
r1261 r1303 162 162 CREATE INDEX radacct_stop_user_idx ON radius_session (acctStopTime, UserName); 163 163 164 -- Helper views to return only active or completed sessions 165 CREATE VIEW radius_active_sessions AS SELECT * FROM radius_session WHERE 166 acctstoptime IS NULL; 167 CREATE VIEW radius_completed_sessions AS SELECT * FROM radius_session WHERE 168 acctstoptime IS NOT NULL; 169 164 170 -- Create a table that RADIUS will store interim accounting updates into 165 171 -- This table is used to determine how much traffic the user has done … … 175 181 ); 176 182 CREATE INDEX radiustraffic_idx ON radius_traffic (AcctSessionId, UserName); 183 CREATE INDEX radiustraffic_session_idx ON radius_traffic (acctsessionid, 184 accttime); 185 CREATE INDEX radiustraffic_id_idx ON radius_traffic (acctsessionid); 186 187 -- Views to filter the radius_traffic updates down to the latest update for 188 -- each session 189 CREATE VIEW radius_latest_updates AS SELECT acctsessionid, 190 max(accttime) AS latest FROM radius_traffic GROUP BY acctsessionid; 191 CREATE VIEW radius_latest_traffic AS select t.acctsessionid, l.latest, 192 t.acctinputoctets, t.acctoutputoctets FROM radius_latest_updates l 193 LEFT JOIN radius_traffic t ON l.acctsessionid=t.acctsessionid AND 194 l.latest=t.accttime ORDER BY latest, acctinputoctets, acctoutputoctets; 177 195 178 196 -- Create a function that can be called to update the customer state table … … 183 201 rows integer; 184 202 BEGIN 185 UPDATE customer_state SET last_updated=NOW(), used_mb=COALESCE(( 186 SELECT (SUM(t1.acctinputoctets+t1.acctoutputoctets) - 187 SUM(COALESCE(t2.acctinputoctets+t2.acctoutputoctets,0))) /1024 /1024 188 FROM radius_traffic t1 LEFT JOIN radius_traffic t2 189 ON t1.acctsessionid = t2.acctsessionid AND t2.accttime=( 190 SELECT MAX(t4.accttime) FROM radius_traffic t4 191 WHERE t4.acctsessionid=t2.acctsessionid 192 AND t4.accttime<customer_state.plan_start), contact c 193 WHERE t1.accttime=( 194 SELECT MAX(t3.accttime) FROM radius_traffic t3 195 WHERE t3.acctsessionid=t1.acctsessionid 196 AND t3.accttime>customer_state.plan_start) 197 AND t1.username=c.username AND c.contact_id=customer_state.contact_id 198 GROUP BY t1.username),0); 203 -- Update usage for sessions that have completed 204 UPDATE customer_state SET last_updated=NOW(), used_mb=used_mb+COALESCE(( 205 SELECT SUM(s.acctinputoctets+s.acctoutputoctets)/1024/1024 as mb FROM 206 radius_completed_sessions s, contact c WHERE s.username=c.username 207 AND c.contact_id=customer_state.contact_id 208 AND s.acctstoptime>customer_state.last_updated), 0); 199 209 GET DIAGNOSTICS rows = ROW_COUNT; 200 210 RETURN rows;
Note: See TracChangeset
for help on using the changeset viewer.
