CREATE TABLE Prims (
  UUID VARCHAR(36) NOT NULL,
  RegionID VARCHAR(36) DEFAULT NULL,
  GroupID VARCHAR(36) DEFAULT NULL,
  ParentID INT DEFAULT NULL,
  ParentUUID VARCHAR(36) DEFAULT NULL,
  OwnerID VARCHAR(36) DEFAULT NULL,
  LastOwnerID VARCHAR(36) DEFAULT NULL,
  CreatorID VARCHAR(36) DEFAULT NULL,
  CreationDate INT DEFAULT NULL,
  LinkNum INT DEFAULT NULL,
  Name VARCHAR(255) DEFAULT NULL,
  Text VARCHAR(255) DEFAULT NULL,
  Description VARCHAR(255) DEFAULT NULL,
  SitName VARCHAR(255) DEFAULT NULL,
  TouchName VARCHAR(255) DEFAULT NULL,
  ObjectFlags INT DEFAULT NULL,
  OwnerMask INT DEFAULT NULL,
  NextOwnerMask INT DEFAULT NULL,
  GroupMask INT DEFAULT NULL,
  EveryoneMask INT DEFAULT NULL,
  BaseMask INT DEFAULT NULL,
  Material TINYINT DEFAULT NULL,  
  ScriptAccessPin INT DEFAULT NULL,
  TextureAnimation BLOB,
  ParticleSystem BLOB,
  ClickAction TINYINT DEFAULT NULL,  
  Color INT DEFAULT NULL,
  PositionX DOUBLE DEFAULT NULL,
  PositionY DOUBLE DEFAULT NULL,
  PositionZ DOUBLE DEFAULT NULL,
  GroupPositionX DOUBLE DEFAULT NULL,
  GroupPositionY DOUBLE DEFAULT NULL,
  GroupPositionZ DOUBLE DEFAULT NULL,
  VelocityX DOUBLE DEFAULT NULL,
  VelocityY DOUBLE DEFAULT NULL,
  VelocityZ DOUBLE DEFAULT NULL,
  AngularVelocityX DOUBLE DEFAULT NULL,
  AngularVelocityY DOUBLE DEFAULT NULL,
  AngularVelocityZ DOUBLE DEFAULT NULL,
  AccelerationX DOUBLE DEFAULT NULL,
  AccelerationY DOUBLE DEFAULT NULL,
  AccelerationZ DOUBLE DEFAULT NULL,
  RotationX DOUBLE DEFAULT NULL,
  RotationY DOUBLE DEFAULT NULL,
  RotationZ DOUBLE DEFAULT NULL,
  RotationW DOUBLE DEFAULT NULL,
  SitTargetOffsetX DOUBLE DEFAULT NULL,
  SitTargetOffsetY DOUBLE DEFAULT NULL,
  SitTargetOffsetZ DOUBLE DEFAULT NULL,
  SitTargetOrientW DOUBLE DEFAULT NULL,
  SitTargetOrientX DOUBLE DEFAULT NULL,
  SitTargetOrientY DOUBLE DEFAULT NULL,
  SitTargetOrientZ DOUBLE DEFAULT NULL,
  -- this is the shape
  Shape INT DEFAULT NULL,
  ScaleX DOUBLE DEFAULT NULL,
  ScaleY DOUBLE DEFAULT NULL,
  ScaleZ DOUBLE DEFAULT NULL,
  PCode INT DEFAULT NULL,
  PathBegin INT DEFAULT NULL,
  PathEnd INT DEFAULT NULL,
  PathScaleX INT DEFAULT NULL,
  PathScaleY INT DEFAULT NULL,
  PathShearX INT DEFAULT NULL,
  PathShearY INT DEFAULT NULL,
  PathSkew INT DEFAULT NULL,
  PathCurve INT DEFAULT NULL,
  PathRadiusOffset INT DEFAULT NULL,
  PathRevolutions INT DEFAULT NULL,
  PathTaperX INT DEFAULT NULL,
  PathTaperY INT DEFAULT NULL,
  PathTwist INT DEFAULT NULL,
  ProfileBegin INT DEFAULT NULL,
  ProfileEnd INT DEFAULT NULL,
  ProfileCurve INT DEFAULT NULL,
  ProfileHollow INT DEFAULT NULL,
  State INT DEFAULT NULL,
  Texture BLOB,
  ExtraParams BLOB,
  PRIMARY KEY (UUID)
);

