﻿START TRANSACTION;

LOCK feed, feedhistory, feeditem, announcement;

CREATE TEMPORARY TABLE backup_feed AS SELECT * FROM feed;
CREATE TEMPORARY TABLE backup_feedhistory AS SELECT * FROM feedhistory;
CREATE TEMPORARY TABLE backup_feeditem AS SELECT * FROM feeditem;
CREATE TEMPORARY TABLE backup_announcement AS SELECT * FROM announcement;

-- Parse::SQL::Dia      version 0.27                              
-- Documentation        http://search.cpan.org/dist/Parse-Dia-SQL/
-- Environment          Perl 5.018004, /usr/bin/perl              
-- Architecture         i386-linux-thread-multi                   
-- Target Database      postgres                                  
-- Input file           database.dia                              
-- Generated at         Wed Jan 14 02:25:25 2015                  
-- Typemap for postgres not found in input file                   

-- get_constraints_drop 

-- get_permissions_drop 

-- get_view_drop

-- get_schema_drop
drop table announcement;
drop table feedhistory;
drop table feeditem;
drop table feed;

-- get_smallpackage_pre_sql 

-- get_schema_create
create table feed (
   id               serial PRIMARY KEY             ,
   slug             varchar(255) NOT NULL UNIQUE   ,
   uri              varchar(255) NOT NULL          ,
   auto_refresh     boolean NOT NULL               ,
   refresh_interval integer                        ,
   next_refresh     timestamp NOT NULL             ,
   expire           boolean NOT NULL               ,
   expire_date      timestamp                      ,
   password         varchar(255)                   ,
   creation_ip      inet NOT NULL                  ,
   creation_date    timestamp NOT NULL DEFAULT now()
)   ;
create table feeditem (
   feed      integer NOT NULL REFERENCES feed ON DELETE CASCADE ON UPDATE CASCADE ,
   timestamp timestamp NOT NULL DEFAULT now()                                          ,
   html      text NOT NULL                                                             ,
   diff      text                                                                      ,
             PRIMARY KEY (feed, timestamp)                                             
)   ;
create table announcement (
   id               serial PRIMARY KEY              ,
   title            varchar(255) NOT NULL           ,
   content          text NOT NULL                   ,
   abstract         text                            ,
   publication_date timestamp NOT NULL DEFAULT now(),
   show_until       timestamp                       ,
   is_important     boolean NOT NULL               
)   ;
create table feedhistory (
   feed             integer NOT NULL REFERENCES feed ON DELETE CASCADE ON UPDATE CASCADE ,
   timestamp        timestamp NOT NULL DEFAULT now()                                     ,
   ip               inet NOT NULL                                                        ,
   slug             varchar(255)                                                         ,
   uri              varchar(255)                                                         ,
   auto_refresh     boolean                                                              ,
   refresh_interval integer                                                              ,
   next_refresh     timestamp                                                            ,
   expire           boolean NOT NULL                                                     ,
   expire_date      timestamp                                                            ,
   password         varchar(255)                                                         ,
                    PRIMARY KEY (feed, timestamp)                                        
)   ;

-- get_view_create

-- get_permissions_create

-- get_inserts

-- get_smallpackage_post_sql

-- get_associations_create

LOCK feed, feedhistory, feeditem, announcement;

ALTER TABLE feed OWNER TO feedizer;
ALTER TABLE feeditem OWNER TO feedizer;
ALTER TABLE feedhistory OWNER TO feedizer;
ALTER TABLE announcement OWNER TO feedizer;


INSERT INTO feed SELECT * FROM backup_feed;
INSERT INTO feeditem SELECT * FROM backup_feeditem;
INSERT INTO feedhistory SELECT * FROM backup_feedhistory;
INSERT INTO announcement SELECT * FROM backup_announcement;

COMMIT;
