This is an automated email from the ASF dual-hosted git repository.

neuman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 6a0c89b  Prepare database for Roles and Permissions (#6117)
6a0c89b is described below

commit 6a0c89b87522e64446b4198814e98edb1c47eac4
Author: ocket8888 <[email protected]>
AuthorDate: Tue Aug 24 12:03:29 2021 -0600

    Prepare database for Roles and Permissions (#6117)
    
    * Add migration for Roles and Permissions
    
    Removes foreign key constraint on role_capability, adds not null
    constraint on role descriptions
    
    * Adds not null constraint to usernames
---
 ...2021081800000000_roles_and_permissions.down.sql | 31 ++++++++++++++++++++++
 .../2021081800000000_roles_and_permissions.up.sql  | 31 ++++++++++++++++++++++
 .../2021081800000001_no_null_username.down.sql     | 20 ++++++++++++++
 .../2021081800000001_no_null_username.up.sql       | 20 ++++++++++++++
 4 files changed, 102 insertions(+)

diff --git 
a/traffic_ops/app/db/migrations/2021081800000000_roles_and_permissions.down.sql 
b/traffic_ops/app/db/migrations/2021081800000000_roles_and_permissions.down.sql
new file mode 100644
index 0000000..163d227
--- /dev/null
+++ 
b/traffic_ops/app/db/migrations/2021081800000000_roles_and_permissions.down.sql
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+ALTER TABLE ONLY public.role
+ALTER COLUMN "description"
+DROP NOT NULL;
+
+DELETE FROM public.role_capability
+WHERE cap_name NOT IN (
+       SELECT DISTINCT "name"
+       FROM public.capability
+);
+
+ALTER TABLE ONLY public.role_capability
+ADD CONSTRAINT fk_cap_name
+FOREIGN KEY (cap_name)
+REFERENCES public.capability (name) ON DELETE RESTRICT;
diff --git 
a/traffic_ops/app/db/migrations/2021081800000000_roles_and_permissions.up.sql 
b/traffic_ops/app/db/migrations/2021081800000000_roles_and_permissions.up.sql
new file mode 100644
index 0000000..5b748e4
--- /dev/null
+++ 
b/traffic_ops/app/db/migrations/2021081800000000_roles_and_permissions.up.sql
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+UPDATE public.role
+SET "description"=''
+WHERE "description" IS NULL;
+
+ALTER TABLE public.role
+ALTER COLUMN "description"
+SET NOT NULL;
+
+ALTER TABLE public.role_capability
+DROP CONSTRAINT fk_cap_name;
+
+INSERT INTO public.role("name", "description", priv_level)
+VALUES ('admin', 'Has access to everything.', 30)
+ON CONFLICT ("name") DO NOTHING;
diff --git 
a/traffic_ops/app/db/migrations/2021081800000001_no_null_username.down.sql 
b/traffic_ops/app/db/migrations/2021081800000001_no_null_username.down.sql
new file mode 100644
index 0000000..82ab284
--- /dev/null
+++ b/traffic_ops/app/db/migrations/2021081800000001_no_null_username.down.sql
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+ALTER TABLE ONLY public.tm_user
+ALTER COLUMN username
+DROP NOT NULL;
diff --git 
a/traffic_ops/app/db/migrations/2021081800000001_no_null_username.up.sql 
b/traffic_ops/app/db/migrations/2021081800000001_no_null_username.up.sql
new file mode 100644
index 0000000..734baf8
--- /dev/null
+++ b/traffic_ops/app/db/migrations/2021081800000001_no_null_username.up.sql
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+ALTER TABLE ONLY public.tm_user
+ALTER COLUMN username
+SET NOT NULL;

Reply via email to