/**
 * $Id: create_user_tables.mysql,v 1.3 2001/11/01 01:49:12 mdb Exp $
 *
 * Creates the necessary database tables in MySQL for the user repository.
 */

/**
 * The users table contains a row for every user.
 */
DROP TABLE IF EXISTS users;
CREATE TABLE users (
    userId    INTEGER(10) PRIMARY KEY NOT NULL AUTO_INCREMENT,
    username  VARCHAR(24) NOT NULL,
    password  VARCHAR(13) NOT NULL,
    email     VARCHAR(128) NOT NULL,
    realname  VARCHAR(128) NOT NULL,
    created   DATE NOT NULL,
    siteId    INTEGER(5) NOT NULL,

    UNIQUE INDEX username_index (username)
);

/**
 * The sessions table contains a row for every authenticated
 * user. Sessions map a session identifier to a user record and expire
 * after an application determined amount of time. A request that supplies
 * a valid session identifier is treated as being authenticated as the
 * user to which that session is mapped, so long timeouts are discouraged.
 */
DROP TABLE IF EXISTS sessions;
CREATE TABLE sessions (
    sessionId  INTEGER(10) PRIMARY KEY NOT NULL AUTO_INCREMENT,
    authcode   VARCHAR(32) NOT NULL,
    userId     INTEGER(10) NOT NULL,
    expires    DATE NOT NULL,

    UNIQUE INDEX authcode_index (authcode)
);
