DROP TABLE IF EXISTS news;
CREATE TABLE news (
  id int(6) NOT NULL auto_increment,
  topic_id int(3) NOT NULL,
  section_id int(3) NOT NULL,
  author_id int(6) NOT NULL,
  lang_id int(2) NOT NULL,
  user_id int(6) DEFAULT '0' NOT NULL,
  state int(1) DEFAULT '0' NOT NULL,
  main_page int(1) DEFAULT '0' NOT NULL,
  timestamp timestamp(14),
  title varchar(150) DEFAULT '' NOT NULL,
  departement tinytext,
  ip varchar(9) NOT NULL,
  KEY id (id,topic_id,section_id,author_id)
);

DROP TABLE IF EXISTS news_moderated;
CREATE TABLE news_moderated (
  news_id int(6) NOT NULL,
  user_id int(6) NOT NULL,
  state int(1) NOT NULL,
  timestamp timestamp(14),
  KEY id (news_id,user_id)
);

DROP TABLE IF EXISTS news_body;
CREATE TABLE news_body (
  id int(6) NOT NULL auto_increment,
  body blob NOT NULL,
  content_type varchar(16) DEFAULT 'text/plain' NOT NULL,
  KEY id (id)
);

DROP TABLE IF EXISTS news_author;
CREATE TABLE news_author (
  id int(6) NOT NULL auto_increment,
  name varchar(50),
  contact varchar(100),
  key id (id)
);

DROP TABLE IF EXISTS news_attachements;
CREATE TABLE news_attachements (
  id int(6) NOT NULL auto_increment,
  news_id int(6) NOT NULL,
  content_type varchar(128),
  size int(8),
  name varchar(128) DEFAULT '' NOT NULL,
  attachement mediumblob NOT NULL,
  KEY id (id,news_id)
);

DROP TABLE IF EXISTS news_urls;
CREATE TABLE news_urls (
  id int(6) NOT NULL auto_increment,
  news_id int(6) NOT NULL,
  lang_id int(2) NOT NULL,
  urls_id int(6) NOT NULL,
  name tinytext,
  KEY id (id,news_id,lang_id,urls_id)
);

DROP TABLE IF EXISTS urls;
CREATE TABLE urls (
  id int(6) NOT NULL auto_increment,
  url varchar(200) not null,
  KEY id (id,url),
  UNIQUE(url)
);

DROP TABLE IF EXISTS news_vote;
CREATE TABLE news_vote (
  news_id int(6) NOT NULL,
  user_id int(6) NOT NULL,
  vote int(1) NOT NULL,
  KEY id (news_id,user_id)
);

DROP TABLE IF EXISTS users;
CREATE TABLE users (
  id int(6) NOT NULL auto_increment,
  lname varchar(40),
  fname varchar(40),
  login varchar(20) NOT NULL,
  passwd varchar(40) NOT NULL,
  email varchar(128) NOT NULL,
  fake_email varchar(128),
  homesite varchar(255),
  level int(20) unsigned DEFAULT '0',
  param int(10) unsigned DEFAULT '0',
  created timestamp(14),
  sig_id int(6) DEFAULT '1' NOT NULL,
  theme int(2) DEFAULT '0',
  status int(1) unsigned DEFAULT '0',
  score int(1) DEFAULT '1',
  PRIMARY KEY (id),
  UNIQUE id (id),
  KEY id2 (id),
  UNIQUE login (login),
  KEY login2 (login),
  UNIQUE email (email)
);

DROP TABLE IF EXISTS users_supp;
CREATE TABLE users_supp (
  user_id int(6) NOT NULL,
  supp_info blob,
  KEY id (user_id)
);

DROP TABLE IF EXISTS sessions;
CREATE TABLE sessions (
  id varchar(20) NOT NULL,
  user_id int(6) NOT NULL,
  ip varchar(9) NOT NULL,
  lastseen timestamp(14),
  expire timestamp(14),
  PRIMARY KEY (id),
  UNIQUE id (id),
  KEY id2 (id),
  KEY user_id2 (user_id)
);

DROP TABLE IF EXISTS topics;
CREATE TABLE topics (
  id int(3) NOT NULL auto_increment,
  topic varchar(50),
  longname varchar(50),
  state int(1) default '1' NOT NULL,
  key id (id)
);

DROP TABLE IF EXISTS sections;
CREATE TABLE sections (
  id int(3) NOT NULL auto_increment,
  section varchar(50),
  state int(1) DEFAULT '1' NOT NULL,
  key id (id)
);

DROP TABLE IF EXISTS lang;
CREATE TABLE lang (
  id int(2) NOT NULL auto_increment,
  lang char(2),
  description varchar(30),
  key id (id)
);

DROP TABLE IF EXISTS nospider;
CREATE TABLE nospider (
  host varchar(128) NOT NULL,
  timestamp timestamp(14) NOT NULL,
  KEY host (host)
);

DROP TABLE IF EXISTS urls_hits;
CREATE TABLE urls_hits (
  news_urls_id int(6) NOT NULL,
  hits int(6) DEFAULT '0' NOT NULL,
  PRIMARY KEY (news_urls_id),
  UNIQUE news_urls_id (news_urls_id),
  KEY id (news_urls_id,hits)
);

DROP TABLE IF EXISTS redirect;
CREATE TABLE redirect (
  urls_id int(6) NOT NULL,
  hits int(6) DEFAULT '0' NOT NULL,
  PRIMARY KEY (urls_id),
  UNIQUE urls_id (urls_id),
  KEY id (urls_id,hits)
);

