#
# $Id: mysql_schema,v 1.8 2005/10/31 22:35:18 jamiemccarthy Exp $
#

DROP TABLE IF EXISTS newsvac_keywords;
CREATE TABLE newsvac_keywords (
  id SMALLINT UNSIGNED NOT NULL auto_increment,
  regex char(255) DEFAULT '' NOT NULL,
  weight float(10,2),
  tag char(20),
  PRIMARY KEY (id),
  UNIQUE regex (regex)
);

DROP TABLE IF EXISTS robosubmitlock;
CREATE TABLE robosubmitlock (
  x char(1)
);

DROP TABLE IF EXISTS url_analysis;
CREATE TABLE url_analysis (
  url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  parse_code enum('html_linkextor','miner','plaintext','nugget'),
  is_success TINYINT(4),
  ts timestamp(14),
  duration float(10,2),
  miner_id INT(10) UNSIGNED,
  nuggets INT(10) UNSIGNED   
);

DROP TABLE IF EXISTS url_content;
CREATE TABLE url_content (
  url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  response_header TEXT,
  cookies TEXT,
  PRIMARY KEY (url_id)   
);

DROP TABLE IF EXISTS url_info;
CREATE TABLE url_info (
  url_id INT(10) UNSIGNED NOT NULL auto_increment,
  url_digest VARCHAR(32) NOT NULL,
  url TEXT NOT NULL,
  url_base TEXT,
  is_success TINYINT(4),
  last_attempt datetime,
  last_success datetime,
  believed_fresh_until datetime,
  status_code SMALLINT(6),
  reason_phrase VARCHAR(30),
  content_type VARCHAR(60),
  title VARCHAR(255),
  miner_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  PRIMARY KEY (url_id),
  UNIQUE url_digest (url_digest),
  KEY miner_id (miner_id)    
);

DROP TABLE IF EXISTS url_message_body;
CREATE TABLE url_message_body (
  url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  message_body LONGTEXT,
  PRIMARY KEY (url_id)
);

DROP TABLE IF EXISTS url_plaintext;
CREATE TABLE url_plaintext (
  url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  plaintext LONGTEXT,
  PRIMARY KEY (url_id)
);

DROP TABLE IF EXISTS rel;
CREATE TABLE rel (
  rel_id INT(10) UNSIGNED NOT NULL auto_increment,
  from_url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  to_url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  parse_code enum('html_linkextor','miner','nugget','plaintext') DEFAULT 'html_linkextor' NOT NULL,
  type char(20) DEFAULT '' NOT NULL,
  first_verified datetime,
  mark enum('valid','invalid') DEFAULT 'valid' NOT NULL,
  PRIMARY KEY (rel_id),
  UNIQUE from_to_parse_type_tag (from_url_id,to_url_id,parse_code,type),
  KEY type (type)    
);

DROP TABLE IF EXISTS nugget_sub;
CREATE TABLE nugget_sub (
  url_id INT(10) UNSIGNED DEFAULT '0' NOT NULL,
  submitworthy TINYINT(3) UNSIGNED,
  PRIMARY KEY (url_id)
);

DROP TABLE IF EXISTS miner;
CREATE TABLE miner (
  miner_id INT(10) UNSIGNED NOT NULL auto_increment,
  name VARCHAR(20) DEFAULT '' NOT NULL,
  last_edit timestamp(14),
  last_edit_aid VARCHAR(30),
  owner_aid VARCHAR(30),
  progress enum('broken','ok','great') DEFAULT 'broken' NOT NULL,
  pre_stories_text TEXT,
  post_stories_text TEXT,
  pre_stories_regex TEXT,
  post_stories_regex TEXT,
  pre_story_text TEXT,
  post_story_text TEXT,
  pre_story_regex TEXT,
  post_story_regex TEXT,
  extract_vars TEXT,
  extract_regex TEXT,
  tweak_code TEXT,
  comment TEXT,
  PRIMARY KEY (miner_id),
  UNIQUE name (name)    
);

DROP TABLE IF EXISTS spider;
CREATE TABLE spider (
  spider_id INT(10) UNSIGNED NOT NULL auto_increment,
  name VARCHAR(20) DEFAULT '' NOT NULL,
  last_edit timestamp(14),
  last_edit_aid VARCHAR(30),
  conditions TEXT,
  group_0_selects TEXT,
  commands TEXT,
  PRIMARY KEY (spider_id),
  UNIQUE name (name)     
);

DROP TABLE IF EXISTS spiderlock;
CREATE TABLE spiderlock (
  x char(1)
);


# Yes, I said "BIGINT"
DROP TABLE IF EXISTS spider_timespec;
CREATE TABLE spider_timespec (
  timespec_id INT(10) UNSIGNED NOT NULL auto_increment,
  name VARCHAR(20) NOT NULL,
  timespec VARCHAR(64) DEFAULT '' NOT NULL,
  results VARCHAR(30) DEFAULT '' NOT NULL,
  last_run BIGINT DEFAULT 0 NOT NULL,
  PRIMARY KEY (timespec_id),
  UNIQUE identity (name, timespec)
);
