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

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

/* Create softndesign db */
create database softndesign;

/* Create user table */
use softndesign;
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 softndesign;
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 softndesign;
create table associations (
  uid integer not null,
  gid integer not null,
--
  primary key (uid, gid)
);

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

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

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

/* Fisrt user */
insert into groups set name='admin', description='Administrateurs';
insert into users set login='admin', password=password('4dm1n'), fullname='M. Administrateur';
insert into associations set uid='1', gid='1';
