Add supporting tables initialization in schema bootstrap
- Added `ensureSupportingTables` method to create `departments`, `department_variables`, and `users` tables if they do not exist. - Updated `department_daily_report_complaints_schema_bootstrap` to include supporting tables setup for schema consistency.
This commit is contained in:
@@ -19,6 +19,8 @@ class department_daily_report_complaints_schema_bootstrap
|
||||
|
||||
global $db;
|
||||
|
||||
self::ensureSupportingTables();
|
||||
|
||||
$db->query(
|
||||
"CREATE TABLE IF NOT EXISTS department_daily_report_complaints (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -60,6 +62,66 @@ class department_daily_report_complaints_schema_bootstrap
|
||||
self::$initialized = true;
|
||||
}
|
||||
|
||||
private static function ensureSupportingTables(): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->query(
|
||||
"CREATE TABLE IF NOT EXISTS departments (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT NULL,
|
||||
economic_department_id INT NOT NULL DEFAULT 0,
|
||||
slack_webhook TEXT NULL,
|
||||
dimension INT NOT NULL DEFAULT 0,
|
||||
branding INT NOT NULL DEFAULT 0,
|
||||
visible TINYINT(1) NOT NULL DEFAULT 1,
|
||||
longitude DECIMAL(10,7) NOT NULL DEFAULT 0,
|
||||
latitude DECIMAL(10,7) NOT NULL DEFAULT 0,
|
||||
order_priority INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
|
||||
);
|
||||
|
||||
$db->query(
|
||||
"CREATE TABLE IF NOT EXISTS department_variables (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
department_id INT NOT NULL,
|
||||
variable VARCHAR(191) NOT NULL,
|
||||
value TEXT NULL,
|
||||
created_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
KEY idx_department_variables_department_id (department_id),
|
||||
KEY idx_department_variables_variable (variable)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
|
||||
);
|
||||
|
||||
$db->query(
|
||||
"CREATE TABLE IF NOT EXISTS users (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
customer_number INT NOT NULL,
|
||||
display_name VARCHAR(255) NULL,
|
||||
email VARCHAR(255) NULL,
|
||||
phone_country_code INT NULL,
|
||||
phone BIGINT NULL,
|
||||
password VARCHAR(255) NULL,
|
||||
group_id INT NOT NULL DEFAULT 0,
|
||||
xlvask_customer_id VARCHAR(255) NULL,
|
||||
sms_notifications_enabled TINYINT(1) NOT NULL DEFAULT 0,
|
||||
email_notifications_enabled TINYINT(1) NOT NULL DEFAULT 0,
|
||||
wash_certificate_email VARCHAR(255) NULL,
|
||||
two_factor_enabled TINYINT(1) NOT NULL DEFAULT 0,
|
||||
two_factor_secret VARCHAR(255) NULL,
|
||||
created_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME NULL,
|
||||
KEY idx_users_customer_number (customer_number),
|
||||
KEY idx_users_group_id (group_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
|
||||
);
|
||||
}
|
||||
|
||||
private static function indexExists(string $table, string $index): bool
|
||||
{
|
||||
global $db;
|
||||
|
||||
Reference in New Issue
Block a user