diff --git a/sim/cluster0/lab-seeds/backend/sql/migrations/080_sfu_rooms.sql b/sim/cluster0/lab-seeds/backend/sql/migrations/080_sfu_rooms.sql new file mode 100644 index 0000000..ac19b1c --- /dev/null +++ b/sim/cluster0/lab-seeds/backend/sql/migrations/080_sfu_rooms.sql @@ -0,0 +1,38 @@ +-- SFU room management schema — MariaDB / SQLite default +-- Created: 2026-06-28 + +CREATE TABLE IF NOT EXISTS sfu_rooms ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + janus_room_id INT NOT NULL UNIQUE, + owner_id BIGINT UNSIGNED NOT NULL, + name VARCHAR(128) NOT NULL DEFAULT '', + purpose VARCHAR(32) NOT NULL DEFAULT 'screen_cast', + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + closed_at DATETIME NULL, + INDEX idx_sfu_rooms_owner (owner_id), + INDEX idx_sfu_rooms_closed (closed_at) +); + +CREATE TABLE IF NOT EXISTS sfu_participants ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + room_id BIGINT UNSIGNED NOT NULL, + user_id BIGINT UNSIGNED NOT NULL, + janus_handle_id BIGINT UNSIGNED NOT NULL, + role VARCHAR(16) NOT NULL DEFAULT 'publisher', + joined_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + left_at DATETIME NULL, + INDEX idx_sfup_room (room_id), + INDEX idx_sfup_user (user_id), + INDEX idx_sfup_joined (joined_at) +); + +CREATE TABLE IF NOT EXISTS sfu_stats ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + participant_id BIGINT UNSIGNED NOT NULL, + bitrate_kbps DECIMAL(10,2) NOT NULL DEFAULT 0, + packet_loss DECIMAL(5,2) NOT NULL DEFAULT 0, + sampled_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX idx_sfustat_participant (participant_id), + INDEX idx_sfustat_time (sampled_at) +); diff --git a/sim/cluster0/scripts/load-schemas.sh b/sim/cluster0/scripts/load-schemas.sh index d6a91e2..dce1963 100644 --- a/sim/cluster0/scripts/load-schemas.sh +++ b/sim/cluster0/scripts/load-schemas.sh @@ -1,7 +1,18 @@ #!/bin/sh # Load project schemas on cast01 primary only. set -eu -SHARED=/shared/cluster/sql +# Lab-seeds SQL is under lab-seeds/backend/sql; fall back to legacy sql/ layout. +if [ -f /shared/cluster/lab-seeds/backend/sql/schema.mariadb.sql ]; then + SQL_BASE=/shared/cluster/lab-seeds/backend/sql + SQL_CRASHES="$SQL_BASE" + SQL_CRASHES_MIGRATIONS="$SQL_BASE/migrations" + SQL_URL_SHORTENER="$SQL_BASE" +else + SQL_BASE=/shared/cluster/sql + SQL_CRASHES="$SQL_BASE/crashes" + SQL_CRASHES_MIGRATIONS="$SQL_BASE/crashes/migrations" + SQL_URL_SHORTENER="$SQL_BASE/url_shortener" +fi [ "$(hostname -s)" = cast01 ] || { echo "run on cast01 only"; exit 1; } apply() { @@ -14,11 +25,12 @@ apply() { apply_db() { db="$1" f="$2" + [ -f "$f" ] || { echo "skip (missing): $f"; return 0; } echo "==> $db < $f" mariadb -u root "$db" < "$f" } -apply "$SHARED/crashes/schema.mariadb.sql" +apply "$SQL_CRASHES/schema.mariadb.sql" # Migrations after base schema (003 is for legacy; base schema already includes tickets) for m in \ @@ -30,10 +42,16 @@ for m in \ 008_auth_email_2fa.sql \ 009_rssh_sessions.sql do - apply_db androidcast_crashes "$SHARED/crashes/migrations/$m" + apply_db androidcast_crashes "$SQL_CRASHES_MIGRATIONS/$m" done -apply "$SHARED/url_shortener/schema.mariadb.sql" +# Apply SFU rooms schema if present +apply_db androidcast_crashes "$SQL_CRASHES_MIGRATIONS/080_sfu_rooms.sql" 2>/dev/null || true + +if [ -f "$SQL_URL_SHORTENER/schema.mariadb.sql" ] && \ + [ "$SQL_URL_SHORTENER/schema.mariadb.sql" != "$SQL_CRASHES/schema.mariadb.sql" ]; then + apply "$SQL_URL_SHORTENER/schema.mariadb.sql" +fi mariadb -u root -e "SHOW DATABASES; SELECT COUNT(*) AS crash_tables FROM information_schema.tables WHERE table_schema='androidcast_crashes'; SELECT COUNT(*) AS url_tables FROM information_schema.tables WHERE table_schema='url_shortener';" echo "schemas_loaded_ok"