:VERSION 10

BEGIN TRANSACTION;

CREATE TABLE IF NOT EXISTS estate_groups (
  EstateID int(10) NOT NULL,
  uuid char(36) NOT NULL
);
CREATE INDEX estate_groups_estate_id on estate_groups(EstateID);

CREATE TABLE IF NOT EXISTS estate_managers (
  EstateID int(10) NOT NULL,
  uuid char(36) NOT NULL
);
CREATE INDEX estate_managers_estate_id on estate_managers(EstateID);

CREATE TABLE IF NOT EXISTS estate_map (
  RegionID char(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
  EstateID int(11) NOT NULL
);
CREATE INDEX estate_map_estate_id on estate_map(EstateID);
CREATE UNIQUE INDEX estate_map_region_id on estate_map(RegionID);

CREATE TABLE IF NOT EXISTS estate_settings (
  EstateID INTEGER NOT NULL PRIMARY KEY,
  EstateName varchar(64) default NULL,
  AbuseEmailToEstateOwner tinyint(4) NOT NULL,
  DenyAnonymous tinyint(4) NOT NULL,
  ResetHomeOnTeleport tinyint(4) NOT NULL,
  FixedSun tinyint(4) NOT NULL,
  DenyTransacted tinyint(4) NOT NULL,
  BlockDwell tinyint(4) NOT NULL,
  DenyIdentified tinyint(4) NOT NULL,
  AllowVoice tinyint(4) NOT NULL,
  UseGlobalTime tinyint(4) NOT NULL,
  PricePerMeter int(11) NOT NULL,
  TaxFree tinyint(4) NOT NULL,
  AllowDirectTeleport tinyint(4) NOT NULL,
  RedirectGridX int(11) NOT NULL,
  RedirectGridY int(11) NOT NULL,
  ParentEstateID int(10) NOT NULL,
  SunPosition double NOT NULL,
  EstateSkipScripts tinyint(4) NOT NULL,
  BillableFactor float NOT NULL,
  PublicAccess tinyint(4) NOT NULL, 
  AbuseEmail varchar(255) not null default '', 
  EstateOwner varchar(36) not null default '', 
  DenyMinors tinyint not null default 0, 
  AllowLandmark tinyint not null default '1', 
  AllowParcelChanges tinyint not null default '1', 
  AllowSetHome tinyint not null default '1');

CREATE TABLE IF NOT EXISTS estate_users (
  EstateID int(10) NOT NULL,
  uuid char(36) NOT NULL
);
CREATE INDEX estate_users_estate_id on estate_users(EstateID);

CREATE TABLE IF NOT EXISTS estateban (
  EstateID int(10) NOT NULL,
  bannedUUID varchar(36) NOT NULL,
  bannedIp varchar(16) NOT NULL,
  bannedIpHostMask varchar(16) NOT NULL,
  bannedNameMask varchar(64) default NULL
);

CREATE INDEX estate_ban_estate_id on estateban(EstateID);

COMMIT;

:VERSION 11
BEGIN;
ALTER TABLE `estateban` ADD COLUMN `banningUUID` varchar(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
ALTER TABLE `estateban` ADD COLUMN `banTime` integer NOT NULL DEFAULT 0;
COMMIT;

:VERSION 12
BEGIN;
ALTER TABLE `estate_settings`
    ADD COLUMN `AllowEnviromentOverride` tinyint not null default 0;
COMMIT;


