Files
coredns-web-ui/migrations/001_initial.sql
T
bryanpedini 53444bec7a test(ui): avoid a literal em dash in the em dash check
- test(ui): avoid a literal em dash in the em dash check
- fix(cli): accept any positive int64 audit count and share the last active admin rule
- fix(api): limit audit before_id to 2^53-1
- fix(api): audit unmatched api requests, bound every request body and record audit write failures
- fix(ui): recheck the account in the login transaction and require existing zones on zone pages
- fix(api): recheck the acting admin and the stored password hash in change transactions
- fix(db): keep committed outcomes on lock release failure, narrow the records contract and trace sql statements
- fix(db): make the initial migration restartable and verify the application schema
- fix(auth): never move last_seen_at backwards on concurrent session touches
- test(api): cover lock release failure after commit and handler tracing without secrets
- fix(test): redact credentials from mysql setup errors
- fix(audit): retain addressed objects on admin refusals
- test(db): cover migration restarts and records contract ranges in mysql
- test(api): verify account races and audit rollback in mysql
- fix(auth): reject password changes after account deletion
- docs: document unknown api audit entries
- fix(audit): bound failure retries and redact sensitive sql parameters
- fix(test): isolate docker resources and cover image cli commands
- test(auth): expect unauthorized after an account deletion race
- fix(db): verify application column widths and foreign keys
2026-11-19 15:46:12 +01:00

72 lines
2.7 KiB
SQL

-- SPDX-License-Identifier: GPL-2.0-or-later
-- Copyright (C) 2026 Bryan Joshua Pedini
CREATE TABLE IF NOT EXISTS `{prefix}webui_schema` (
`id` TINYINT NOT NULL,
`version` INT NOT NULL,
PRIMARY KEY (`id`),
CHECK (`id` = 1)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `{prefix}webui_users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(64) NOT NULL,
`role` VARCHAR(8) NOT NULL,
`password_hash` VARCHAR(255) NOT NULL,
`created_at` DATETIME(6) NOT NULL,
`updated_at` DATETIME(6) NOT NULL,
`last_login_at` DATETIME(6) NULL,
`deleted_at` DATETIME(6) NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
CHECK (`role` IN ('admin', 'user'))
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `{prefix}webui_sessions` (
`token_hash` BINARY(32) NOT NULL,
`user_id` INT NOT NULL,
`created_at` DATETIME(6) NOT NULL,
`last_seen_at` DATETIME(6) NOT NULL,
`expires_at` DATETIME(6) NOT NULL,
`origin` VARCHAR(45) NOT NULL,
`user_agent` VARCHAR(255) NOT NULL,
PRIMARY KEY (`token_hash`),
KEY `user_id` (`user_id`),
KEY `expires_at` (`expires_at`),
FOREIGN KEY (`user_id`) REFERENCES `{prefix}webui_users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `{prefix}webui_zone_delegations` (
`zone` VARCHAR(255) NOT NULL,
`user_id` INT NOT NULL,
`created_at` DATETIME(6) NOT NULL,
`created_by` INT NOT NULL,
PRIMARY KEY (`zone`, `user_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `{prefix}webui_users` (`id`),
FOREIGN KEY (`created_by`) REFERENCES `{prefix}webui_users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `{prefix}webui_audit` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`time` DATETIME(6) NOT NULL,
`user_id` INT NULL,
`actor` VARCHAR(64) NOT NULL,
`origin` VARCHAR(45) NOT NULL,
`operation` VARCHAR(32) NOT NULL,
`status` SMALLINT NULL,
`error` VARCHAR(255) NULL,
`zone` VARCHAR(255) NULL,
`record_id` INT NULL,
`target_user_id` INT NULL,
`before_value` JSON NULL,
`after_value` JSON NULL,
PRIMARY KEY (`id`),
KEY `time` (`time`),
KEY `zone_time` (`zone`, `time`),
KEY `user_time` (`user_id`, `time`),
KEY `operation_time` (`operation`, `time`),
FOREIGN KEY (`user_id`) REFERENCES `{prefix}webui_users` (`id`),
FOREIGN KEY (`target_user_id`) REFERENCES `{prefix}webui_users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;