Spaces:
Runtime error
Runtime error
File size: 1,614 Bytes
609fb6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
email VARCHAR(255) UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
role VARCHAR(50) NOT NULL,
tenant_id UUID NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE agents (
id SERIAL PRIMARY KEY,
user_id UUID REFERENCES users(id),
tenant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL,
type VARCHAR(50) NOT NULL,
status VARCHAR(50) NOT NULL,
description TEXT,
avatar_url TEXT,
llm_base VARCHAR(50),
prompt TEXT,
knowledge_base_url TEXT,
learning_rate FLOAT,
exploration_rate FLOAT,
training_iterations INT,
batch_size INT,
max_tokens INT,
temperature FLOAT,
top_p FLOAT,
frequency_penalty FLOAT,
presence_penalty FLOAT,
stop_sequences TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
ALTER TABLE agents ENABLE ROW LEVEL SECURITY;
CREATE POLICY "tenant_isolation" ON users
FOR ALL
USING (tenant_id = current_setting('app.current_tenant')::uuid);
CREATE POLICY "tenant_isolation" ON agents
FOR ALL
USING (tenant_id = current_setting('app.current_tenant')::uuid);
CREATE POLICY "Enable real-time" ON users
FOR SELECT USING (true);
CREATE POLICY "Enable real-time" ON agents
FOR SELECT USING (true);
CREATE POLICY "user_access" ON users
FOR SELECT
USING (auth.uid() = id);
CREATE POLICY "agent_access" ON agents
FOR SELECT
USING (auth.uid() = user_id);
CREATE INDEX idx_users_tenant_id ON users(tenant_id);
CREATE INDEX idx_agents_tenant_id ON agents(tenant_id); |