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 SMALLINT DEFAULT NULL,  
  ScriptAccessPin INT DEFAULT NULL,
  TextureAnimation BYTEA,
  ParticleSystem BYTEA,
  ClickAction SMALLINT DEFAULT NULL,  
  Color INT DEFAULT NULL,
  PositionX DOUBLE PRECISION DEFAULT NULL,
  PositionY DOUBLE PRECISION DEFAULT NULL,
  PositionZ DOUBLE PRECISION DEFAULT NULL,
  GroupPositionX DOUBLE PRECISION DEFAULT NULL,
  GroupPositionY DOUBLE PRECISION DEFAULT NULL,
  GroupPositionZ DOUBLE PRECISION DEFAULT NULL,
  VelocityX DOUBLE PRECISION DEFAULT NULL,
  VelocityY DOUBLE PRECISION DEFAULT NULL,
  VelocityZ DOUBLE PRECISION DEFAULT NULL,
  AngularVelocityX DOUBLE PRECISION DEFAULT NULL,
  AngularVelocityY DOUBLE PRECISION DEFAULT NULL,
  AngularVelocityZ DOUBLE PRECISION DEFAULT NULL,
  AccelerationX DOUBLE PRECISION DEFAULT NULL,
  AccelerationY DOUBLE PRECISION DEFAULT NULL,
  AccelerationZ DOUBLE PRECISION DEFAULT NULL,
  RotationX DOUBLE PRECISION DEFAULT NULL,
  RotationY DOUBLE PRECISION DEFAULT NULL,
  RotationZ DOUBLE PRECISION DEFAULT NULL,
  RotationW DOUBLE PRECISION DEFAULT NULL,
  SitTargetOffsetX DOUBLE PRECISION DEFAULT NULL,
  SitTargetOffsetY DOUBLE PRECISION DEFAULT NULL,
  SitTargetOffsetZ DOUBLE PRECISION DEFAULT NULL,
  SitTargetOrientW DOUBLE PRECISION DEFAULT NULL,
  SitTargetOrientX DOUBLE PRECISION DEFAULT NULL,
  SitTargetOrientY DOUBLE PRECISION DEFAULT NULL,
  SitTargetOrientZ DOUBLE PRECISION DEFAULT NULL,
  -- this is the shape
  Shape INT DEFAULT NULL,
  ScaleX DOUBLE PRECISION DEFAULT NULL,
  ScaleY DOUBLE PRECISION DEFAULT NULL,
  ScaleZ DOUBLE PRECISION 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 SMALLINT DEFAULT NULL,
  PathCurve INT DEFAULT NULL,
  PathRadiusOffset SMALLINT DEFAULT NULL,
  PathRevolutions INT DEFAULT NULL,
  PathTaperX SMALLINT DEFAULT NULL,
  PathTaperY SMALLINT DEFAULT NULL,
  PathTwist SMALLINT DEFAULT NULL,
  ProfileBegin INT DEFAULT NULL,
  ProfileEnd INT DEFAULT NULL,
  ProfileCurve INT DEFAULT NULL,
  ProfileHollow INT DEFAULT NULL,
  State INT DEFAULT NULL,
  Texture BYTEA,
  ExtraParams BYTEA,
  PRIMARY KEY (UUID)
);

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

CREATE TABLE Terrain (
  RegionID VARCHAR(36) not null,
  MapData BYTEA,
  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 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 BOOLEAN DEFAULT NULL,
  BlockFly BOOLEAN DEFAULT NULL,
  AllowDamage BOOLEAN DEFAULT NULL,
  RestrictPushing BOOLEAN DEFAULT NULL,
  AllowLandResell BOOLEAN DEFAULT NULL,
  AllowLandJoinDivide BOOLEAN DEFAULT NULL,
  BlockShowInSearch BOOLEAN DEFAULT NULL,
  
  AgentLimit INT DEFAULT NULL,
  ObjectBonus DOUBLE PRECISION DEFAULT NULL,
  Maturity INT DEFAULT NULL,
  
  DisableScripts BOOLEAN DEFAULT NULL,
  DisableCollisions BOOLEAN DEFAULT NULL,
  DisablePhysics BOOLEAN DEFAULT NULL,

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

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

  UseEstateSun BOOLEAN DEFAULT NULL,
  Sandbox BOOLEAN DEFAULT NULL,

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

