Files
gochat/backend/migrations/000004_add_saml_config_tables.up.sql
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00

43 lines
1.6 KiB
SQL

-- GoChat SAML Configuration Tables
-- Reference: P2E §1.6 — SAML SP integration for enterprise SSO
-- Stores SAML IdP metadata, SP configuration, and attribute mapping
-- SAML Configurations (per-account SAML settings)
CREATE TABLE IF NOT EXISTS saml_configs (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL UNIQUE,
enabled BOOLEAN DEFAULT FALSE,
idp_metadata_url VARCHAR(1024),
idp_metadata_xml TEXT,
sp_entity_id VARCHAR(255) NOT NULL,
acs_url VARCHAR(1024) NOT NULL,
sp_private_key TEXT,
sp_certificate TEXT,
clock_drift_tolerance INTEGER DEFAULT 180,
attribute_map JSONB DEFAULT '{}',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
deleted_at TIMESTAMP WITH TIME ZONE
);
CREATE INDEX idx_saml_configs_deleted_at ON saml_configs(deleted_at);
CREATE INDEX idx_saml_configs_account_id ON saml_configs(account_id) WHERE deleted_at IS NULL;
-- SAML Sessions (tracks SAML-initiated auth sessions)
CREATE TABLE IF NOT EXISTS saml_sessions (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL,
user_id INTEGER,
request_id VARCHAR(255) NOT NULL UNIQUE,
name_id VARCHAR(255),
session_index VARCHAR(255),
sso_url VARCHAR(1024),
slo_url VARCHAR(1024),
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE INDEX idx_saml_sessions_request_id ON saml_sessions(request_id);
CREATE INDEX idx_saml_sessions_expires_at ON saml_sessions(expires_at);
CREATE INDEX idx_saml_sessions_account_id ON saml_sessions(account_id);