:VERSION 1

CREATE TABLE [users] (
  [UUID] [varchar](36) NOT NULL default '',
  [username] [varchar](32) NOT NULL,
  [lastname] [varchar](32) NOT NULL,
  [passwordHash] [varchar](32) NOT NULL,
  [passwordSalt] [varchar](32) NOT NULL,
  [homeRegion] [bigint] default NULL,
  [homeLocationX] [float] default NULL,
  [homeLocationY] [float] default NULL,
  [homeLocationZ] [float] default NULL,
  [homeLookAtX] [float] default NULL,
  [homeLookAtY] [float] default NULL,
  [homeLookAtZ] [float] default NULL,
  [created] [int] NOT NULL,
  [lastLogin] [int] NOT NULL,
  [userInventoryURI] [varchar](255) default NULL,
  [userAssetURI] [varchar](255) default NULL,
  [profileCanDoMask] [int] default NULL,
  [profileWantDoMask] [int] default NULL,
  [profileAboutText] [ntext],
  [profileFirstText] [ntext],
  [profileImage] [varchar](36) default NULL,
  [profileFirstImage] [varchar](36) default NULL,
  [webLoginKey] [varchar](36) default NULL,
  PRIMARY KEY CLUSTERED
(
	[UUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [usernames] ON [users]
(
	[username] ASC,
	[lastname] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


CREATE TABLE [agents] (
  [UUID] [varchar](36) NOT NULL,
  [sessionID] [varchar](36) NOT NULL,
  [secureSessionID] [varchar](36) NOT NULL,
  [agentIP] [varchar](16) NOT NULL,
  [agentPort] [int] NOT NULL,
  [agentOnline] [tinyint] NOT NULL,
  [loginTime] [int] NOT NULL,
  [logoutTime] [int] NOT NULL,
  [currentRegion] [varchar](36) NOT NULL,
  [currentHandle] [bigint] NOT NULL,
  [currentPos] [varchar](64) NOT NULL,
  PRIMARY KEY CLUSTERED
(
	[UUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [session] ON [agents]
(
	[sessionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [ssession] ON [agents]
(
	[secureSessionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


CREATE TABLE [dbo].[userfriends](
	[ownerID] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[friendID] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[friendPerms] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[datetimestamp] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]

CREATE TABLE [avatarappearance]  (
  [Owner]  [varchar](36) NOT NULL,
  [Serial]  int NOT NULL,
  [Visual_Params] [image] NOT NULL,
  [Texture] [image] NOT NULL,
  [Avatar_Height] float NOT NULL,
  [Body_Item] [varchar](36) NOT NULL,
  [Body_Asset] [varchar](36) NOT NULL,
  [Skin_Item] [varchar](36) NOT NULL,
  [Skin_Asset] [varchar](36) NOT NULL,
  [Hair_Item] [varchar](36) NOT NULL,
  [Hair_Asset] [varchar](36) NOT NULL,
  [Eyes_Item] [varchar](36) NOT NULL,
  [Eyes_Asset] [varchar](36) NOT NULL,
  [Shirt_Item] [varchar](36) NOT NULL,
  [Shirt_Asset] [varchar](36) NOT NULL,
  [Pants_Item] [varchar](36) NOT NULL,
  [Pants_Asset] [varchar](36) NOT NULL,
  [Shoes_Item] [varchar](36) NOT NULL,
  [Shoes_Asset] [varchar](36) NOT NULL,
  [Socks_Item] [varchar](36) NOT NULL,
  [Socks_Asset] [varchar](36) NOT NULL,
  [Jacket_Item] [varchar](36) NOT NULL,
  [Jacket_Asset] [varchar](36) NOT NULL,
  [Gloves_Item] [varchar](36) NOT NULL,
  [Gloves_Asset] [varchar](36) NOT NULL,
  [Undershirt_Item] [varchar](36) NOT NULL,
  [Undershirt_Asset] [varchar](36) NOT NULL,
  [Underpants_Item] [varchar](36) NOT NULL,
  [Underpants_Asset] [varchar](36) NOT NULL,
  [Skirt_Item] [varchar](36) NOT NULL,
  [Skirt_Asset] [varchar](36) NOT NULL,

  PRIMARY KEY  CLUSTERED (
  [Owner]
  ) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

:VERSION 2

BEGIN TRANSACTION

ALTER TABLE users ADD homeRegionID varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000';
ALTER TABLE users ADD userFlags int NOT NULL default 0;
ALTER TABLE users ADD godLevel int NOT NULL default 0;
ALTER TABLE users ADD customType varchar(32) not null default '';
ALTER TABLE users ADD partner varchar(36) not null default '00000000-0000-0000-0000-000000000000';

COMMIT


:VERSION 3

BEGIN TRANSACTION

CREATE TABLE [avatarattachments] (
	[UUID] varchar(36) NOT NULL
	, [attachpoint] int NOT NULL
	, [item] varchar(36) NOT NULL
	, [asset] varchar(36) NOT NULL)

CREATE NONCLUSTERED INDEX IX_avatarattachments ON dbo.avatarattachments
	(
	UUID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]


COMMIT


:VERSION 4

BEGIN TRANSACTION

CREATE TABLE Tmp_userfriends
	(
	ownerID varchar(36) NOT NULL,
	friendID varchar(36) NOT NULL,
	friendPerms int NOT NULL,
	datetimestamp int NOT NULL
	)  ON [PRIMARY]

IF EXISTS(SELECT * FROM userfriends)
	 EXEC('INSERT INTO dbo.Tmp_userfriends (ownerID, friendID, friendPerms, datetimestamp)
		SELECT CONVERT(varchar(36), ownerID), CONVERT(varchar(36), friendID), CONVERT(int, friendPerms), CONVERT(int, datetimestamp) FROM dbo.userfriends WITH (HOLDLOCK TABLOCKX)')

DROP TABLE dbo.userfriends

EXECUTE sp_rename N'Tmp_userfriends', N'userfriends', 'OBJECT' 

CREATE NONCLUSTERED INDEX IX_userfriends_ownerID ON userfriends
	(
	ownerID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX IX_userfriends_friendID ON userfriends
	(
	friendID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

COMMIT


:VERSION 5

BEGIN TRANSACTION

 ALTER TABLE users add email varchar(250);
 
COMMIT


:VERSION 6

BEGIN TRANSACTION

CREATE TABLE dbo.Tmp_users
	(
	UUID uniqueidentifier NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'),
	username varchar(32) NOT NULL,
	lastname varchar(32) NOT NULL,
	passwordHash varchar(32) NOT NULL,
	passwordSalt varchar(32) NOT NULL,
	homeRegion bigint NULL DEFAULT (NULL),
	homeLocationX float(53) NULL DEFAULT (NULL),
	homeLocationY float(53) NULL DEFAULT (NULL),
	homeLocationZ float(53) NULL DEFAULT (NULL),
	homeLookAtX float(53) NULL DEFAULT (NULL),
	homeLookAtY float(53) NULL DEFAULT (NULL),
	homeLookAtZ float(53) NULL DEFAULT (NULL),
	created int NOT NULL,
	lastLogin int NOT NULL,
	userInventoryURI varchar(255) NULL DEFAULT (NULL),
	userAssetURI varchar(255) NULL DEFAULT (NULL),
	profileCanDoMask int NULL DEFAULT (NULL),
	profileWantDoMask int NULL DEFAULT (NULL),
	profileAboutText ntext NULL,
	profileFirstText ntext NULL,
	profileImage uniqueidentifier NULL DEFAULT (NULL),
	profileFirstImage uniqueidentifier NULL DEFAULT (NULL),
	webLoginKey uniqueidentifier NULL DEFAULT (NULL),
	homeRegionID uniqueidentifier NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'),
	userFlags int NOT NULL DEFAULT ((0)),
	godLevel int NOT NULL DEFAULT ((0)),
	customType varchar(32) NOT NULL DEFAULT (''),
	partner uniqueidentifier NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'),
	email varchar(250) NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]

IF EXISTS(SELECT * FROM dbo.users)
	 EXEC('INSERT INTO dbo.Tmp_users (UUID, username, lastname, passwordHash, passwordSalt, homeRegion, homeLocationX, homeLocationY, homeLocationZ, homeLookAtX, homeLookAtY, homeLookAtZ, created, lastLogin, userInventoryURI, userAssetURI, profileCanDoMask, profileWantDoMask, profileAboutText, profileFirstText, profileImage, profileFirstImage, webLoginKey, homeRegionID, userFlags, godLevel, customType, partner, email)
		SELECT CONVERT(uniqueidentifier, UUID), username, lastname, passwordHash, passwordSalt, homeRegion, homeLocationX, homeLocationY, homeLocationZ, homeLookAtX, homeLookAtY, homeLookAtZ, created, lastLogin, userInventoryURI, userAssetURI, profileCanDoMask, profileWantDoMask, profileAboutText, profileFirstText, CONVERT(uniqueidentifier, profileImage), CONVERT(uniqueidentifier, profileFirstImage), CONVERT(uniqueidentifier, webLoginKey), CONVERT(uniqueidentifier, homeRegionID), userFlags, godLevel, customType, CONVERT(uniqueidentifier, partner), email FROM dbo.users WITH (HOLDLOCK TABLOCKX)')

DROP TABLE dbo.users

EXECUTE sp_rename N'dbo.Tmp_users', N'users', 'OBJECT' 

ALTER TABLE dbo.users ADD CONSTRAINT
	PK__users__65A475E737A5467C PRIMARY KEY CLUSTERED 
	(
	UUID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX usernames ON dbo.users
	(
	username,
	lastname
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

COMMIT


:VERSION 7

BEGIN TRANSACTION

CREATE TABLE dbo.Tmp_agents
	(
	UUID uniqueidentifier NOT NULL,
	sessionID uniqueidentifier NOT NULL,
	secureSessionID uniqueidentifier NOT NULL,
	agentIP varchar(16) NOT NULL,
	agentPort int NOT NULL,
	agentOnline tinyint NOT NULL,
	loginTime int NOT NULL,
	logoutTime int NOT NULL,
	currentRegion uniqueidentifier NOT NULL,
	currentHandle bigint NOT NULL,
	currentPos varchar(64) NOT NULL
	)  ON [PRIMARY]

IF EXISTS(SELECT * FROM dbo.agents)
	 EXEC('INSERT INTO dbo.Tmp_agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos)
		SELECT CONVERT(uniqueidentifier, UUID), CONVERT(uniqueidentifier, sessionID), CONVERT(uniqueidentifier, secureSessionID), agentIP, agentPort, agentOnline, loginTime, logoutTime, CONVERT(uniqueidentifier, currentRegion), currentHandle, currentPos FROM dbo.agents WITH (HOLDLOCK TABLOCKX)')

DROP TABLE dbo.agents

EXECUTE sp_rename N'dbo.Tmp_agents', N'agents', 'OBJECT' 

ALTER TABLE dbo.agents ADD CONSTRAINT
	PK__agents__65A475E749C3F6B7 PRIMARY KEY CLUSTERED 
	(
	UUID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX session ON dbo.agents
	(
	sessionID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX ssession ON dbo.agents
	(
	secureSessionID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

COMMIT


:VERSION 8

BEGIN TRANSACTION

CREATE TABLE dbo.Tmp_userfriends
	(
	ownerID uniqueidentifier NOT NULL,
	friendID uniqueidentifier NOT NULL,
	friendPerms int NOT NULL,
	datetimestamp int NOT NULL
	)  ON [PRIMARY]

IF EXISTS(SELECT * FROM dbo.userfriends)
	 EXEC('INSERT INTO dbo.Tmp_userfriends (ownerID, friendID, friendPerms, datetimestamp)
		SELECT CONVERT(uniqueidentifier, ownerID), CONVERT(uniqueidentifier, friendID), friendPerms, datetimestamp FROM dbo.userfriends WITH (HOLDLOCK TABLOCKX)')

DROP TABLE dbo.userfriends

EXECUTE sp_rename N'dbo.Tmp_userfriends', N'userfriends', 'OBJECT' 

CREATE NONCLUSTERED INDEX IX_userfriends_ownerID ON dbo.userfriends
	(
	ownerID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX IX_userfriends_friendID ON dbo.userfriends
	(
	friendID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

COMMIT


:VERSION 9

BEGIN TRANSACTION

CREATE TABLE dbo.Tmp_avatarappearance
	(
	Owner uniqueidentifier NOT NULL,
	Serial int NOT NULL,
	Visual_Params image NOT NULL,
	Texture image NOT NULL,
	Avatar_Height float(53) NOT NULL,
	Body_Item uniqueidentifier NOT NULL,
	Body_Asset uniqueidentifier NOT NULL,
	Skin_Item uniqueidentifier NOT NULL,
	Skin_Asset uniqueidentifier NOT NULL,
	Hair_Item uniqueidentifier NOT NULL,
	Hair_Asset uniqueidentifier NOT NULL,
	Eyes_Item uniqueidentifier NOT NULL,
	Eyes_Asset uniqueidentifier NOT NULL,
	Shirt_Item uniqueidentifier NOT NULL,
	Shirt_Asset uniqueidentifier NOT NULL,
	Pants_Item uniqueidentifier NOT NULL,
	Pants_Asset uniqueidentifier NOT NULL,
	Shoes_Item uniqueidentifier NOT NULL,
	Shoes_Asset uniqueidentifier NOT NULL,
	Socks_Item uniqueidentifier NOT NULL,
	Socks_Asset uniqueidentifier NOT NULL,
	Jacket_Item uniqueidentifier NOT NULL,
	Jacket_Asset uniqueidentifier NOT NULL,
	Gloves_Item uniqueidentifier NOT NULL,
	Gloves_Asset uniqueidentifier NOT NULL,
	Undershirt_Item uniqueidentifier NOT NULL,
	Undershirt_Asset uniqueidentifier NOT NULL,
	Underpants_Item uniqueidentifier NOT NULL,
	Underpants_Asset uniqueidentifier NOT NULL,
	Skirt_Item uniqueidentifier NOT NULL,
	Skirt_Asset uniqueidentifier NOT NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]

IF EXISTS(SELECT * FROM dbo.avatarappearance)
	 EXEC('INSERT INTO dbo.Tmp_avatarappearance (Owner, Serial, Visual_Params, Texture, Avatar_Height, Body_Item, Body_Asset, Skin_Item, Skin_Asset, Hair_Item, Hair_Asset, Eyes_Item, Eyes_Asset, Shirt_Item, Shirt_Asset, Pants_Item, Pants_Asset, Shoes_Item, Shoes_Asset, Socks_Item, Socks_Asset, Jacket_Item, Jacket_Asset, Gloves_Item, Gloves_Asset, Undershirt_Item, Undershirt_Asset, Underpants_Item, Underpants_Asset, Skirt_Item, Skirt_Asset)
		SELECT CONVERT(uniqueidentifier, Owner), Serial, Visual_Params, Texture, Avatar_Height, CONVERT(uniqueidentifier, Body_Item), CONVERT(uniqueidentifier, Body_Asset), CONVERT(uniqueidentifier, Skin_Item), CONVERT(uniqueidentifier, Skin_Asset), CONVERT(uniqueidentifier, Hair_Item), CONVERT(uniqueidentifier, Hair_Asset), CONVERT(uniqueidentifier, Eyes_Item), CONVERT(uniqueidentifier, Eyes_Asset), CONVERT(uniqueidentifier, Shirt_Item), CONVERT(uniqueidentifier, Shirt_Asset), CONVERT(uniqueidentifier, Pants_Item), CONVERT(uniqueidentifier, Pants_Asset), CONVERT(uniqueidentifier, Shoes_Item), CONVERT(uniqueidentifier, Shoes_Asset), CONVERT(uniqueidentifier, Socks_Item), CONVERT(uniqueidentifier, Socks_Asset), CONVERT(uniqueidentifier, Jacket_Item), CONVERT(uniqueidentifier, Jacket_Asset), CONVERT(uniqueidentifier, Gloves_Item), CONVERT(uniqueidentifier, Gloves_Asset), CONVERT(uniqueidentifier, Undershirt_Item), CONVERT(uniqueidentifier, Undershirt_Asset), CONVERT(uniqueidentifier, Underpants_Item), CONVERT(uniqueidentifier, Underpants_Asset), CONVERT(uniqueidentifier, Skirt_Item), CONVERT(uniqueidentifier, Skirt_Asset) FROM dbo.avatarappearance WITH (HOLDLOCK TABLOCKX)')

DROP TABLE dbo.avatarappearance

EXECUTE sp_rename N'dbo.Tmp_avatarappearance', N'avatarappearance', 'OBJECT' 

ALTER TABLE dbo.avatarappearance ADD CONSTRAINT
	PK__avatarap__7DD115CC4E88ABD4 PRIMARY KEY CLUSTERED 
	(
	Owner
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

COMMIT


:VERSION 10

BEGIN TRANSACTION

CREATE TABLE dbo.Tmp_avatarattachments
	(
	UUID uniqueidentifier NOT NULL,
	attachpoint int NOT NULL,
	item uniqueidentifier NOT NULL,
	asset uniqueidentifier NOT NULL
	)  ON [PRIMARY]

IF EXISTS(SELECT * FROM dbo.avatarattachments)
	 EXEC('INSERT INTO dbo.Tmp_avatarattachments (UUID, attachpoint, item, asset)
		SELECT CONVERT(uniqueidentifier, UUID), attachpoint, CONVERT(uniqueidentifier, item), CONVERT(uniqueidentifier, asset) FROM dbo.avatarattachments WITH (HOLDLOCK TABLOCKX)')

DROP TABLE dbo.avatarattachments

EXECUTE sp_rename N'dbo.Tmp_avatarattachments', N'avatarattachments', 'OBJECT' 

CREATE NONCLUSTERED INDEX IX_avatarattachments ON dbo.avatarattachments
	(
	UUID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

COMMIT


:VERSION 11

BEGIN TRANSACTION

ALTER TABLE users ADD scopeID uniqueidentifier not null default '00000000-0000-0000-0000-000000000000'

COMMIT