:VERSION 31

BEGIN TRANSACTION;

CREATE TABLE IF NOT EXISTS prims(
    UUID varchar(255) primary key,
    RegionUUID varchar(255),
	CreationDate integer,
	Name varchar(255),
	SceneGroupID varchar(255),
	Text varchar(255),
	Description varchar(255),
	SitName varchar(255),
	TouchName varchar(255),
	CreatorID varchar(255),
	OwnerID varchar(255),
	GroupID varchar(255),
	LastOwnerID varchar(255),
	OwnerMask integer,
	NextOwnerMask integer,
	GroupMask integer,
	EveryoneMask integer,
	BaseMask integer,
	PositionX float,
	PositionY float,
	PositionZ float,
	GroupPositionX float,
	GroupPositionY float,
	GroupPositionZ float,
	VelocityX float,
	VelocityY float,
	VelocityZ float,
	AngularVelocityX float,
	AngularVelocityY float,
	AngularVelocityZ float,
	AccelerationX float,
	AccelerationY float,
	AccelerationZ float,
	RotationX float,
	RotationY float,
	RotationZ float,
	RotationW float,
	ObjectFlags integer,
	SitTargetOffsetX float NOT NULL default 0,
	SitTargetOffsetY float NOT NULL default 0,
	SitTargetOffsetZ float NOT NULL default 0,
	SitTargetOrientW float NOT NULL default 0,
	SitTargetOrientX float NOT NULL default 0,
	SitTargetOrientY float NOT NULL default 0,
	SitTargetOrientZ float NOT NULL default 0,
	ColorR integer not null default 0,
	ColorG integer not null default 0,
	ColorB integer not null default 0,
	ColorA integer not null default 0,
	ClickAction integer not null default 0,
	PayPrice integer not null default 0,
	PayButton1 integer not null default 0,
	PayButton2 integer not null default 0,
	PayButton3 integer not null default 0,
	PayButton4 integer not null default 0,
	LoopedSound varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
	LoopedSoundGain float NOT NULL default 0,
	TextureAnimation string,
	ParticleSystem string,
	OmegaX float NOT NULL default 0,
	OmegaY float NOT NULL default 0,
	OmegaZ float NOT NULL default 0,
	CameraEyeOffsetX float NOT NULL default 0,
	CameraEyeOffsetY float NOT NULL default 0,
	CameraEyeOffsetZ float NOT NULL default 0,
	CameraAtOffsetX float NOT NULL default 0,
	CameraAtOffsetY float NOT NULL default 0,
	CameraAtOffsetZ float NOT NULL default 0,
	ForceMouselook string NOT NULL default 0,
	ScriptAccessPin INTEGER NOT NULL default 0,
	AllowedDrop INTEGER NOT NULL default 0,
	DieAtEdge string NOT NULL default 0,
	SalePrice INTEGER NOT NULL default 0,
	SaleType string NOT NULL default 0,
	Material INTEGER NOT NULL default 3,
	CollisionSound varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
	CollisionSoundVolume float NOT NULL default 0,
	VolumeDetect INTEGER NOT NULL DEFAULT 0, 
	MediaURL varchar(255), 
	DynAttrs TEXT, 
	`PhysicsShapeType` tinyint(4) NOT NULL default '0', 
	`Density` double NOT NULL default '1000', 
	`GravityModifier` double NOT NULL default '1', 
	`Friction` double NOT NULL default '0.6', 
	`Restitution` double NOT NULL default '0.5', 
	`KeyframeMotion` blob, 
	AttachedPosX double default '0', 
	AttachedPosY double default '0', 
	AttachedPosZ double default '0');

CREATE TABLE IF NOT EXISTS primshapes(
       UUID varchar(255) primary key,
       Shape integer,
       ScaleX float,
       ScaleY float,
       ScaleZ float,
       PCode integer,
       PathBegin integer,
       PathEnd integer,
       PathScaleX integer,
       PathScaleY integer,
       PathShearX integer,
       PathShearY integer,
       PathSkew integer,
       PathCurve integer,
       PathRadiusOffset integer,
       PathRevolutions integer,
       PathTaperX integer,
       PathTaperY integer,
       PathTwist integer,
       PathTwistBegin integer,
       ProfileBegin integer,
       ProfileEnd integer,
       ProfileCurve integer,
       ProfileHollow integer,
       Texture blob,
       ExtraParams blob,
       State Integer NOT NULL default 0, 
	   Media TEXT, 
	   LastAttachPoint int not null default '0');

