X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=contrib%2Fupgrade0.6-localdb.sql;h=dbf7789bd67cf4db4e98a3f12a0423edcb05b4dd;hb=020917702127ad12881c8868bb649a685c561def;hp=0733ba13948c1d444df50676ac388b798d89bca8;hpb=dbc502263438b4ba798f74a372c2a79fdc3061f4;p=cumulus.git diff --git a/contrib/upgrade0.6-localdb.sql b/contrib/upgrade0.6-localdb.sql index 0733ba1..dbf7789 100644 --- a/contrib/upgrade0.6-localdb.sql +++ b/contrib/upgrade0.6-localdb.sql @@ -4,15 +4,16 @@ -- This script should be loaded after connecting to the database to be -- upgraded. --- Database schema changes: the size column was added to the segments table, --- and the segments_used table was added. Rather than upgrade the segments --- table in-place, we create a new table and then rename it over the old --- segments table. +-- Database schema changes: the size and mtime columns were added to the +-- segments table, and the segments_used table was added. Rather than upgrade +-- the segments table in-place, we create a new table and then rename it over +-- the old segments table. create table segments_new ( segmentid integer primary key, segment text unique not null, path text, checksum text, + mtime real, size integer ); @@ -25,11 +26,12 @@ create table segments_used ( -- Compute the size of each of the segments, if possible, based on our -- knowledge of the objects stored in them. insert into segments_new -select segmentid, segment, path, checksum, size +select segmentid, segment, path, checksum, mtime, size from (select segmentid, segment, path, checksum from segments) left join - (select segmentid, sum(size) as size from block_index group by segmentid) + (select segmentid, sum(size) as size, max(timestamp) as mtime + from block_index group by segmentid) using (segmentid); drop table segments; @@ -50,3 +52,15 @@ using (segmentid); -- The snapshot_contents table is obsolete. drop table snapshot_contents; + +-- Upgrade database views. +drop view cleaning_order; +drop view segment_info; + +create view segment_info as +select segmentid, mtime, size, cast(size * utilization as integer) as used, + utilization +from segments join + (select segmentid, max(utilization) as utilization + from segments_used group by segmentid) +using (segmentid);