CREATE TABLE UserAgents (
  ProfileID VARCHAR(36) NOT NULL,
  AgentIP VARCHAR(24) DEFAULT NULL,
  AgentPort INT DEFAULT NULL,
  AgentOnline BIT DEFAULT NULL,
  SessionID VARCHAR(36) DEFAULT NULL,
  SecureSessionID VARCHAR(36) DEFAULT NULL,
  InitialRegion VARCHAR(255) DEFAULT NULL,
  Region VARCHAR(255) DEFAULT NULL,
  LoginTime INT DEFAULT NULL,
  LogoutTime INT DEFAULT NULL,
  Handle BIGINT DEFAULT NULL,
  PositionX DOUBLE DEFAULT NULL,
  PositionY DOUBLE DEFAULT NULL,
  PositionZ DOUBLE DEFAULT NULL,
  LookAtX DOUBLE DEFAULT NULL,
  LookAtY DOUBLE DEFAULT NULL,
  LookAtZ DOUBLE DEFAULT NULL,  
  PRIMARY KEY (ProfileID)
);

CREATE TABLE UserProfiles (
  ID VARCHAR(36) NOT NULL,
  WebLoginKey VARCHAR(36) DEFAULT NULL,
  FirstName VARCHAR(32) DEFAULT NULL,
  SurName VARCHAR(32) DEFAULT NULL,
  Email VARCHAR(250) DEFAULT NULL,
  PasswordHash VARCHAR(32) DEFAULT NULL,
  PasswordSalt VARCHAR(32) DEFAULT NULL,
  HomeRegionID VARCHAR(36) DEFAULT NULL,
  HomeRegionX INT DEFAULT NULL,
  HomeRegionY INT DEFAULT NULL,
  HomeLocationX DOUBLE DEFAULT NULL,
  HomeLocationY DOUBLE DEFAULT NULL,
  HomeLocationZ DOUBLE DEFAULT NULL,
  HomeLookAtX DOUBLE DEFAULT NULL,
  HomeLookAtY DOUBLE DEFAULT NULL,
  HomeLookAtZ DOUBLE DEFAULT NULL,
  Created INT DEFAULT NULL,
  LastLogin INT DEFAULT NULL,
  UserInventoryURI VARCHAR(255) DEFAULT NULL,
  UserAssetURI VARCHAR(255) DEFAULT NULL,
  Image VARCHAR(36) DEFAULT NULL,
  FirstLifeImage VARCHAR(36) DEFAULT NULL,
  AboutText TEXT DEFAULT NULL,
  FirstLifeAboutText TEXT DEFAULT NULL,
  CanDoMask INT DEFAULT NULL,
  WantDoMask INT DEFAULT NULL,
  UserFlags INT DEFAULT NULL,
  GodLevel INT DEFAULT NULL,  
  CustomType VARCHAR(32) DEFAULT NULL,
  Partner VARCHAR(36) DEFAULT NULL,
  RootInventoryFolderID VARCHAR(36) DEFAULT NULL,
  PRIMARY KEY (ID)
);

CREATE INDEX UserSurnameIndex ON UserProfiles (SurName);
CREATE INDEX UserFirstNameIndex ON UserProfiles (FirstName);
CREATE UNIQUE INDEX UserFullNameIndex ON UserProfiles (SurName,FirstName);

CREATE TABLE UserAppearances (
  Owner VARCHAR(36) NOT NULL,
  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,    
  PRIMARY KEY (Owner)
);

CREATE TABLE UserFriends (
  UserFriendID VARCHAR(36) NOT NULL,
  OwnerID VARCHAR(36) DEFAULT NULL,
  FriendID VARCHAR(36) DEFAULT NULL,
  FriendPermissions INT DEFAULT NULL,
  PRIMARY KEY (UserFriendID)  
);

CREATE UNIQUE INDEX UserFriendsOwnerIdFriendIdIndex ON UserFriends (OwnerID,FriendID);  