CREATE TABLE IF NOT EXISTS primitems(
       itemID varchar(255) primary key,
       primID varchar(255),
       assetID varchar(255),
       parentFolderID varchar(255),
       invType integer,
       assetType integer,
       name varchar(255),
       description varchar(255),
       creationDate integer,
       creatorID varchar(255),
       ownerID varchar(255),
       lastOwnerID varchar(255),
       groupID varchar(255),
       nextPermissions string,
       currentPermissions string,
       basePermissions string,
       everyonePermissions string,
       groupPermissions string, 
	   flags integer not null default 0);

CREATE TABLE IF NOT EXISTS terrain(
       RegionUUID varchar(255),
       Revision integer,
       Heightfield blob);

CREATE TABLE IF NOT EXISTS land(
       UUID varchar(255) primary key,
       RegionUUID varchar(255),
       LocalLandID string,
       Bitmap blob,
       Name varchar(255),
       Desc varchar(255),
       OwnerUUID varchar(255),
       IsGroupOwned string,
       Area integer,
       AuctionID integer,
       Category integer,
       ClaimDate integer,
       ClaimPrice integer,
       GroupUUID varchar(255),
       SalePrice integer,
       LandStatus integer,
       LandFlags string,
       LandingType string,
       MediaAutoScale string,
       MediaTextureUUID varchar(255),
       MediaURL varchar(255),
       MusicURL varchar(255),
       PassHours float,
       PassPrice string,
       SnapshotUUID varchar(255),
       UserLocationX float,
       UserLocationY float,
       UserLocationZ float,
       UserLookAtX float,
       UserLookAtY float,
       UserLookAtZ float,
       AuthbuyerID varchar(36) NOT NULL default  '00000000-0000-0000-0000-000000000000', 
       OtherCleanTime INTEGER NOT NULL default 0, 
       Dwell INTEGER NOT NULL default 0, 
       `MediaType` VARCHAR(32) NOT NULL DEFAULT 'none/none', 
       `MediaDescription` VARCHAR(255) NOT NULL DEFAULT '', 
       `MediaSize` VARCHAR(16) NOT NULL DEFAULT '0,0', 
       `MediaLoop` BOOLEAN NOT NULL DEFAULT FALSE, 
       `ObscureMusic` BOOLEAN NOT NULL DEFAULT FALSE, 
       `ObscureMedia` BOOLEAN NOT NULL DEFAULT FALSE);

CREATE TABLE IF NOT EXISTS landaccesslist(
       LandUUID varchar(255),
       AccessUUID varchar(255),
       Flags string);

CREATE TABLE IF NOT EXISTS regionban(
                regionUUID varchar (255),
                bannedUUID varchar (255),
                bannedIp varchar (255),
                bannedIpHostMask varchar (255)
                );