DROP TABLE IF EXISTS board;
CREATE TABLE board (
  id int(6) NOT NULL auto_increment,
  message varchar(255) NOT NULL,
  timestamp timestamp(14),
  ip varchar(9) NOT NULL,
  info varchar(60) DEFAULT '0' NOT NULL,
  section int(2) DEFAULT '1' NOT NULL,
  KEY id (id,timestamp)
);

DROP TABLE IF EXISTS comments;
CREATE TABLE comments (
  id int(11) DEFAULT '0' NOT NULL auto_increment,
  subject varchar(80) DEFAULT '' NOT NULL,
  body blob NOT NULL,
  timestamp timestamp(14),
  news_id int(6) NOT NULL,
  # obj_id varchar(20) DEFAULT '' NOT NULL,
  # obj_type varchar(2) DEFAULT '0' NOT NULL,
  user_id int(6) DEFAULT '1' NOT NULL,
  com_parent int(11) DEFAULT '0' NOT NULL,
  ip varchar(9) DEFAULT '0' NOT NULL,
  # score tinyint(1) DEFAULT '-1' NOT NULL,
  sig_id int(6) DEFAULT '1' NOT NULL,
  PRIMARY KEY (id),
  KEY id (id),
  KEY news_id (news_id),
  KEY user_id (user_id),
  KEY com_parent (com_parent)
);

DROP TABLE IF EXISTS comments_scored;
CREATE TABLE comments_scored (
  comments_id int(11) DEFAULT '0' NOT NULL,
  user_id int(6) DEFAULT '0' NOT NULL,
  score int(1) DEFAULT '-1' NOT NULL,
  timestamp timestamp(14),
  info varchar(30) DEFAULT '',
  KEY id (comments_id,user_id)
);

DROP TABLE IF EXISTS sig;
CREATE TABLE sig (
  id int(6) DEFAULT '0' NOT NULL auto_increment,
  sig varchar(250) NOT NULL,
  PRIMARY KEY (id)
);

DROP TABLE IF EXISTS poll_questions;
CREATE TABLE poll_questions (
  id int(6) NOT NULL auto_increment, 
  question varchar(255) NOT NULL, 
  comment varchar(255),
  date int(10) NOT NULL,
  accept int(2) DEFAULT '0' NOT NULL,
  KEY id(id)
);

DROP TABLE IF EXISTS poll_answers;
CREATE TABLE poll_answers (
  question_id int(6) NOT NULL,
  answer varchar(255) NOT NULL,
  number int(10) DEFAULT '0' NOT NULL,
  question_number int(3) NOT NULL,
  KEY question_id(question_id)
);

DROP TABLE IF EXISTS poll_ip;
CREATE TABLE poll_ip(
  ip varchar(15) NOT NULL,
  date int(10) NOT NULL,
  KEY ip(ip) 
);

DROP TABLE IF EXISTS themes;
CREATE TABLE themes (
  id int(2) NOT NULL auto_increment,
  name varchar(50) NOT NULL,
  html text NOT NULL,
  typ varchar(50) NOT NULL,
  KEY id (id)
);

DROP TABLE IF EXISTS messages;
CREATE TABLE messages (
  id int(7) auto_increment NOT NULL,
  timestamp timestamp(14),
  user_id_source int(6) DEFAULT '0' NOT NULL,
  user_id_dest   int(6) DEFAULT '0' NOT NULL,
  read_ok enum('0','1') DEFAULT '0' NOT NULL,
  subject varchar(150) DEFAULT '0' NOT NULL,
  body blob NOT NULL,
  KEY id (id,user_id_dest,user_id_source,timestamp)
);

DROP TABLE IF EXISTS ip_sessions;
CREATE TABLE ip_sessions (
  id int(20) NOT NULL,
  ip varchar(9) NOT NULL,
  created timestamp(14),
  PRIMARY KEY (id),
  KEY ip (ip)
);

DROP TABLE IF EXISTS webcam;
CREATE TABLE webcam (
  id int(20) auto_increment NOT NULL,
  user_id int(6) DEFAULT '0' NOT NULL,
  state int(1) DEFAULT '0' NOT NULL,
  image blob NOT NULL,
  image_small blob,
  comment tinytext,
  timestamp timestamp(14),
  content_type varchar(128),
  size int(8),
  name varchar(128) DEFAULT '' NOT NULL,
  PRIMARY KEY (id)
);


DROP TABLE IF EXISTS tips;
CREATE TABLE tips (
  id int(6) NOT NULL auto_increment,
  tip_section_id int(6) DEFAULT '0' NOT NULL,
  user_id int(6) DEFAULT '0' NOT NULL,
  state int(1) DEFAULT '0' NOT NULL,
  name varchar(128) DEFAULT '' NOT NULL,
  tip text DEFAULT '' NOT NULL,
  timestamp timestamp(14),
  PRIMARY KEY (id)
);

DROP TABLE IF EXISTS tips_sections;
CREATE TABLE tips_sections (
  id int(6) NOT NULL auto_increment,
  tip_section_referer_id int(6) DEFAULT '0' NOT NULL,
  tip_section varchar(50),
  state int(1) DEFAULT '1' NOT NULL,
  PRIMARY KEY (id)
);


INSERT INTO users (id,login,passwd) VALUES ('1', 'Anonyme','X');
INSERT INTO users (id,login,passwd,level,email) VALUES ('2', 'admin','X','6291456','root');
INSERT INTO sig (sig) VALUES ('');
INSERT INTO lang VALUES (1,'fr','Francais');
INSERT INTO lang VALUES (2,'en','Anglais');
INSERT INTO sections VALUES (1,'Articles',1);
INSERT INTO topics VALUES (1,'Linux','Linux',1);
