--- trunk/schema.sql	2005/05/14 12:31:15	5
+++ trunk/schema.sql	2005/05/17 11:09:08	33
@@ -1,7 +1,7 @@
 create table users (
 	id	serial,
 	email	text not null,
-	full_name text not null,
+	full_name text default '',
 	date	timestamp not null default now(),
 	active	boolean not null default true,
 	bounce_count int not null default 0,
@@ -9,15 +9,19 @@
 	primary key(id)
 );
 
+create unique index users_email_ind on users(email);
+
 create table lists (
 	id	serial,
 	name	text not null,
+	email	text not null,
 	bounce_limit int not null default 3,
 	date	timestamp not null default now(),
 	primary key(id)
 );
 
-create index lists_name_ind on lists(name);
+create unique index lists_name_ind on lists(name);
+create unique index lists_email_ind on lists(email);
 
 create table user_list (
 	user_id	int not null references users(id) on update cascade on delete cascade,
@@ -33,12 +37,11 @@
 	primary key(id)
 );
 
-create index messages_md5_ind on messages(md5);
-
-create table message_list (
+create table queue (
 	message_id int not null references messages(id) on update cascade on delete cascade,
-	list_id int not null references lists(id) on update cascade on delete cascade,
+	list_id	int not null references lists(id) on update cascade on delete cascade,
 	date	timestamp not null default now(),
+	all_sent boolean default false,
 	primary key(message_id, list_id)
 );
 
@@ -46,15 +49,16 @@
 	message_id int not null references messages(id) on update cascade on delete cascade,
 	user_id	int not null references users(id) on update cascade on delete cascade,
 	date	timestamp not null default now(),
-	sent	boolean not null default false,
 	primary key(message_id, user_id)
 );
 
 create table received (
-	user_id	not null references users(id) on update cascade on delete cascade,
+	id serial,
+	user_id	int not null references users(id) on update cascade on delete cascade,
 	message	text not null,
 	bounced	boolean not null default false,
 	date	timestamp not null default now(),
+	primary key (id)
 );
 
 
@@ -62,8 +66,8 @@
 insert into users (email, full_name) values ('dpavlin@gmail.com', 'DbP');
 insert into users (email, full_name) values ('xxx_doesnt_exist_xxx@gmail.com', 'fake');
 
-insert into lists (name) values ('Just me');
-insert into lists (name) values ('All users');
+insert into lists (name, email) values ('Just me','my-alter-ego@rot13.org');
+insert into lists (name, email) values ('All users','announce@example.com');
 
 insert into user_list (user_id, list_id) select users.id,1 from users limit 1;
 insert into user_list (user_id, list_id) select users.id,2 from users;
