switched to fully self contained docker

This commit is contained in:
2026-07-26 14:01:20 -05:00
parent 0ed0fb5817
commit 5d2f90ce24
34 changed files with 688 additions and 672 deletions
+111 -89
View File
@@ -1,103 +1,125 @@
CREATE TABLE IF NOT EXISTS schema_migrations (
version BIGINT UNSIGNED NOT NULL PRIMARY KEY,
applied_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)
) ENGINE=InnoDB;
CREATE TABLE technician_sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
token_hash BLOB NOT NULL UNIQUE,
csrf_token TEXT NOT NULL,
gitea_login TEXT NOT NULL,
display_name TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NOT NULL,
last_seen_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_technician_sessions_expires
ON technician_sessions(expires_at);
CREATE TABLE IF NOT EXISTS technician_sessions (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
token_hash BINARY(32) NOT NULL UNIQUE,
csrf_token VARCHAR(64) NOT NULL,
gitea_login VARCHAR(255) NOT NULL,
display_name VARCHAR(255) NOT NULL,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
expires_at TIMESTAMP(6) NOT NULL,
last_seen_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
INDEX idx_technician_sessions_expires (expires_at)
) ENGINE=InnoDB;
CREATE TABLE packages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE,
display_name TEXT NOT NULL,
package_name TEXT NOT NULL,
package_version TEXT NOT NULL,
file_name TEXT NOT NULL,
sha256 TEXT NOT NULL,
enabled INTEGER NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS packages (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
slug VARCHAR(100) NOT NULL UNIQUE,
display_name VARCHAR(255) NOT NULL,
package_name VARCHAR(255) NOT NULL,
package_version VARCHAR(100) NOT NULL,
file_name VARCHAR(255) NOT NULL,
sha256 CHAR(64) NOT NULL,
enabled BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)
ON UPDATE CURRENT_TIMESTAMP(6)
) ENGINE=InnoDB;
CREATE TABLE authorizations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code_hash BLOB NOT NULL UNIQUE,
code_hint TEXT NOT NULL,
created_by TEXT NOT NULL,
customer_label TEXT NOT NULL DEFAULT '',
host_limit INTEGER NOT NULL CHECK (host_limit > 0),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NOT NULL,
revoked_at DATETIME
);
CREATE INDEX idx_authorizations_expires ON authorizations(expires_at);
CREATE INDEX idx_authorizations_created_by
ON authorizations(created_by, created_at);
CREATE TABLE IF NOT EXISTS authorizations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
code_hash BINARY(32) NOT NULL UNIQUE,
code_hint VARCHAR(8) NOT NULL,
created_by VARCHAR(255) NOT NULL,
customer_label VARCHAR(255) NOT NULL DEFAULT '',
host_limit INT UNSIGNED NOT NULL,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
expires_at TIMESTAMP(6) NOT NULL,
revoked_at TIMESTAMP(6) NULL,
INDEX idx_authorizations_expires (expires_at),
INDEX idx_authorizations_created_by (created_by, created_at)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS authorization_packages (
authorization_id BIGINT UNSIGNED NOT NULL,
package_id BIGINT UNSIGNED NOT NULL,
CREATE TABLE authorization_packages (
authorization_id INTEGER NOT NULL,
package_id INTEGER NOT NULL,
package_slug TEXT NOT NULL,
display_name TEXT NOT NULL,
package_name TEXT NOT NULL,
package_version TEXT NOT NULL,
file_name TEXT NOT NULL,
sha256 TEXT NOT NULL,
PRIMARY KEY (authorization_id, package_id),
CONSTRAINT fk_authorization_packages_authorization
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
ON DELETE CASCADE,
CONSTRAINT fk_authorization_packages_package
FOREIGN KEY (package_id) REFERENCES packages(id)
FOREIGN KEY (package_id) REFERENCES packages(id)
ON DELETE RESTRICT
) ENGINE=InnoDB;
);
CREATE TABLE IF NOT EXISTS authorization_hosts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
authorization_id BIGINT UNSIGNED NOT NULL,
host_fingerprint BINARY(32) NOT NULL,
hostname VARCHAR(255) NOT NULL,
first_seen_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
last_seen_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
UNIQUE KEY uq_authorization_host (authorization_id, host_fingerprint),
CONSTRAINT fk_authorization_hosts_authorization
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
CREATE TABLE authorization_hosts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
authorization_id INTEGER NOT NULL,
host_fingerprint BLOB NOT NULL,
hostname TEXT NOT NULL,
first_seen_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_seen_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (authorization_id, host_fingerprint),
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
ON DELETE CASCADE
) ENGINE=InnoDB;
);
CREATE TABLE IF NOT EXISTS download_sessions (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
token_hash BINARY(32) NOT NULL UNIQUE,
authorization_id BIGINT UNSIGNED NOT NULL,
authorization_host_id BIGINT UNSIGNED NOT NULL,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
expires_at TIMESTAMP(6) NOT NULL,
revoked_at TIMESTAMP(6) NULL,
INDEX idx_download_sessions_expires (expires_at),
CONSTRAINT fk_download_sessions_authorization
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
CREATE TABLE download_sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
token_hash BLOB NOT NULL UNIQUE,
authorization_id INTEGER NOT NULL,
authorization_host_id INTEGER NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NOT NULL,
revoked_at DATETIME,
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
ON DELETE CASCADE,
CONSTRAINT fk_download_sessions_host
FOREIGN KEY (authorization_host_id) REFERENCES authorization_hosts(id)
FOREIGN KEY (authorization_host_id) REFERENCES authorization_hosts(id)
ON DELETE CASCADE
) ENGINE=InnoDB;
);
CREATE INDEX idx_download_sessions_expires ON download_sessions(expires_at);
CREATE TABLE IF NOT EXISTS audit_events (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
event_type VARCHAR(100) NOT NULL,
actor VARCHAR(255) NOT NULL DEFAULT '',
authorization_id BIGINT UNSIGNED NULL,
hostname VARCHAR(255) NOT NULL DEFAULT '',
package_slug VARCHAR(100) NOT NULL DEFAULT '',
source_ip VARCHAR(64) NOT NULL DEFAULT '',
CREATE TABLE audit_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
event_type TEXT NOT NULL,
actor TEXT NOT NULL DEFAULT '',
authorization_id INTEGER,
hostname TEXT NOT NULL DEFAULT '',
package_slug TEXT NOT NULL DEFAULT '',
source_ip TEXT NOT NULL DEFAULT '',
details TEXT NOT NULL,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
INDEX idx_audit_created (created_at),
INDEX idx_audit_authorization (authorization_id, created_at),
INDEX idx_audit_exchange_limit (event_type, source_ip, created_at)
) ENGINE=InnoDB;
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_audit_created ON audit_events(created_at);
CREATE INDEX idx_audit_authorization
ON audit_events(authorization_id, created_at);
CREATE INDEX idx_audit_exchange_limit
ON audit_events(event_type, source_ip, created_at);
INSERT IGNORE INTO schema_migrations (version) VALUES (1);
CREATE TABLE installer_actions (
slug TEXT NOT NULL PRIMARY KEY,
display_name TEXT NOT NULL,
sort_order INTEGER NOT NULL DEFAULT 0,
enabled INTEGER NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE authorization_actions (
authorization_id INTEGER NOT NULL,
action_slug TEXT NOT NULL,
PRIMARY KEY (authorization_id, action_slug),
FOREIGN KEY (authorization_id) REFERENCES authorizations(id)
ON DELETE CASCADE,
FOREIGN KEY (action_slug) REFERENCES installer_actions(slug)
ON DELETE RESTRICT
);
INSERT INTO installer_actions (slug, display_name, sort_order, enabled)
VALUES
('install-rmm', 'Install ConnectWise RMM agent', 10, 1),
('install-acronis', 'Install Acronis agent', 20, 1),
('install-screenconnect', 'Install ScreenConnect agent', 30, 1);