X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=contrib%2Fupgrade0.6-localdb.sql;h=49fc1aabef7b08b706731ee0081023d8b6a54c3e;hb=f38dd9bcb0caffd3fc9126b05788c936690e8288;hp=dbf7789bd67cf4db4e98a3f12a0423edcb05b4dd;hpb=020917702127ad12881c8868bb649a685c561def;p=cumulus.git diff --git a/contrib/upgrade0.6-localdb.sql b/contrib/upgrade0.6-localdb.sql index dbf7789..49fc1aa 100644 --- a/contrib/upgrade0.6-localdb.sql +++ b/contrib/upgrade0.6-localdb.sql @@ -7,14 +7,16 @@ -- 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. +-- the old segments table. The intent column was also added to the snapshots +-- table. create table segments_new ( segmentid integer primary key, segment text unique not null, path text, checksum text, mtime real, - size integer + size integer, + expire_time integer ); create table segments_used ( @@ -22,11 +24,19 @@ create table segments_used ( segmentid integer not null, utilization real ); +create unique index segments_used_index + on segments_used(snapshotid, segmentid); + +alter table snapshots add column intent real; + +-- Initialize the intent column; set all old snapshots to have intent 1 +-- (intended to be a daily snapshot). +update snapshots set intent = 1; -- 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, mtime, size +select segmentid, segment, path, checksum, mtime, size, null as expire_time from (select segmentid, segment, path, checksum from segments) left join @@ -58,8 +68,8 @@ 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 +select segmentid, mtime, size, expire_time, + cast(size * utilization as integer) as used, utilization from segments join (select segmentid, max(utilization) as utilization from segments_used group by segmentid)