CREATE TABLE IF NOT EXISTS ajxp_users (
  login varchar(255) NOT NULL,
  password varchar(255) NOT NULL,
  groupPath varchar(255) NULL,
  PRIMARY KEY  (login)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_user_rights (
	rid INTEGER PRIMARY KEY AUTO_INCREMENT,
	login VARCHAR(255) NOT NULL,
	repo_uuid VARCHAR(33) NOT NULL,
	rights MEDIUMTEXT NOT NULL,
  INDEX (login),
  INDEX (repo_uuid)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_user_prefs (
	rid INTEGER PRIMARY KEY AUTO_INCREMENT,
	login VARCHAR(255) NOT NULL,
	name VARCHAR(255) NOT NULL,
	val BLOB
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_user_bookmarks (
	rid INTEGER PRIMARY KEY AUTO_INCREMENT,
	login VARCHAR(255) NOT NULL,
	repo_uuid VARCHAR(33) NOT NULL,
	path VARCHAR(255),
	title VARCHAR(255)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_repo (
	uuid VARCHAR(33) PRIMARY KEY,
	parent_uuid VARCHAR(33) default NULL,
	owner_user_id VARCHAR(255) default NULL,
	child_user_id VARCHAR(255) default NULL,
	path VARCHAR(255),
	display VARCHAR(255),
	accessType VARCHAR(20),
	recycle VARCHAR(255),
	bcreate BOOLEAN,
	writeable BOOLEAN,
	enabled BOOLEAN,
	isTemplate BOOLEAN,
	inferOptionsFromParent BOOLEAN,
	slug VARCHAR(255),
	groupPath VARCHAR(255)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_repo_options (
	oid INTEGER PRIMARY KEY AUTO_INCREMENT,
	uuid VARCHAR(33) NOT NULL,
	name VARCHAR(50) NOT NULL,
	val BLOB,
	INDEX (uuid)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_roles (
	role_id VARCHAR(255) PRIMARY KEY,
	serial_role TEXT(500) NOT NULL,
  last_updated INT(11) NOT NULL DEFAULT 0,
  INDEX `last_updated` (`last_updated`)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_groups (
    groupPath VARCHAR(255) PRIMARY KEY,
    groupLabel VARCHAR(255) NOT NULL
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_plugin_configs (
  id VARCHAR(50) NOT NULL,
  configs LONGBLOB NOT NULL,
  PRIMARY KEY (id)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_simple_store (
   object_id VARCHAR(255) NOT NULL,
   store_id VARCHAR(50) NOT NULL,
   serialized_data LONGTEXT NULL,
   binary_data LONGBLOB NULL,
   related_object_id VARCHAR(255) NULL,
   insertion_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY(object_id, store_id)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_user_teams (
    team_id VARCHAR(70) NOT NULL,
    user_id varchar(255) NOT NULL,
    team_label VARCHAR(255) NOT NULL,
    owner_id varchar(255) NOT NULL,
    PRIMARY KEY(team_id, user_id)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS ajxp_version (
  db_build INT NOT NULL
);
INSERT INTO ajxp_version SET db_build=0;