perf(struct): ddd

This commit is contained in:
2026-02-03 17:31:08 +08:00
parent 202b5eaad5
commit 4a071bd7c8
64 changed files with 1214 additions and 1189 deletions

View File

@@ -0,0 +1,14 @@
BEGIN;
CREATE TABLE IF NOT EXISTS tenant_oauth_clients (
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
client_id VARCHAR(64) NOT NULL REFERENCES oauth_clients(client_id) ON DELETE CASCADE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
PRIMARY KEY (tenant_id, client_id)
);
CREATE INDEX IF NOT EXISTS idx_tenant_oauth_clients_tenant_id ON tenant_oauth_clients(tenant_id);
CREATE INDEX IF NOT EXISTS idx_tenant_oauth_clients_client_id ON tenant_oauth_clients(client_id);
COMMIT;

View File

@@ -0,0 +1,10 @@
BEGIN;
INSERT INTO tenant_oauth_clients (tenant_id, client_id)
SELECT t.id, c.client_id
FROM tenants t
CROSS JOIN oauth_clients c
ON CONFLICT (tenant_id, client_id) DO NOTHING;
COMMIT;

View File

@@ -0,0 +1,6 @@
BEGIN;
DROP TABLE IF EXISTS tenant_oauth_clients;
COMMIT;

View File

@@ -0,0 +1,6 @@
BEGIN;
DELETE FROM tenant_oauth_clients;
COMMIT;

View File

@@ -0,0 +1,11 @@
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_name = 'tenant_oauth_clients'
) THEN
RAISE EXCEPTION 'tenant_oauth_clients table does not exist';
END IF;
END $$;

View File

@@ -0,0 +1,11 @@
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_name = 'tenant_oauth_clients'
) THEN
RAISE EXCEPTION 'tenant_oauth_clients table does not exist';
END IF;
END $$;