Adding tenancy to the users table

Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/6903eaee
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/6903eaee
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/6903eaee

Branch: refs/heads/master
Commit: 6903eaee44f86c53d2c962751b7e9358903b0890
Parents: 5105b6c
Author: nir-sopher <nirsop...@gmail.com>
Authored: Mon Mar 20 10:39:01 2017 +0200
Committer: Jeremy Mitchell <mitchell...@gmail.com>
Committed: Sun Apr 2 16:08:51 2017 -0600

----------------------------------------------------------------------
 .../migrations/20170315000001_user_tenancy.sql  | 31 ++++++++++
 .../app/lib/Fixtures/Integration/TmUser.pm      |  6 ++
 traffic_ops/app/lib/Fixtures/TmUser.pm          | 60 ++++++++++++++++++++
 traffic_ops/app/lib/Schema/Result/Tenant.pm     | 19 ++++++-
 traffic_ops/app/lib/Schema/Result/TmUser.pm     | 40 +++++++++++--
 5 files changed, 148 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6903eaee/traffic_ops/app/db/migrations/20170315000001_user_tenancy.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/migrations/20170315000001_user_tenancy.sql 
b/traffic_ops/app/db/migrations/20170315000001_user_tenancy.sql
new file mode 100644
index 0000000..9be1ca3
--- /dev/null
+++ b/traffic_ops/app/db/migrations/20170315000001_user_tenancy.sql
@@ -0,0 +1,31 @@
+/*
+
+    Licensed 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.
+*/
+
+-- +goose Up
+-- SQL in section 'Up' is executed when this migration is applied
+
+
+ALTER TABLE tm_user
+    ADD tenant_id BIGINT,
+    ADD CONSTRAINT fk_tenantid FOREIGN KEY (tenant_id) REFERENCES tenant (id) 
MATCH FULL,
+    ALTER COLUMN tenant_id SET DEFAULT NULL;
+CREATE INDEX idx_k_tm_user_tenant_idx ON tm_user USING btree (tenant_id);
+
+-- +goose Down
+-- SQL section 'Down' is executed when this migration is rolled back
+
+ALTER TABLE tm_user
+DROP COLUMN tenant_id;
+

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6903eaee/traffic_ops/app/lib/Fixtures/Integration/TmUser.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Fixtures/Integration/TmUser.pm 
b/traffic_ops/app/lib/Fixtures/Integration/TmUser.pm
index 0aa637a..37e3db6 100644
--- a/traffic_ops/app/lib/Fixtures/Integration/TmUser.pm
+++ b/traffic_ops/app/lib/Fixtures/Integration/TmUser.pm
@@ -31,6 +31,7 @@ my %definition_for = (
                new => 'TmUser',
                using => {
                  username => 'admin',
+                 tenant_id => undef,
                  local_passwd => '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
                  uid => '1',
                  role => '1',
@@ -59,6 +60,7 @@ my %definition_for = (
                        company => undef,
                        confirm_local_passwd => 
'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
                        username => 'codebig',
+                       tenant_id => undef,
                        gid => '1',
                        country => 'United States',
                        state_or_province => 'state_or_province',
@@ -86,6 +88,7 @@ my %definition_for = (
                        confirm_local_passwd => 
'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
                        gid => '1',
                        username => 'extension',
+                       tenant_id => undef,
                        country => 'United States',
                        email => 'plu...@email.com',
                        state_or_province => 'state_or_province',
@@ -111,6 +114,7 @@ my %definition_for = (
                        confirm_local_passwd => 
'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
                        company => undef,
                        username => 'migration',
+                       tenant_id => undef,
                        gid => '1',
                        state_or_province => undef,
                        email => undef,
@@ -140,6 +144,7 @@ my %definition_for = (
                        country => 'United States',
                        gid => '1',
                        username => 'portal',
+                       tenant_id => undef,
                        confirm_local_passwd => 
'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
                        company => undef,
                        local_passwd => 
'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
@@ -165,6 +170,7 @@ my %definition_for = (
                        state_or_province => 'state_or_province',
                        gid => '1',
                        username => 'testuser',
+                       tenant_id => undef,
                        last_updated => '2015-12-10 15:43:45',
                        company => undef,
                        confirm_local_passwd => 
'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6903eaee/traffic_ops/app/lib/Fixtures/TmUser.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Fixtures/TmUser.pm 
b/traffic_ops/app/lib/Fixtures/TmUser.pm
index eee7986..cbb546b 100644
--- a/traffic_ops/app/lib/Fixtures/TmUser.pm
+++ b/traffic_ops/app/lib/Fixtures/TmUser.pm
@@ -27,6 +27,7 @@ my %definition_for = (
                using => {
                        id                   => 100,
                        username             => 'admin',
+                       tenant_id            => undef,
                        role                 => 4,
                        uid                  => '1',
                        gid                  => '1',
@@ -51,6 +52,7 @@ my %definition_for = (
                using => {
                        id                   => 200,
                        username             => 'portal',
+                       tenant_id            => undef,
                        role                 => 6,
                        uid                  => '1',
                        gid                  => '1',
@@ -75,6 +77,7 @@ my %definition_for = (
                using => {
                        id                   => 300,
                        username             => 'codebig',
+                       tenant_id            => undef,
                        role                 => 6,
                        uid                  => '1',
                        gid                  => '1',
@@ -99,6 +102,7 @@ my %definition_for = (
                using => {
                        id                   => 400,
                        username             => 'migration',
+                       tenant_id            => undef,
                        role                 => 5,
                        uid                  => '1',
                        gid                  => '1',
@@ -123,6 +127,7 @@ my %definition_for = (
                using => {
                        id                   => 500,
                        username             => 'federation',
+                       tenant_id            => undef,
                        role                 => 7,
                        uid                  => '1',
                        gid                  => '1',
@@ -147,6 +152,7 @@ my %definition_for = (
                using => {
                        id                   => 600,
                        username             => 'steering1',
+                       tenant_id            => undef,
                        role                 => 7,
                        uid                  => '1',
                        gid                  => '1',
@@ -171,6 +177,7 @@ my %definition_for = (
                using => {
                        id                   => 700,
                        username             => 'steering2',
+                       tenant_id            => undef,
                        role                 => 7,
                        uid                  => '1',
                        gid                  => '1',
@@ -190,6 +197,59 @@ my %definition_for = (
                        registration_sent    => '1999-01-01 00:00:00',
                },
        },
+       
+       admin_root => {
+               new   => 'TmUser',
+               using => {
+                       id                   => 800,
+                       username             => 'admin-root',
+                       tenant_id            => 10**9,
+                       role                 => 4,
+                       uid                  => '1',
+                       gid                  => '1',
+                       local_passwd         => $local_passwd,
+                       confirm_local_passwd => $local_passwd,
+                       full_name            => 'The Admin User for the "root" 
tenant',
+                       email                => 'admin-r...@kabletown.com',
+                       new_user             => '1',
+                       address_line1        => 'address_line1',
+                       address_line2        => 'address_line2',
+                       city                 => 'city',
+                       state_or_province    => 'state_or_province',
+                       phone_number         => '111-111-1111',
+                       postal_code          => '80122',
+                       country              => 'United States',
+                       token                => '',
+                       registration_sent    => '1999-01-01 00:00:00',
+               },
+       },
+       
+       portal_root => {
+               new   => 'TmUser',
+               using => {
+                       id                   => 900,
+                       username             => 'portal-root',
+                       tenant_id            => 10**9,
+                       role                 => 6,
+                       uid                  => '1',
+                       gid                  => '1',
+                       local_passwd         => $local_passwd,
+                       confirm_local_passwd => $local_passwd,
+                       full_name            => 'The Portal User for the "root" 
tenant',
+                       email                => 'portal-r...@kabletown.com',
+                       new_user             => '1',
+                       address_line1        => 'address_line3',
+                       address_line2        => 'address_line4',
+                       city                 => 'city',
+                       state_or_province    => 'state_or_province',
+                       phone_number         => '222-222-2222',
+                       postal_code          => '80122',
+                       country              => 'United States',
+                       token                => '',
+                       registration_sent    => '1999-01-01 00:00:00',
+               },
+       },
+
 );
 
 sub get_definition {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6903eaee/traffic_ops/app/lib/Schema/Result/Tenant.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/Tenant.pm 
b/traffic_ops/app/lib/Schema/Result/Tenant.pm
index dd35a08..9f11084 100644
--- a/traffic_ops/app/lib/Schema/Result/Tenant.pm
+++ b/traffic_ops/app/lib/Schema/Result/Tenant.pm
@@ -148,9 +148,24 @@ __PACKAGE__->has_many(
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
+=head2 tm_users
 
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-03-13 09:41:00
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:a816RdXB0mjimo2LvnqX/Q
+Type: has_many
+
+Related object: L<Schema::Result::TmUser>
+
+=cut
+
+__PACKAGE__->has_many(
+  "tm_users",
+  "Schema::Result::TmUser",
+  { "foreign.tenant_id" => "self.id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-03-20 09:11:40
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:W4nbCNSj6N1gMar0mRvQ5Q
 
 
 # You can replace this text with custom code or comments, and it will be 
preserved on regeneration

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6903eaee/traffic_ops/app/lib/Schema/Result/TmUser.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/TmUser.pm 
b/traffic_ops/app/lib/Schema/Result/TmUser.pm
index bc0abc9..91d57af 100644
--- a/traffic_ops/app/lib/Schema/Result/TmUser.pm
+++ b/traffic_ops/app/lib/Schema/Result/TmUser.pm
@@ -139,6 +139,12 @@ __PACKAGE__->table("tm_user");
   data_type: 'timestamp with time zone'
   is_nullable: 1
 
+=head2 tenant_id
+
+  data_type: 'bigint'
+  is_foreign_key: 1
+  is_nullable: 1
+
 =cut
 
 __PACKAGE__->add_columns(
@@ -196,6 +202,8 @@ __PACKAGE__->add_columns(
   { data_type => "text", is_nullable => 1 },
   "registration_sent",
   { data_type => "timestamp with time zone", is_nullable => 1 },
+  "tenant_id",
+  { data_type => "bigint", is_foreign_key => 1, is_nullable => 1 },
 );
 
 =head1 PRIMARY KEY
@@ -212,7 +220,7 @@ __PACKAGE__->set_primary_key("id");
 
 =head1 UNIQUE CONSTRAINTS
 
-=head2 C<idx_54541_tmuser_email_unique>
+=head2 C<idx_89765_tmuser_email_unique>
 
 =over 4
 
@@ -222,9 +230,9 @@ __PACKAGE__->set_primary_key("id");
 
 =cut
 
-__PACKAGE__->add_unique_constraint("idx_54541_tmuser_email_unique", ["email"]);
+__PACKAGE__->add_unique_constraint("idx_89765_tmuser_email_unique", ["email"]);
 
-=head2 C<idx_54541_username_unique>
+=head2 C<idx_89765_username_unique>
 
 =over 4
 
@@ -234,7 +242,7 @@ 
__PACKAGE__->add_unique_constraint("idx_54541_tmuser_email_unique", ["email"]);
 
 =cut
 
-__PACKAGE__->add_unique_constraint("idx_54541_username_unique", ["username"]);
+__PACKAGE__->add_unique_constraint("idx_89765_username_unique", ["username"]);
 
 =head1 RELATIONS
 
@@ -318,9 +326,29 @@ __PACKAGE__->belongs_to(
   },
 );
 
+=head2 tenant
+
+Type: belongs_to
+
+Related object: L<Schema::Result::Tenant>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "tenant",
+  "Schema::Result::Tenant",
+  { id => "tenant_id" },
+  {
+    is_deferrable => 0,
+    join_type     => "LEFT",
+    on_delete     => "NO ACTION",
+    on_update     => "NO ACTION",
+  },
+);
+
 
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2016-11-18 22:45:19
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SGrZkCGhmXed7UzWMLYfOg
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-19 10:20:47
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2lI3iG0t7INKH+xQq+lo9g
 
 
 # You can replace this text with custom code or comments, and it will be 
preserved on regeneration

Reply via email to