feat: add java control plane container baseline
This commit is contained in:
1 parent
2897354dd8
commit
1615401185
18 files changed
+566
No files matched your search
@@ -0,0 +1,17 @@
|
||||
package com.moyi.controlplane;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HealthController {
|
||||
@GetMapping("/health")
|
||||
public Map<String, Object> health() {
|
||||
return Map.of(
|
||||
"status", "ok",
|
||||
"service", "moyi-control-plane-java",
|
||||
"migration", "bootstrap"
|
||||
);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.moyi.controlplane;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MoyiControlPlaneApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MoyiControlPlaneApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
spring:
|
||||
application:
|
||||
name: moyi-control-plane
|
||||
datasource:
|
||||
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5434/moyi_control}
|
||||
username: ${SPRING_DATASOURCE_USERNAME:moyi}
|
||||
password: ${SPRING_DATASOURCE_PASSWORD:}
|
||||
hikari:
|
||||
maximum-pool-size: ${DB_POOL_MAX_SIZE:15}
|
||||
minimum-idle: ${DB_POOL_MIN_IDLE:2}
|
||||
data:
|
||||
redis:
|
||||
url: ${SPRING_DATA_REDIS_URL:redis://localhost:6379}
|
||||
flyway:
|
||||
enabled: ${FLYWAY_ENABLED:true}
|
||||
baseline-on-migrate: true
|
||||
|
||||
server:
|
||||
address: ${CONTROL_PLANE_HOST:0.0.0.0}
|
||||
port: ${CONTROL_PLANE_PORT:8787}
|
||||
shutdown: graceful
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,prometheus
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
|
||||
moyi:
|
||||
auth:
|
||||
session-ttl-hours: ${SESSION_TTL_HOURS:168}
|
||||
password-pepper: ${AUTH_PASSWORD_PEPPER:}
|
||||
storage:
|
||||
oss-endpoint: ${OSS_ENDPOINT:}
|
||||
oss-region: ${OSS_REGION:}
|
||||
oss-bucket: ${OSS_BUCKET:}
|
||||
oss-access-key-id: ${OSS_ACCESS_KEY_ID:}
|
||||
oss-access-key-secret: ${OSS_ACCESS_KEY_SECRET:}
|
||||
@@ -0,0 +1,61 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id uuid PRIMARY KEY,
|
||||
account varchar(320) NOT NULL UNIQUE,
|
||||
account_kind varchar(16) NOT NULL CHECK (account_kind IN ('email', 'phone', 'username')),
|
||||
password_hash text NOT NULL,
|
||||
display_name varchar(80) NOT NULL,
|
||||
role varchar(16) NOT NULL DEFAULT 'user' CHECK (role IN ('user', 'admin')),
|
||||
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
last_login_at timestamptz
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS invitation_codes (
|
||||
id uuid PRIMARY KEY,
|
||||
code_hash char(64) NOT NULL UNIQUE,
|
||||
code_prefix varchar(12) NOT NULL,
|
||||
label varchar(100) NOT NULL,
|
||||
max_uses integer NOT NULL DEFAULT 1 CHECK (max_uses > 0),
|
||||
used_count integer NOT NULL DEFAULT 0 CHECK (used_count >= 0 AND used_count <= max_uses),
|
||||
expires_at timestamptz,
|
||||
disabled_at timestamptz,
|
||||
created_by uuid NOT NULL REFERENCES users(id),
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS invitation_redemptions (
|
||||
invitation_id uuid NOT NULL REFERENCES invitation_codes(id),
|
||||
user_id uuid NOT NULL REFERENCES users(id),
|
||||
redeemed_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (invitation_id, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auth_sessions (
|
||||
id uuid PRIMARY KEY,
|
||||
token_hash char(64) NOT NULL UNIQUE,
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
expires_at timestamptz NOT NULL,
|
||||
revoked_at timestamptz,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
last_seen_at timestamptz NOT NULL DEFAULT now(),
|
||||
user_agent text,
|
||||
ip_address inet
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS auth_sessions_user_id_idx ON auth_sessions(user_id);
|
||||
CREATE INDEX IF NOT EXISTS auth_sessions_expires_at_idx ON auth_sessions(expires_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auth_audit_log (
|
||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
actor_user_id uuid REFERENCES users(id),
|
||||
event_type varchar(64) NOT NULL,
|
||||
target_type varchar(32),
|
||||
target_id text,
|
||||
ip_address inet,
|
||||
user_agent text,
|
||||
details jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS auth_audit_log_created_at_idx ON auth_audit_log(created_at DESC);
|
||||
@@ -0,0 +1,47 @@
|
||||
CREATE TABLE IF NOT EXISTS model_providers (
|
||||
id varchar(64) PRIMARY KEY,
|
||||
code varchar(64) NOT NULL UNIQUE,
|
||||
name varchar(120) NOT NULL,
|
||||
protocol varchar(32) NOT NULL CHECK (protocol IN ('openai-compatible', 'http', 'sdk')),
|
||||
base_url text,
|
||||
description text,
|
||||
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS model_catalog (
|
||||
id varchar(64) PRIMARY KEY,
|
||||
provider_id varchar(64) NOT NULL REFERENCES model_providers(id),
|
||||
public_name varchar(160) NOT NULL,
|
||||
upstream_model varchar(160) NOT NULL,
|
||||
model_type varchar(24) NOT NULL CHECK (model_type IN ('text', 'code', 'multimodal', 'image', 'audio', 'video', 'embedding', '3d')),
|
||||
call_mode varchar(16) NOT NULL CHECK (call_mode IN ('sync', 'stream', 'async')),
|
||||
description text NOT NULL DEFAULT '',
|
||||
input_types jsonb NOT NULL DEFAULT '[]'::jsonb,
|
||||
output_types jsonb NOT NULL DEFAULT '[]'::jsonb,
|
||||
capabilities jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS model_catalog_provider_id_idx ON model_catalog(provider_id);
|
||||
CREATE INDEX IF NOT EXISTS model_catalog_status_idx ON model_catalog(status);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS platform_api_keys (
|
||||
id uuid PRIMARY KEY,
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name varchar(80) NOT NULL,
|
||||
key_prefix varchar(24) NOT NULL,
|
||||
key_hash char(64) NOT NULL UNIQUE,
|
||||
scopes jsonb NOT NULL DEFAULT '["invoke"]'::jsonb,
|
||||
model_ids jsonb NOT NULL DEFAULT '[]'::jsonb,
|
||||
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
last_used_at timestamptz,
|
||||
revoked_at timestamptz
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS platform_api_keys_user_id_idx ON platform_api_keys(user_id);
|
||||
CREATE INDEX IF NOT EXISTS platform_api_keys_status_idx ON platform_api_keys(status);
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS model_projects (
|
||||
id varchar(64) PRIMARY KEY,
|
||||
owner_user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name varchar(80) NOT NULL,
|
||||
description text NOT NULL DEFAULT '',
|
||||
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
ALTER TABLE platform_api_keys ADD COLUMN IF NOT EXISTS project_id varchar(64) REFERENCES model_projects(id) ON DELETE CASCADE;
|
||||
CREATE INDEX IF NOT EXISTS model_projects_owner_user_id_idx ON model_projects(owner_user_id);
|
||||
CREATE INDEX IF NOT EXISTS platform_api_keys_project_id_idx ON platform_api_keys(project_id);
|
||||
Reference in new issue
Block a user