/* Create user simpleweb */  
use mysql; 
insert into user (Host, User, Password)
  values('localhost', 'simpleweb', password('******'));
/* on duplicate key update; */

/* Allow simpleweb user to access simpleweb db */
use mysql; 
insert into db (Host, Db, User, Select_priv)
  values('localhost','simpleweb','simpleweb','Y');

/* Create simpleweb db */
create database simpleweb;

/* Create user table */
use simpleweb;
create table users (
  uid integer not null auto_increment,
  login varchar(255) default '' not null,
  password varchar(255) default '' not null,
  fullname varchar(255) default '',
--
  primary key (uid)
);

/* Create group table */
use simpleweb;
create table groups (
  gid integer not null auto_increment,
  name varchar(255) default '' not null,
  description varchar(255) default '',
--
  primary key (gid)
);

/* Create user and group association table */
use simpleweb;
create table associations (
  uid integer not null,
  gid integer not null,
--
  primary key (uid, gid)
);

/* Crete session table */
use simpleweb;
create table sessions (
  sid integer not null auto_increment,
  uid integer not null,
  expire float not null,
--
  primary key (sid)
);

/* Grant simpleweb user to simpleweb tables */
grant select, insert, update, delete on associations to simpleweb;
grant select, insert, update, delete on groups to simpleweb;
grant select, insert, update, delete on users to simpleweb;
grant select, insert, update, delete on sessions to simpleweb;

/* Flush all the stuff */
flush query cache;