CREATE INDEX PrimsRegionIdIndex ON Prims (RegionID);
CREATE INDEX PrimsRegionParentUuidIndex ON Prims (ParentUUID);

CREATE TABLE Terrain (
  RegionID VARCHAR(36) NOT NULL,
  MapData BLOB,
  PRIMARY KEY (RegionID)
);

CREATE TABLE PrimItems (
  ItemID VARCHAR(36) NOT NULL,
  GroupID VARCHAR(36) DEFAULT NULL,
  PrimID VARCHAR(36) DEFAULT NULL,
  ParentFolderID VARCHAR(36) DEFAULT NULL,
  AssetID VARCHAR(36) DEFAULT NULL,
  OwnerID VARCHAR(36) DEFAULT NULL,
  LastOwnerID VARCHAR(36) DEFAULT NULL,
  CreatorID VARCHAR(36) DEFAULT NULL,
  CreationDate BIGINT DEFAULT NULL,
  Type INT DEFAULT NULL,
  InvType INT DEFAULT NULL,
  Name VARCHAR(255) DEFAULT NULL,
  Description VARCHAR(255) DEFAULT NULL,
  NextPermissions INT DEFAULT NULL,
  CurrentPermissions INT DEFAULT NULL,
  BasePermissions INT DEFAULT NULL,
  EveryonePermissions INT DEFAULT NULL,
  GroupPermissions INT DEFAULT NULL,
  Flags INT DEFAULT NULL,
  PRIMARY KEY (ItemID)
);

CREATE INDEX PrimItemsPrimIdIndex ON PrimItems (PrimID);

CREATE TABLE RegionSettings (
  RegionID VARCHAR(36) NOT NULL,
  
  BlockTerraform BIT DEFAULT NULL,
  BlockFly BIT DEFAULT NULL,
  AllowDamage BIT DEFAULT NULL,
  RestrictPushing BIT DEFAULT NULL,
  AllowLandResell BIT DEFAULT NULL,
  AllowLandJoinDivide BIT DEFAULT NULL,
  BlockShowInSearch BIT DEFAULT NULL,
  
  AgentLimit INT DEFAULT NULL,
  ObjectBonus DOUBLE DEFAULT NULL,
  Maturity INT DEFAULT NULL,
  
  DisableScripts BIT DEFAULT NULL,
  DisableCollisions BIT DEFAULT NULL,
  DisablePhysics BIT DEFAULT NULL,

  TerrainTexture1 VARCHAR(36) DEFAULT NULL,
  TerrainTexture2 VARCHAR(36) DEFAULT NULL,
  TerrainTexture3 VARCHAR(36) DEFAULT NULL,
  TerrainTexture4 VARCHAR(36) DEFAULT NULL,

  Elevation1NW DOUBLE DEFAULT NULL,
  Elevation2NW DOUBLE DEFAULT NULL,
  Elevation1NE DOUBLE DEFAULT NULL,
  Elevation2NE DOUBLE DEFAULT NULL,
  Elevation1SE DOUBLE DEFAULT NULL,
  Elevation2SE DOUBLE DEFAULT NULL,
  Elevation1SW DOUBLE DEFAULT NULL,
  Elevation2SW DOUBLE DEFAULT NULL,
  
  WaterHeight DOUBLE DEFAULT NULL,
  TerrainRaiseLimit DOUBLE DEFAULT NULL,
  TerrainLowerLimit DOUBLE DEFAULT NULL,    

  UseEstateSun BIT DEFAULT NULL,
  Sandbox BIT DEFAULT NULL,

  SunVectorX DOUBLE DEFAULT NULL,
  SunVectorY DOUBLE DEFAULT NULL,
  SunVectorZ DOUBLE DEFAULT NULL,
 
  FixedSun BIT DEFAULT NULL, 
  SunPosition DOUBLE DEFAULT NULL, 
 
  Covenant VARCHAR(36) DEFAULT NULL,
   
  PRIMARY KEY  (RegionID)
);
