-- One-off migration: adds the admin_dashboard_widgets table, used to store
-- each admin's personal dashboard layout (which stat widgets are visible,
-- in what order, and at what size). Run once against the app database:
--
--   mysql -h <host> -u <user> -p <database> < scripts/create_admin_dashboard_widgets_table.sql
--
-- (or paste the statement below into phpMyAdmin / Adminer / your MySQL
-- client of choice). No existing tables are modified.

CREATE TABLE IF NOT EXISTS admin_dashboard_widgets (
    id          INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    user_id     BIGINT UNSIGNED NOT NULL,
    widget_key  VARCHAR(64) NOT NULL,
    position    INT NOT NULL DEFAULT 0,
    visible     TINYINT(1) NOT NULL DEFAULT 1,
    size        VARCHAR(8) NOT NULL DEFAULT 'md',
    UNIQUE KEY uniq_admin_dashboard_widgets_user_widget (user_id, widget_key),
    CONSTRAINT fk_admin_dashboard_widgets_user
        FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
