drop table if exists ttrss_counters_cache;
 drop table if exists ttrss_cat_counters_cache;
 drop table if exists ttrss_feeds;
+drop table if exists ttrss_archived_feeds;
 drop table if exists ttrss_feed_categories;
 drop table if exists ttrss_users;
 drop table if exists ttrss_themes;
        index(owner_uid),
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
 
+create table ttrss_archived_feeds (id integer not null primary key,
+       owner_uid integer not null,
+       title varchar(200) not null, 
+       feed_url text not null, 
+       site_url varchar(250) not null default '',
+       index(owner_uid),
+       foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
+
 create table ttrss_counters_cache (
        feed_id integer not null,
        owner_uid integer not null,
        index (feed_id),
        foreign key (feed_id) references ttrss_feeds(id) ON DELETE CASCADE,
        index (orig_feed_id),
-       foreign key (orig_feed_id) references ttrss_feeds(id) ON DELETE SET NULL,
+       foreign key (orig_feed_id) references ttrss_archived_feeds(id) ON DELETE SET NULL,
        index (owner_uid),
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
 
 
 drop table ttrss_scheduled_updates;
 drop table ttrss_counters_cache;
 drop table ttrss_cat_counters_cache;
+drop table ttrss_archived_feeds;
 drop table ttrss_feeds;
 drop table ttrss_feed_categories;
 drop table ttrss_users;
 insert into ttrss_feeds (owner_uid, title, feed_url) values 
        (1, 'Tiny Tiny RSS: Forum', 'http://tt-rss.spb.ru/forum/rss.php');
 
+create table ttrss_archived_feeds (id integer not null primary key,
+       owner_uid integer not null references ttrss_users(id) on delete cascade,
+       title varchar(200) not null, 
+       feed_url text not null, 
+       site_url varchar(250) not null default '');     
+
 create table ttrss_counters_cache (
        feed_id integer not null,
        owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
        int_id serial not null primary key,
        ref_id integer not null references ttrss_entries(id) ON DELETE CASCADE,
        feed_id int references ttrss_feeds(id) ON DELETE CASCADE, 
-       orig_feed_id int references ttrss_feeds(id) ON DELETE SET NULL, 
+       orig_feed_id integer references ttrss_archived_feeds(id) ON DELETE SET NULL, 
        owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
        marked boolean not null default false,
        published boolean not null default false,
 
 
 alter table ttrss_user_entries change feed_id feed_id integer null;
 
+create table ttrss_archived_feeds (id integer not null primary key,
+       owner_uid integer not null,
+       title varchar(200) not null, 
+       feed_url text not null, 
+       site_url varchar(250) not null default '',
+       index(owner_uid),
+       foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
+
 alter table ttrss_user_entries add column orig_feed_id integer;
 update ttrss_user_entries set orig_feed_id = NULL;
 
-alter table ttrss_user_entries add constraint FOREIGN KEY (orig_feed_id) REFERENCES ttrss_feeds(id) ON DELETE SET NULL;
+alter table ttrss_user_entries add constraint FOREIGN KEY (orig_feed_id) REFERENCES ttrss_archived_feeds(id) ON DELETE SET NULL;
 
 update ttrss_version set schema_version = 60;
 
 
 
 alter table ttrss_user_entries alter column feed_id drop not null;
 
+create table ttrss_archived_feeds (id integer not null primary key,
+       owner_uid integer not null references ttrss_users(id) on delete cascade,
+       title varchar(200) not null, 
+       feed_url text not null, 
+       site_url varchar(250) not null default '');     
+
 alter table ttrss_user_entries add column orig_feed_id integer;
 update ttrss_user_entries set orig_feed_id = NULL;
 
-alter table ttrss_user_entries add constraint "$4" FOREIGN KEY (orig_feed_id) REFERENCES ttrss_feeds(id) ON DELETE SET NULL;
+alter table ttrss_user_entries add constraint "$4" FOREIGN KEY (orig_feed_id) REFERENCES ttrss_archived_feeds(id) ON DELETE SET NULL;
 
 update ttrss_version set schema_version = 60;