ALTER TABLE
    `players`
ADD
    IF NOT EXISTS `inside` VARCHAR(50) NULL DEFAULT '';

CREATE TABLE IF NOT EXISTS `houselocations` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'latin1_swedish_ci',
	`label` VARCHAR(255) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`coords` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`owned` TINYINT(2) NULL DEFAULT NULL,
	`price` INT(11) NULL DEFAULT NULL,
	`defaultPrice` INT(11) NULL DEFAULT NULL,
	`tier` TINYINT(2) NULL DEFAULT NULL,
	`garage` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`garageShell` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`creator` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`mlo` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`ipl` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`console` INT(11) NULL DEFAULT NULL,
	`board` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`for_sale` INT(11) NULL DEFAULT '1',
	`extra_imgs` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`description` TEXT NOT NULL DEFAULT '' COLLATE 'latin1_swedish_ci',
	`creatorJob` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`blip` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`upgrades` TEXT NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`apartmentCount` INT(11) NULL DEFAULT NULL,
	PRIMARY KEY (`name`) USING BTREE,
	INDEX `name` (`name`) USING BTREE,
	INDEX `id` (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;

CREATE TABLE IF NOT EXISTS `player_houses` (
	`id` INT(255) NOT NULL AUTO_INCREMENT,
	`house` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`citizenid` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`owner` VARCHAR(46) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`keyholders` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`stash` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`outfit` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`logout` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`decorateStash` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`charge` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`credit` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`creditPrice` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`console` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`decorateCoords` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`rented` INT(11) NULL DEFAULT NULL,
	`rentPrice` INT(11) NULL DEFAULT NULL,
	`rentable` INT(11) NULL DEFAULT NULL,
	`purchasable` INT(11) NULL DEFAULT NULL,
	`vaultCodes` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `house` (`house`) USING BTREE,
	INDEX `owner` (`owner`) USING BTREE,
	INDEX `citizenid` (`citizenid`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=3
;



CREATE TABLE IF NOT EXISTS `house_rents` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`house` VARCHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
	`identifier` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
	`payed` INT(11) NOT NULL DEFAULT '0',
	`date` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
	PRIMARY KEY (`id`) USING BTREE
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB AUTO_INCREMENT = 1;

CREATE TABLE IF NOT EXISTS `house_objects` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`creator` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'latin1_swedish_ci',
	`model` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'latin1_swedish_ci',
	`coords` TEXT NOT NULL COLLATE 'latin1_swedish_ci',
	`house` VARCHAR(80) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`construction` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
	`created` TIMESTAMP NULL DEFAULT current_timestamp(),
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;


ALTER TABLE `house_objects`
	ADD IF NOT EXISTS `construction` VARCHAR(50) NULL DEFAULT NULL,
	ADD IF NOT EXISTS `created` TIMESTAMP NULL DEFAULT current_timestamp()
;

CREATE TABLE IF NOT EXISTS `house_plants` (
	`id` int(11) NOT NULL AUTO_INCREMENT,
	`building` varchar(50) DEFAULT NULL,
	`stage` varchar(50) DEFAULT 'stage-a',
	`sort` varchar(50) DEFAULT NULL,
	`gender` varchar(50) DEFAULT NULL,
	`food` int(11) DEFAULT 100,
	`health` int(11) DEFAULT 100,
	`progress` int(11) DEFAULT 0,
	`coords` text DEFAULT NULL,
	`plantid` varchar(50) DEFAULT NULL,
	PRIMARY KEY (`id`),
	KEY `building` (`building`),
	KEY `plantid` (`plantid`)
) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `house_meta_keys` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`house` VARCHAR(255) NOT NULL,
	`key_id` VARCHAR(255) NOT NULL,
	`owner_identifier` VARCHAR(255) NOT NULL,
	`created_at` TIMESTAMP NULL DEFAULT current_timestamp(),
	PRIMARY KEY (`id`) USING BTREE,
	UNIQUE INDEX `key_id` (`key_id`) USING BTREE,
	INDEX `idx_house` (`house`) USING BTREE,
	INDEX `idx_key_id` (`key_id`) USING BTREE
)
COLLATE='utf8mb3_general_ci'
ENGINE=InnoDB
;

CREATE TABLE IF NOT EXISTS `house_junk` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`house` VARCHAR(255) NOT NULL,
	`model` VARCHAR(255) NOT NULL,
	`coords` LONGTEXT NULL DEFAULT NULL,
	`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP(),
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `idx_house` (`house`) USING BTREE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;

ALTER TABLE `player_houses`
    CHANGE COLUMN IF EXISTS `identifier`  `owner` VARCHAR(46) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci';

ALTER TABLE `houselocations`
	ADD IF NOT EXISTS `blip` TEXT NULL DEFAULT NULL,
	ADD IF NOT EXISTS `upgrades` TEXT NULL DEFAULT NULL,
	ADD IF NOT EXISTS `apartmentCount` TEXT NULL DEFAULT NULL,
	ADD IF NOT EXISTS `creatorGotMoney` TINYINT(1) NOT NULL DEFAULT '0',
	ADD IF NOT EXISTS `permissions` LONGTEXT NULL DEFAULT NULL,
	ADD IF NOT EXISTS `paymentMethod` VARCHAR(50) NULL DEFAULT NULL,
	ADD IF NOT EXISTS `photos` TEXT NULL DEFAULT NULL
;

ALTER TABLE `houselocations` ADD COLUMN IF NOT EXISTS `doorbellSound` VARCHAR(50) DEFAULT NULL AFTER `paymentMethod`;

ALTER TABLE `player_houses`
	ADD IF NOT EXISTS `rented` INT(11) NULL DEFAULT NULL,
	ADD IF NOT EXISTS `rentPrice` INT(11) NULL DEFAULT NULL,
	ADD IF NOT EXISTS `rentable` INT(11) NULL DEFAULT NULL,
	ADD IF NOT EXISTS `purchasable` INT(11) NULL DEFAULT NULL,
	ADD IF NOT EXISTS `console` TEXT NULL DEFAULT NULL,
	ADD IF NOT EXISTS `decorateCoords` TEXT NULL DEFAULT NULL,
	ADD IF NOT EXISTS `vaultCodes` TEXT NULL DEFAULT NULL
;

ALTER TABLE `houselocations`
	DROP IF EXISTS `houseID`
;
	

ALTER TABLE `player_houses`
	DROP IF EXISTS `houseID`,
	DROP IF EXISTS `timer`,
	DROP IF EXISTS `insideId`
;

ALTER TABLE `houselocations`
	CHANGE COLUMN `tier` `tier` SMALLINT NULL DEFAULT NULL;
	
CREATE TABLE IF NOT EXISTS `house_decorations` (
	`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`house` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
	`creator` VARCHAR(70) NOT NULL DEFAULT '0' COLLATE 'utf8mb3_general_ci',
	`modelName` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb3_general_ci',
	`coords` TEXT NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
	`rotation` TEXT NOT NULL DEFAULT '' COLLATE 'utf8mb3_general_ci',
	`inStash` TINYINT(1) NOT NULL DEFAULT '0',
	`inHouse` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
	`uniq` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
	`created` TIMESTAMP NULL DEFAULT NULL,
	`lightData` TEXT NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `id` (`id`, `house`) USING BTREE
)
COLLATE='utf8mb3_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;

CREATE TABLE IF NOT EXISTS `house_bills` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `house` VARCHAR(100) NOT NULL,
  `payed_by` VARCHAR(80) NULL DEFAULT NULL,
  `total` INT NOT NULL,
  `breakdown` LONGTEXT NOT NULL,
  `payed` TINYINT(1) NOT NULL DEFAULT 0,
  `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  INDEX `idx_house_payed_by` (`house`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


CREATE TABLE IF NOT EXISTS `house_stolen_furniture` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `identifier` varchar(50) NOT NULL,
  `house` varchar(50) NOT NULL,
  `model_name` varchar(100) NOT NULL,
  `stolen_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `identifier` (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `qs_housing_furnitures` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`creator` VARCHAR(80) NULL DEFAULT NULL,
	`category_key` VARCHAR(100) NOT NULL,
	`object` VARCHAR(200) NOT NULL,
	`label` VARCHAR(255) NOT NULL,
	`description` TEXT NULL DEFAULT NULL,
	`price` INT(11) NOT NULL DEFAULT '0',
	`img` TEXT NULL DEFAULT NULL,
	`colorlabel` VARCHAR(255) NULL DEFAULT NULL,
	`type` VARCHAR(50) NULL DEFAULT NULL,
	`stash` LONGTEXT NULL DEFAULT NULL,
	`offset` LONGTEXT NULL DEFAULT NULL,
	`colors` LONGTEXT NULL DEFAULT NULL,
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `creator` (`creator`) USING BTREE,
	INDEX `category_key` (`category_key`) USING BTREE
)COLLATE='utf8mb4_unicode_ci' ENGINE=InnoDB;

ALTER TABLE `player_houses` ADD COLUMN IF NOT EXISTS `lights_on` TINYINT(1) DEFAULT 0;
ALTER TABLE `player_houses` ADD COLUMN IF NOT EXISTS `lights_on_since` BIGINT DEFAULT NULL;
ALTER TABLE `player_houses` ADD COLUMN IF NOT EXISTS `sale_furnished` TINYINT(1) DEFAULT NULL;
ALTER TABLE `player_houses` ADD COLUMN IF NOT EXISTS `rent_furnished` TINYINT(1) DEFAULT NULL;
ALTER TABLE `houselocations` ADD COLUMN IF NOT EXISTS `hideFromBrowser` TINYINT(1) DEFAULT 0;

ALTER TABLE `house_decorations` ADD COLUMN IF NOT EXISTS `price` INT(11) DEFAULT NULL;


ALTER TABLE `player_houses` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE `houselocations` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

CREATE TABLE IF NOT EXISTS `qs_housing_furniture_shops` (
	`id` INT AUTO_INCREMENT PRIMARY KEY,
	`name` VARCHAR(100) NOT NULL,
	`enter` LONGTEXT NOT NULL,
	`blip` LONGTEXT DEFAULT NULL,
	`categories` LONGTEXT DEFAULT NULL,
	`creator` VARCHAR(100) NOT NULL,
	`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
	`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;