Suppress error messages from Makefile when git-describe is not available.
[cumulus.git] / cleandb.sql
1 -- SQL commands for cleaning out the local database.  These commands should be
2 -- executed within a transaction, but this script does not do so
3 -- automatically--it is up to the caller to set up a transaction before
4 -- executing these commands.
5 --
6 -- Any snapshots which do not need to be tracked should be deleted from the
7 -- snapshots table prior to executing these commands.  This script will then
8 -- clean up all state with a snapshotid not found in the snapshots table.
9
10 -- Delete entries in the snapshot_contents table which are for non-existent
11 -- snapshots.
12 delete from snapshot_contents
13     where snapshotid not in (select snapshotid from snapshots);
14
15 -- Find segments which contain no objects used by any current snapshots, and
16 -- delete them from the segment table.
17 delete from segments where segmentid not in
18     (select distinct segmentid from snapshot_contents natural join block_index);
19
20 -- Finally, delete objects contained in non-existent segments.  We can't simply
21 -- delete unused objects, since we use the set of unused objects to determine
22 -- the used/free ratio of segments.
23 delete from block_index
24     where segmentid not in (select segmentid from segments);