ALTER TABLE `users`
  ADD COLUMN `account_type` VARCHAR(24) NOT NULL DEFAULT 'personal' AFTER `role`,
  ADD COLUMN `interests_json` TEXT NULL AFTER `account_type`,
  ADD COLUMN `newsletter_opt_in` TINYINT(1) NOT NULL DEFAULT 0 AFTER `interests_json`,
  ADD COLUMN `newsletter_consented_at` VARCHAR(40) NULL AFTER `newsletter_opt_in`,
  ADD KEY `users_account_type_index` (`account_type`),
  ADD KEY `users_newsletter_index` (`newsletter_opt_in`);

CREATE TABLE `establishments` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` BIGINT UNSIGNED NOT NULL,
  `name` VARCHAR(180) NOT NULL,
  `description` TEXT NULL,
  `address` VARCHAR(255) NULL,
  `postal_code` VARCHAR(12) NULL,
  `city` VARCHAR(120) NULL,
  `phone` VARCHAR(40) NULL,
  `website` VARCHAR(2048) NULL,
  `status` VARCHAR(24) NOT NULL DEFAULT 'draft',
  `created_at` VARCHAR(40) NOT NULL,
  `updated_at` VARCHAR(40) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `establishments_user_unique` (`user_id`),
  KEY `establishments_status_index` (`status`),
  KEY `establishments_city_index` (`city`),
  CONSTRAINT `establishments_user_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