CREATE TABLE IF NOT EXISTS regionsettings (
  regionUUID char(36) NOT NULL,
  block_terraform int(11) NOT NULL,
  block_fly int(11) NOT NULL,
  allow_damage int(11) NOT NULL,
  restrict_pushing int(11) NOT NULL,
  allow_land_resell int(11) NOT NULL,
  allow_land_join_divide int(11) NOT NULL,
  block_show_in_search int(11) NOT NULL,
  agent_limit int(11) NOT NULL,
  object_bonus float NOT NULL,
  maturity int(11) NOT NULL,
  disable_scripts int(11) NOT NULL,
  disable_collisions int(11) NOT NULL,
  disable_physics int(11) NOT NULL,
  terrain_texture_1 char(36) NOT NULL,
  terrain_texture_2 char(36) NOT NULL,
  terrain_texture_3 char(36) NOT NULL,
  terrain_texture_4 char(36) NOT NULL,
  elevation_1_nw float NOT NULL,
  elevation_2_nw float NOT NULL,
  elevation_1_ne float NOT NULL,
  elevation_2_ne float NOT NULL,
  elevation_1_se float NOT NULL,
  elevation_2_se float NOT NULL,
  elevation_1_sw float NOT NULL,
  elevation_2_sw float NOT NULL,
  water_height float NOT NULL,
  terrain_raise_limit float NOT NULL,
  terrain_lower_limit float NOT NULL,
  use_estate_sun int(11) NOT NULL,
  fixed_sun int(11) NOT NULL,
  sun_position float NOT NULL,
  covenant char(36) default NULL,
  sandbox tinyint(4) NOT NULL, 
  sunvectorx double NOT NULL default 0, 
  sunvectory double NOT NULL default 0, 
  sunvectorz double NOT NULL default 0, 
  map_tile_ID varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000', 
  covenant_datetime INTEGER NOT NULL default 0, 
  `TelehubObject` varchar(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', 
  `parcel_tile_ID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
  PRIMARY KEY  (regionUUID)
);

CREATE TABLE IF NOT EXISTS regionwindlight (
  region_id VARCHAR(36) NOT NULL DEFAULT '000000-0000-0000-0000-000000000000' PRIMARY KEY,
  water_color_r FLOAT NOT NULL DEFAULT '4.000000',
  water_color_g FLOAT NOT NULL DEFAULT '38.000000',
  water_color_b FLOAT NOT NULL DEFAULT '64.000000',
  water_color_i FLOAT NOT NULL DEFAULT '1.000000',
  water_fog_density_exponent FLOAT NOT NULL DEFAULT '4.0',
  underwater_fog_modifier FLOAT NOT NULL DEFAULT '0.25',
  reflection_wavelet_scale_1 FLOAT NOT NULL DEFAULT '2.0',
  reflection_wavelet_scale_2 FLOAT NOT NULL DEFAULT '2.0',
  reflection_wavelet_scale_3 FLOAT NOT NULL DEFAULT '2.0',
  fresnel_scale FLOAT NOT NULL DEFAULT '0.40',
  fresnel_offset FLOAT NOT NULL DEFAULT '0.50',
  refract_scale_above FLOAT NOT NULL DEFAULT '0.03',
  refract_scale_below FLOAT NOT NULL DEFAULT '0.20',
  blur_multiplier FLOAT NOT NULL DEFAULT '0.040',
  big_wave_direction_x FLOAT NOT NULL DEFAULT '1.05',
  big_wave_direction_y FLOAT NOT NULL DEFAULT '-0.42',
  little_wave_direction_x FLOAT NOT NULL DEFAULT '1.11',
  little_wave_direction_y FLOAT NOT NULL DEFAULT '-1.16',
  normal_map_texture VARCHAR(36) NOT NULL DEFAULT '822ded49-9a6c-f61c-cb89-6df54f42cdf4',
  horizon_r FLOAT NOT NULL DEFAULT '0.25',
  horizon_g FLOAT NOT NULL DEFAULT '0.25',
  horizon_b FLOAT NOT NULL DEFAULT '0.32',
  horizon_i FLOAT NOT NULL DEFAULT '0.32',
  haze_horizon FLOAT NOT NULL DEFAULT '0.19',
  blue_density_r FLOAT NOT NULL DEFAULT '0.12',
  blue_density_g FLOAT NOT NULL DEFAULT '0.22',
  blue_density_b FLOAT NOT NULL DEFAULT '0.38',
  blue_density_i FLOAT NOT NULL DEFAULT '0.38',
  haze_density FLOAT NOT NULL DEFAULT '0.70',
  density_multiplier FLOAT NOT NULL DEFAULT '0.18',
  distance_multiplier FLOAT NOT NULL DEFAULT '0.8',
  max_altitude INTEGER NOT NULL DEFAULT '1605',
  sun_moon_color_r FLOAT NOT NULL DEFAULT '0.24',
  sun_moon_color_g FLOAT NOT NULL DEFAULT '0.26',
  sun_moon_color_b FLOAT NOT NULL DEFAULT '0.30',
  sun_moon_color_i FLOAT NOT NULL DEFAULT '0.30',
  sun_moon_position FLOAT NOT NULL DEFAULT '0.317',
  ambient_r FLOAT NOT NULL DEFAULT '0.35',
  ambient_g FLOAT NOT NULL DEFAULT '0.35',
  ambient_b FLOAT NOT NULL DEFAULT '0.35',
  ambient_i FLOAT NOT NULL DEFAULT '0.35',
  east_angle FLOAT NOT NULL DEFAULT '0.00',
  sun_glow_focus FLOAT NOT NULL DEFAULT '0.10',
  sun_glow_size FLOAT NOT NULL DEFAULT '1.75',
  scene_gamma FLOAT NOT NULL DEFAULT '1.00',
  star_brightness FLOAT NOT NULL DEFAULT '0.00',
  cloud_color_r FLOAT NOT NULL DEFAULT '0.41',
  cloud_color_g FLOAT NOT NULL DEFAULT '0.41',
  cloud_color_b FLOAT NOT NULL DEFAULT '0.41',
  cloud_color_i FLOAT NOT NULL DEFAULT '0.41',
  cloud_x FLOAT NOT NULL DEFAULT '1.00',
  cloud_y FLOAT NOT NULL DEFAULT '0.53',
  cloud_density FLOAT NOT NULL DEFAULT '1.00',
  cloud_coverage FLOAT NOT NULL DEFAULT '0.27',
  cloud_scale FLOAT NOT NULL DEFAULT '0.42',
  cloud_detail_x FLOAT NOT NULL DEFAULT '1.00',
  cloud_detail_y FLOAT NOT NULL DEFAULT '0.53',
  cloud_detail_density FLOAT NOT NULL DEFAULT '0.12',
  cloud_scroll_x FLOAT NOT NULL DEFAULT '0.20',
  cloud_scroll_x_lock INTEGER NOT NULL DEFAULT '0',
  cloud_scroll_y FLOAT NOT NULL DEFAULT '0.01',
  cloud_scroll_y_lock INTEGER NOT NULL DEFAULT '0',
  draw_classic_clouds INTEGER NOT NULL DEFAULT '1');

CREATE TABLE IF NOT EXISTS `spawn_points` (
  `RegionID` varchar(36) NOT NULL DEFAULT '000000-0000-0000-0000-000000000000',
  `Yaw` float NOT NULL,
  `Pitch` float NOT NULL,
  `Distance` float NOT NULL
);

CREATE TABLE IF NOT EXISTS `regionenvironment` (
  `region_id` varchar(36) NOT NULL DEFAULT '000000-0000-0000-0000-000000000000' PRIMARY KEY,
  `llsd_settings` TEXT NOT NULL
);

COMMIT;


:VERSION 32         #---- avination fields plus a few others

BEGIN;

ALTER TABLE `prims` ADD COLUMN `PassTouches` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `prims` ADD COLUMN `PassCollisions`BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `prims` ADD COLUMN `Vehicle` TEXT default NULL;
ALTER TABLE `regionsettings` ADD COLUMN `block_search` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `regionsettings` ADD COLUMN `casino` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `land` ADD COLUMN `SeeAVs` BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE `land` ADD COLUMN `AnyAVSounds` BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE `land` ADD COLUMN `GroupAVSounds` BOOLEAN NOT NULL DEFAULT TRUE;

COMMIT;

:VERSION 33         #---- Rotation axis locks

BEGIN;

ALTER TABLE prims ADD COLUMN `RotationAxisLocks` tinyint(4) NOT NULL default '0';

COMMIT;

:VERSION 34         #---- add baked terrain store

BEGIN;

CREATE TABLE IF NOT EXISTS bakedterrain(
       RegionUUID varchar(255),
       Revision integer,
       Heightfield blob);

COMMIT;

:VERSION 35         #----- Add RezzerID field in table prims

BEGIN;

ALTER TABLE `prims` ADD COLUMN `RezzerID` char(36) DEFAULT NULL;

COMMIT;

:VERSION 36         #----- Add physics inertia data

BEGIN;
ALTER TABLE `prims` ADD COLUMN `PhysInertia` TEXT default NULL;
COMMIT;

:VERSION 37         #----- Add standtarget and sit range

BEGIN;
ALTER TABLE `prims` ADD COLUMN `standtargetx` float NOT NULL DEFAULT '0.0';
ALTER TABLE `prims` ADD COLUMN `standtargety` float NOT NULL DEFAULT '0.0';
ALTER TABLE `prims` ADD COLUMN `standtargetz` float NOT NULL DEFAULT '0.0';
ALTER TABLE `prims` ADD COLUMN `sitactrange` float NOT NULL DEFAULT '0.0';
COMMIT;


:VERSION 38         #----- Add pseudo CRC and region cache id

BEGIN;
ALTER TABLE `prims` ADD COLUMN `pseudocrc` integer DEFAULT '0';
ALTER TABLE `regionsettings` ADD COLUMN `cacheID` char(36) DEFAULT NULL;
COMMIT;

:VERSION 39         #----- parcel environment store
BEGIN;
ALTER TABLE `land` ADD COLUMN `environment` TEXT default NULL;
COMMIT;

:VERSION 40         #----- sop animations and materials
BEGIN;
ALTER TABLE `prims` ADD COLUMN `sopanims` blob default NULL;
ALTER TABLE `primshapes` ADD COLUMN `MatOvrd` blob default NULL;
COMMIT;

:VERSION 41         #----- add linkset data binary storage column
BEGIN;
ALTER TABLE `prims` ADD COLUMN `lnkstBinData` blob default NULL;
COMMIT;


:VERSION 42         #----- add pbr terrain storage
BEGIN;
ALTER TABLE regionsettings ADD COLUMN TerrainPBR1 char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
ALTER TABLE regionsettings ADD COLUMN TerrainPBR2 char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
ALTER TABLE regionsettings ADD COLUMN TerrainPBR3 char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
ALTER TABLE regionsettings ADD COLUMN TerrainPBR4 char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
COMMIT;

:VERSION 43         #----- add rez start string param column
BEGIN;
ALTER TABLE `prims` ADD COLUMN `StartStr` TEXT;
COMMIT;
