/* Read this into mysql with "\. initdb-mysql" when logged in as root
   to delete the old lxr database and create a new */ 

drop if exists database lxr; 
create database lxr; 
use lxr;

/* symnum filenum */
create table files (
        filename        char(255) binary not null,
        revision        char(255) binary not null,
        fileid          int not null auto_increment,
        primary key     (fileid) /*,
        unique          (filename, revision) */

);

create table symbols (
        symname         char(255) binary not null,
        symid           int not null auto_increment,
        primary key     (symid),
        unique          (symname)

);

create table indexes (
        symid           int not null references symbols,
        fileid          int not null references files,
        line            int not null,
		langid          tinyint not null references declarations,
        type            smallint not null references declarations,
        relsym          int          references symbols
);

create table releases 
        (fileid         int not null references files,
        release         char(255) binary not null,
        primary key     (fileid,release)
);

create table useage
        (fileid         int not null    references files,
        line            int not null,
        symid           int not null    references symbols
);

create table status
        (fileid         int not null references files,
        status          tinyint not null,
        primary key     (fileid)
);

create table declarations
		(declid  		smallint not null auto_increment,
		 langid         tinyint not null,
		 declaration    char(255) not null,
		 primary key    (declid, langid)
);


create index indexindex on indexes  (symid) ;
create unique index symbolindex on symbols  (symname) ;
create index useageindex on useage  (symid) ;
create index filelookup on files (filename);

grant all on lxr.* to lxr@localhost;
