perf(struct): ddd
This commit is contained in:
14
scripts/db/migrations/0009_tenant_oauth_clients.sql
Normal file
14
scripts/db/migrations/0009_tenant_oauth_clients.sql
Normal 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;
|
||||
|
||||
10
scripts/db/migrations/0010_backfill_tenant_oauth_clients.sql
Normal file
10
scripts/db/migrations/0010_backfill_tenant_oauth_clients.sql
Normal 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;
|
||||
|
||||
6
scripts/db/rollback/0009.down.sql
Normal file
6
scripts/db/rollback/0009.down.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
BEGIN;
|
||||
|
||||
DROP TABLE IF EXISTS tenant_oauth_clients;
|
||||
|
||||
COMMIT;
|
||||
|
||||
6
scripts/db/rollback/0010.down.sql
Normal file
6
scripts/db/rollback/0010.down.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
BEGIN;
|
||||
|
||||
DELETE FROM tenant_oauth_clients;
|
||||
|
||||
COMMIT;
|
||||
|
||||
11
scripts/db/verify/0009_tenant_oauth_clients.sql
Normal file
11
scripts/db/verify/0009_tenant_oauth_clients.sql
Normal 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 $$;
|
||||
|
||||
11
scripts/db/verify/0010_backfill_tenant_oauth_clients.sql
Normal file
11
scripts/db/verify/0010_backfill_tenant_oauth_clients.sql
Normal 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 $$;
|
||||
|
||||
Reference in New Issue
Block a user