|
|
|
@@ -91,19 +91,15 @@ CREATE INDEX folders_tenant_id_idx ON folders (tenant_id);
|
|
|
|
|
|
|
|
|
|
-- Add tenant_id to users
|
|
|
|
|
ALTER TABLE users ADD COLUMN tenant_id UUID;
|
|
|
|
|
UPDATE users
|
|
|
|
|
SET tenant_id = (SELECT tenant_id FROM public.tenants WHERE slug = 'admin');
|
|
|
|
|
ALTER TABLE users ALTER COLUMN tenant_id SET NOT NULL;
|
|
|
|
|
ALTER TABLE users
|
|
|
|
|
ADD CONSTRAINT users_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(tenant_id);
|
|
|
|
|
CREATE INDEX users_tenant_id_idx ON users (tenant_id);
|
|
|
|
|
|
|
|
|
|
-- Add tenant_id to refresh_tokens
|
|
|
|
|
ALTER TABLE refresh_tokens ADD COLUMN tenant_id UUID;
|
|
|
|
|
UPDATE refresh_tokens AS rt
|
|
|
|
|
SET tenant_id = u.tenant_id
|
|
|
|
|
FROM users AS u
|
|
|
|
|
WHERE rt.user_id = u.id;
|
|
|
|
|
SET tenant_id = (
|
|
|
|
|
SELECT um.tenant_id
|
|
|
|
|
FROM user_memberships AS um
|
|
|
|
|
WHERE um.user_id = rt.user_id
|
|
|
|
|
LIMIT 1
|
|
|
|
|
);
|
|
|
|
|
ALTER TABLE refresh_tokens ALTER COLUMN tenant_id SET NOT NULL;
|
|
|
|
|
ALTER TABLE refresh_tokens
|
|
|
|
|
ADD CONSTRAINT refresh_tokens_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(tenant_id);
|
|
|
|
@@ -112,7 +108,12 @@ CREATE INDEX refresh_tokens_tenant_id_idx ON refresh_tokens (tenant_id);
|
|
|
|
|
-- Add tenant_id to jobs
|
|
|
|
|
ALTER TABLE jobs ADD COLUMN tenant_id UUID;
|
|
|
|
|
UPDATE jobs
|
|
|
|
|
SET tenant_id = (SELECT tenant_id FROM public.tenants WHERE slug = 'admin');
|
|
|
|
|
SET tenant_id = (
|
|
|
|
|
SELECT um.tenant_id
|
|
|
|
|
FROM user_memberships AS um
|
|
|
|
|
WHERE um.user_id = jobs.user_id
|
|
|
|
|
LIMIT 1
|
|
|
|
|
);
|
|
|
|
|
ALTER TABLE jobs ALTER COLUMN tenant_id SET NOT NULL;
|
|
|
|
|
ALTER TABLE jobs
|
|
|
|
|
ADD CONSTRAINT jobs_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(tenant_id);
|
|
|
|
|