You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/07/23 21:08:23 UTC
[trafficcontrol] 04/04: assign "unassigned" tenants
This is an automated email from the ASF dual-hosted git repository.
dewrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit c88aa2acc4c80039d047ee95fa599c4af5ea9630
Author: Dan Kirkwood <da...@apache.org>
AuthorDate: Thu Jul 12 12:41:29 2018 -0600
assign "unassigned" tenants
---
traffic_ops/app/db/patches.sql | 36 ++++++++++++++++++++++++++----------
traffic_ops/app/db/seeds.sql | 1 +
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/traffic_ops/app/db/patches.sql b/traffic_ops/app/db/patches.sql
index 16cbb8f..a72cd72 100644
--- a/traffic_ops/app/db/patches.sql
+++ b/traffic_ops/app/db/patches.sql
@@ -42,17 +42,33 @@ ALTER TYPE profile_type ADD VALUE IF NOT EXISTS 'GROVE_PROFILE';
-- If tenancy is not needed, simply default to the root tenant. This will help
-- to eliminate the use_tenancy property
-INSERT INTO tenant (name, active, parent_id) VALUES ('root', true, NULL)
-ON CONFLICT DO NOTHING;
-UPDATE tm_user SET tenant_id = (SELECT id FROM tenant WHERE name = 'root')
-WHERE tenant_id IS NULL;
-ALTER TABLE tm_user ALTER COLUMN tenant_id SET NOT NULL;
+DO
+$tenantnotnull$
+BEGIN
+ IF EXISTS (SELECT value FROM parameter WHERE name = 'use_tenancy' AND config_file = 'global' AND value = '1') THEN
+ -- tenancy turned ON -- anything without a tenant gets the "unassigned" tenant
+ UPDATE tm_user SET tenant_id = (SELECT id FROM tenant WHERE name = 'unassigned')
+ WHERE tenant_id IS NULL;
+ UPDATE deliveryservice SET tenant_id = (SELECT id FROM tenant WHERE name = 'unassigned')
+ WHERE tenant_id IS NULL;
+ UPDATE origin SET tenant = (SELECT id FROM tenant WHERE name = 'unassigned')
+ WHERE tenant IS NULL;
+ ELSE
+ -- tenancy turned OFF -- anything without a tenant gets the "root" tenant
+ UPDATE tm_user SET tenant_id = (SELECT id FROM tenant WHERE name = 'root')
+ WHERE tenant_id IS NULL;
+ UPDATE deliveryservice SET tenant_id = (SELECT id FROM tenant WHERE name = 'root')
+ WHERE tenant_id IS NULL;
+ UPDATE origin SET tenant = (SELECT id FROM tenant WHERE name = 'root')
+ WHERE tenant IS NULL;
+ END IF;
+END
+$tenantnotnull$;
-UPDATE deliveryservice SET tenant_id = (SELECT id FROM tenant WHERE name = 'root')
-WHERE tenant_id IS NULL;
+-- add constraints so we can depend on everything being assigned a tenant
+ALTER TABLE tm_user ALTER COLUMN tenant_id SET NOT NULL;
ALTER TABLE deliveryservice ALTER COLUMN tenant_id SET NOT NULL;
-
-UPDATE origin SET tenant = (SELECT id FROM tenant WHERE name = 'root')
-WHERE tenant IS NULL;
ALTER TABLE origin ALTER COLUMN tenant SET NOT NULL;
+-- get rid of the use_tenancy flag
+DELETE FROM parameter WHERE name = 'use_tenancy' AND config_file = 'global';
diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql
index 9dc20f0..2783d9e 100644
--- a/traffic_ops/app/db/seeds.sql
+++ b/traffic_ops/app/db/seeds.sql
@@ -81,6 +81,7 @@ insert into role (name, description, priv_level) values ('disallowed', 'Block al
-- tenants
insert into tenant (name, active, parent_id) values ('root', true, null) ON CONFLICT DO NOTHING;
+insert into tenant (name, active, parent_id) values ('unassigned', true, (select id from tenant where name='root')) ON CONFLICT DO NOTHING;
-- capabilities
insert into capability (name, description) values ('all-read', 'Full read access') ON CONFLICT (name) DO NOTHING;