:VERSION 1

BEGIN TRANSACTION;

-- users table
CREATE TABLE users(
       UUID varchar(255) primary key,
       username varchar(255),
       surname varchar(255),
       passwordHash varchar(255),
       passwordSalt varchar(255),
       homeRegionX integer,
       homeRegionY integer,
       homeLocationX float,
       homeLocationY float,
       homeLocationZ float,
       homeLookAtX float,
       homeLookAtY float,
       homeLookAtZ float,
       created integer,
       lastLogin integer,
       rootInventoryFolderID varchar(255),
       userInventoryURI varchar(255),
       userAssetURI varchar(255),
       profileCanDoMask integer,
       profileWantDoMask integer,
       profileAboutText varchar(255),
       profileFirstText varchar(255),
       profileImage varchar(255),
       profileFirstImage varchar(255), 
       webLoginKey text default '00000000-0000-0000-0000-000000000000');
-- friends table
CREATE TABLE userfriends(
       ownerID varchar(255),
       friendID varchar(255),
       friendPerms integer,
       ownerPerms integer,
       datetimestamp integer);

COMMIT;

:VERSION 2

BEGIN;

ALTER TABLE users add homeRegionID varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000';

COMMIT;

:VERSION 3

BEGIN;

ALTER TABLE users add userFlags integer NOT NULL default 0;
ALTER TABLE users add godLevel integer NOT NULL default 0;

COMMIT;

:VERSION 4

BEGIN;

ALTER TABLE users add customType varchar(32) not null default '';
ALTER TABLE users add partner char(36) not null default '00000000-0000-0000-0000-000000000000';

COMMIT;

:VERSION 5

BEGIN;

CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `attachpoint` int(11) NOT NULL DEFAULT 0, `item` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `asset` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000');

COMMIT;

:VERSION 6

BEGIN TRANSACTION;

-- usersagents table
CREATE TABLE IF NOT EXISTS useragents(
       UUID varchar(255) primary key,
       agentIP varchar(255),
       agentPort integer,
       agentOnline boolean,
       sessionID varchar(255),
       secureSessionID varchar(255),
       regionID varchar(255),
       loginTime integer,
       logoutTime integer,
       currentRegion varchar(255),
       currentHandle varchar(255),
       currentPosX float,
       currentPosY float,
       currentPosZ float);

COMMIT;

:VERSION 7

BEGIN TRANSACTION;

ALTER TABLE useragents add currentLookAtX float not null default 128;
ALTER TABLE useragents add currentLookAtY float not null default 128;
ALTER TABLE useragents add currentLookAtZ float not null default 70;

COMMIT;

:VERSION 8

BEGIN TRANSACTION;

ALTER TABLE users add email varchar(250);

COMMIT;

:VERSION 9

BEGIN;

update users
  set UUID = substr(UUID, 1, 8) || "-" || substr(UUID, 9, 4) || "-" || substr(UUID, 13, 4) || "-" || substr(UUID, 17, 4) || "-" || substr(UUID, 21, 12)
  where UUID not like '%-%';

update useragents
  set UUID = substr(UUID, 1, 8) || "-" || substr(UUID, 9, 4) || "-" || substr(UUID, 13, 4) || "-" || substr(UUID, 17, 4) || "-" || substr(UUID, 21, 12)
  where UUID not like '%-%';

COMMIT;

:VERSION 10

BEGIN TRANSACTION;

CREATE TABLE IF NOT EXISTS avatarappearance(
  Owner varchar(36) NOT NULL primary key,
  BodyItem varchar(36) DEFAULT NULL,
  BodyAsset varchar(36) DEFAULT NULL,
  SkinItem varchar(36) DEFAULT NULL,
  SkinAsset varchar(36) DEFAULT NULL,
  HairItem varchar(36) DEFAULT NULL,
  HairAsset varchar(36) DEFAULT NULL,
  EyesItem varchar(36) DEFAULT NULL,
  EyesAsset varchar(36) DEFAULT NULL,
  ShirtItem varchar(36) DEFAULT NULL,
  ShirtAsset varchar(36) DEFAULT NULL,
  PantsItem varchar(36) DEFAULT NULL,
  PantsAsset varchar(36) DEFAULT NULL,
  ShoesItem varchar(36) DEFAULT NULL,
  ShoesAsset varchar(36) DEFAULT NULL,
  SocksItem varchar(36) DEFAULT NULL,
  SocksAsset varchar(36) DEFAULT NULL,
  JacketItem varchar(36) DEFAULT NULL,
  JacketAsset varchar(36) DEFAULT NULL,
  GlovesItem varchar(36) DEFAULT NULL,
  GlovesAsset varchar(36) DEFAULT NULL,
  UnderShirtItem varchar(36) DEFAULT NULL,
  UnderShirtAsset varchar(36) DEFAULT NULL,
  UnderPantsItem varchar(36) DEFAULT NULL,
  UnderPantsAsset varchar(36) DEFAULT NULL,
  SkirtItem varchar(36) DEFAULT NULL,
  SkirtAsset varchar(36) DEFAULT NULL,
  Texture blob,
  VisualParams blob,
  Serial int DEFAULT NULL,
  AvatarHeight float DEFAULT NULL
);

COMMIT;
