You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2017/03/09 19:09:27 UTC

[19/44] incubator-trafficcontrol git commit: move enum values stuff to view

move enum values stuff to view


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

Branch: refs/heads/master
Commit: 67ca5bfb7b753f4dab490da2c4eb1824379b3762
Parents: 16678b2
Author: Jan van Doorn <ja...@cable.comcast.com>
Authored: Fri Jan 6 16:44:42 2017 -0700
Committer: Jan van Doorn <jv...@apache.org>
Committed: Fri Feb 17 17:49:10 2017 +0000

----------------------------------------------------------------------
 .../20161226000000_cdn_domain_name.sql          |  3 +
 traffic_ops/app/lib/MojoPlugins/Enum.pm         | 12 ++--
 .../app/lib/Schema/Result/ProfileTypeValue.pm   | 69 ++++++++++++++++++++
 3 files changed, 77 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/67ca5bfb/traffic_ops/app/db/migrations/20161226000000_cdn_domain_name.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/migrations/20161226000000_cdn_domain_name.sql b/traffic_ops/app/db/migrations/20161226000000_cdn_domain_name.sql
index b84cc35..45da0a8 100644
--- a/traffic_ops/app/db/migrations/20161226000000_cdn_domain_name.sql
+++ b/traffic_ops/app/db/migrations/20161226000000_cdn_domain_name.sql
@@ -18,6 +18,9 @@
 
 CREATE TYPE profile_type AS ENUM ('ATS_PROFILE', 'TR_PROFILE', 'TM_PROFILE', 'TS_PROFILE', 'TP_PROFILE', 'INFLUXDB_PROFILE', 
   'RIAK_PROFILE', 'SPLUNK_PROFILE', 'DS_PROFILE', 'ORG_PROFILE', 'KAFKA_PROFILE', 'LOGSTASH_PROFILE', 'ES_PROFILE', 'UNK_PROFILE');
+
+CREATE OR REPLACE VIEW "profile_type_values" AS SELECT unnest(enum_range(NULL::profile_type )) AS value ORDER BY value;
+  
 ALTER TABLE public.profile ADD COLUMN type profile_type;
 UPDATE public.profile SET type='UNK_PROFILE'; -- So we don't get any NULL, these should be checked.
 UPDATE public.profile SET type='TR_PROFILE' WHERE name like 'CCR_%' OR name like 'TR_%';

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/67ca5bfb/traffic_ops/app/lib/MojoPlugins/Enum.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/MojoPlugins/Enum.pm b/traffic_ops/app/lib/MojoPlugins/Enum.pm
index b132b61..4d7174d 100644
--- a/traffic_ops/app/lib/MojoPlugins/Enum.pm
+++ b/traffic_ops/app/lib/MojoPlugins/Enum.pm
@@ -29,13 +29,11 @@ sub register {
 			my $self = shift;
 			my $enum_name = shift;
 
-			my @possible;
-			my $dbh    = Schema->database_handle;
-			my $h = $dbh->prepare('SELECT unnest(enum_range(NULL:: ' . $enum_name . ' )) as value ORDER BY value');
-			$h->execute || print "ERR";
-			while ( my @data = $h->fetchrow_array() ) {
-				push(@possible, $data[0]);
-			}
+			print ">>> " . $enum_name . "\n";
+			my %views = (  # to add more enums, just add the key, val pair here.
+				'profile_type', 'ProfileTypeValue'
+			 ); 
+			my @possible = $self->db->resultset( $views{$enum_name })->search(undef)->get_column('value')->all();
 			return \@possible;
 		}
 	);

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/67ca5bfb/traffic_ops/app/lib/Schema/Result/ProfileTypeValue.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/ProfileTypeValue.pm b/traffic_ops/app/lib/Schema/Result/ProfileTypeValue.pm
new file mode 100644
index 0000000..0d1b50d
--- /dev/null
+++ b/traffic_ops/app/lib/Schema/Result/ProfileTypeValue.pm
@@ -0,0 +1,69 @@
+use utf8;
+package Schema::Result::ProfileTypeValue;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Schema::Result::ProfileTypeValue
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+__PACKAGE__->table_class("DBIx::Class::ResultSource::View");
+
+=head1 TABLE: C<profile_type_values>
+
+=cut
+
+__PACKAGE__->table("profile_type_values");
+__PACKAGE__->result_source_instance->view_definition(" SELECT unnest(enum_range(NULL::profile_type)) AS value\n  ORDER BY (unnest(enum_range(NULL::profile_type)))");
+
+=head1 ACCESSORS
+
+=head2 value
+
+  data_type: 'enum'
+  extra: {custom_type_name => "profile_type",list => ["ATS_PROFILE","TR_PROFILE","TM_PROFILE","TS_PROFILE","TP_PROFILE","INFLUXDB_PROFILE","RIAK_PROFILE","SPLUNK_PROFILE","DS_PROFILE","ORG_PROFILE","KAFKA_PROFILE","LOGSTASH_PROFILE","ES_PROFILE","UNK_PROFILE"]}
+  is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+  "value",
+  {
+    data_type => "enum",
+    extra => {
+      custom_type_name => "profile_type",
+      list => [
+        "ATS_PROFILE",
+        "TR_PROFILE",
+        "TM_PROFILE",
+        "TS_PROFILE",
+        "TP_PROFILE",
+        "INFLUXDB_PROFILE",
+        "RIAK_PROFILE",
+        "SPLUNK_PROFILE",
+        "DS_PROFILE",
+        "ORG_PROFILE",
+        "KAFKA_PROFILE",
+        "LOGSTASH_PROFILE",
+        "ES_PROFILE",
+        "UNK_PROFILE",
+      ],
+    },
+    is_nullable => 1,
+  },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-01-06 15:41:31
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:F1WD3vn6YZcU/YlHKVp8CA
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;