Circ Chain Functions should take BIGINTs

Because INTEGER isn't suitable for circ IDs.

This only requires editing the input definitions.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Purge Circulations: Skip partially complete chains

Billings in earlier portions of the chain may leave them open. Thus, look
for any circulations in the chain with a null xact_finish.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Purge Circulations: Support last xact_finished use

Based on a new (off by default) global flag change between the xact_finish
on the last circ in the chain and the most recent one.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Purge Circulations: Better selection logic

This attempts two things:

1 - Keep the number of circs the library wants based on the most recent
    circulations, regardless of user prefs and such.

    This is accomplished by changing the circ fetching query to use a
    window function in a subquery so we can filter on it easily.

    This also allowed removal of the purge position counter.

2 - Allow removal of circs that are between kept circs if they meet all
    other removal criteria.

    This is accomplished by using CONTINUE instead of EXIT in the loop.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Purge Circulations: Remove extra delete loop

A trigger on action.circulation purges upwards through the circ chain. Thus
we don't need to do the loop ourselves.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Purge Circulations: Allow global age as forced min

This allows a library to keep all circs in the last Y interval, regardless
of user settings that may otherwise cause an earlier purging.

Another global flag that defaults to off controls this behavior.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Purge Circulations: Unwrapped Upgrade Script

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Fix rentention typo

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Return count purged

Because postgres dislikes functions that don't return.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Add srfsh script to call action.purge_circulations().

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Stamping upgrade script for purge circs fixes

Signed-off-by: Dan Wells <dbw2@calvin.edu>