Files
gochat/backend/migrations/000016_add_channel_twitter_microsoft_google.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

81 lines
3.7 KiB
SQL

-- Channel: Twitter/X (G10)
-- Twitter Account Activity API uses OAuth 2.0 with PKCE for user authentication.
-- Webhook CRC (Challenge-Response Check) for webhook validation.
-- Reference: Chatwoot app/models/channel/twitter_profile.rb
CREATE TABLE IF NOT EXISTS channel_twitters (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL,
inbox_id INTEGER NOT NULL UNIQUE,
twitter_user_id VARCHAR(255) NOT NULL,
name VARCHAR(255),
screen_name VARCHAR(255),
profile_image_url VARCHAR(512),
access_token VARCHAR(1024) NOT NULL,
refresh_token VARCHAR(1024),
twitter_access_token VARCHAR(512),
twitter_access_token_secret VARCHAR(512),
webhook_id VARCHAR(255),
webhook_env VARCHAR(255),
reauthorization_required BOOLEAN DEFAULT FALSE,
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_channel_twitters_deleted_at ON channel_twitters(deleted_at);
CREATE INDEX idx_channel_twitters_account_id ON channel_twitters(account_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_twitters_inbox_id ON channel_twitters(inbox_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_twitters_twitter_user_id ON channel_twitters(twitter_user_id) WHERE deleted_at IS NULL;
-- Channel: Microsoft/Azure AD (G10)
-- Microsoft Graph API uses OAuth 2.0 with Azure AD for enterprise authentication.
-- Webhook subscriptions for real-time event processing.
-- This is a gochat addition — no Chatwoot reference exists.
CREATE TABLE IF NOT EXISTS channel_microsofts (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL,
inbox_id INTEGER NOT NULL UNIQUE,
tenant_id VARCHAR(255) NOT NULL,
client_id VARCHAR(255) NOT NULL,
access_token VARCHAR(2048) NOT NULL,
refresh_token VARCHAR(2048),
team_id VARCHAR(255),
channel_id VARCHAR(255),
display_name VARCHAR(255),
subscription_id VARCHAR(255),
reauthorization_required BOOLEAN DEFAULT FALSE,
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_channel_microsofts_deleted_at ON channel_microsofts(deleted_at);
CREATE INDEX idx_channel_microsofts_account_id ON channel_microsofts(account_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_microsofts_inbox_id ON channel_microsofts(inbox_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_microsofts_tenant_id ON channel_microsofts(tenant_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_microsofts_client_id ON channel_microsofts(client_id) WHERE deleted_at IS NULL;
-- Channel: Google/Google Chat (G10)
-- Google Chat API uses OAuth 2.0 for authentication.
-- This is a gochat addition — no Chatwoot reference exists.
CREATE TABLE IF NOT EXISTS channel_googles (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL,
inbox_id INTEGER NOT NULL UNIQUE,
google_user_id VARCHAR(255) NOT NULL,
access_token VARCHAR(2048) NOT NULL,
refresh_token VARCHAR(2048),
space_id VARCHAR(255),
display_name VARCHAR(255),
subscription_id VARCHAR(255),
reauthorization_required BOOLEAN DEFAULT FALSE,
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_channel_googles_deleted_at ON channel_googles(deleted_at);
CREATE INDEX idx_channel_googles_account_id ON channel_googles(account_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_googles_inbox_id ON channel_googles(inbox_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_googles_google_user_id ON channel_googles(google_user_id) WHERE deleted_at IS NULL;