/* -*-sql-*-
 *
 * Plain old SQL for setting up the tables for Odin web services.
 *
 * (c) 2015 Mark Wooding
 */

/*----- Licensing notice ----------------------------------------------------
 *
 * This file is part of the `odin.gg' service, `odin-cgi'.
 *
 * `odin-cgi' is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * `odin-cgi' is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with `odin-cgi'; if not, see
 * <http://www.gnu.org/licenses/>.
 */

/* The various tools assume that the database is appropriate configured with
 * the SERIALIZABLE isolation level.
 */

begin;

drop table if exists odin_shorturl;
drop table if exists odin_shorturl_seq;

create table odin_shorturl_seq (seq int);
insert into odin_shorturl_seq (seq) values (10000);

create table odin_shorturl
	(tag varchar(16) primary key,
	 stamp bigint not null,
	 owner varchar(64) not null,
	 url text not null);
create index odin_shorturl_by_owner on odin_shorturl (owner);
create index odin_shorturl_by_url_owner on odin_shorturl (url, owner);

commit;
