Move domain_name to cdn table - schema
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/1d5d9b5b Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/1d5d9b5b Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/1d5d9b5b Branch: refs/heads/master Commit: 1d5d9b5bc2a862fce61c9a00f5552a6f82bc405e Parents: 065a311 Author: Jan van Doorn <jan_vando...@cable.comcast.com> Authored: Mon Dec 26 10:45:47 2016 -0700 Committer: Jan van Doorn <j...@apache.org> Committed: Fri Feb 17 17:49:10 2017 +0000 ---------------------------------------------------------------------- traffic_ops/app/db/ats_6_mso_migrate.pl | 91 +++++++++++++++++---------- traffic_ops/app/lib/Schema/Result/Cdn.pm | 15 +++-- 2 files changed, 70 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/1d5d9b5b/traffic_ops/app/db/ats_6_mso_migrate.pl ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/ats_6_mso_migrate.pl b/traffic_ops/app/db/ats_6_mso_migrate.pl index 0604f03..fd63fd2 100755 --- a/traffic_ops/app/db/ats_6_mso_migrate.pl +++ b/traffic_ops/app/db/ats_6_mso_migrate.pl @@ -33,47 +33,74 @@ my $dsn = "DBI:$driver:dbname=$database;host=127.0.0.1;port=5432"; my $dbh = DBI->connect( $dsn, $userid, $password, { RaiseError => 1 } ) or die $DBI::errstr; -print "Opened database successfully\n"; - -my $sql = 'select id,xml_id,mid_header_rewrite from deliveryservice where multi_site_origin=true;'; +# elsif ( $multi_site_origin_algorithm == 1 ) { +# $mso_algorithm = "false"; +# } +# elsif ( $multi_site_origin_algorithm == 2 ) { +# $mso_algorithm = "strict"; +# } +# elsif ( $multi_site_origin_algorithm == 3 ) { +# $mso_algorithm = "true"; +# } +# elsif ( $multi_site_origin_algorithm == 4 ) { +# $mso_algorithm = "latched"; +# } +# else { +# $mso_algorithm = "consistent_hash"; +my @mso_algorithm_choices = ( "consistent_hash", "false", "strict", "true", "latched" ); +my $sql = 'select id,xml_id,mid_header_rewrite,multi_site_origin,multi_site_origin_algorithm from deliveryservice where multi_site_origin=true;'; my $sth = $dbh->prepare_cached($sql); $sth->execute || die "Couldn't execute statement: " . $sth->errstr; while ( my @data = $sth->fetchrow_array() ) { - if ( !defined( $data[2] ) ) { + if ( defined( $data[3] ) && !$data[3] ) { next; } - my @lines = split( /__RETURN__/, $data[2] ); my %profile_ids; - foreach my $line (@lines) { - if ( !defined( $profile_ids{ $data[1] } ) ) { - my $insp = $dbh->prepare('INSERT INTO PROFILE ("name", "description") VALUES(?, ?);'); - $insp->bind_param( 1, "MIDMSO_" . $data[1] ); - $insp->bind_param( 2, "Profile for " . $data[1] . " MSO settings" ); - $insp->execute(); - my $profile_id = $dbh->last_insert_id( undef, undef, "profile", undef ); - $profile_ids{ $data[1] } = $profile_id; - } - if ( $line =~ /set-config proxy.config.http.parent_origin/ ) { - my $setting = $line; - $setting =~ s/set-config //; - print $data[1] . " ->" . $setting . "\n"; - $setting =~ s/^ *//; - my ( $name, $value ) = split( /\s+/, $setting ); - print $name . " -> " . $value . "\n"; - my $insh = $dbh->prepare('INSERT INTO PARAMETER ("name", "config_file", "value") VALUES (?, ?, ?);'); - $insh->bind_param( 1, $name ); - $insh->bind_param( 2, 'parent.config' ); - $insh->bind_param( 3, $value ); - $insh->execute(); - my $param_id = $dbh->last_insert_id( undef, undef, "parameter", undef ); - print "Last inserted: " . $param_id; - my $inspp = $dbh->prepare('INSERT INTO PROFILE_PARAMETER ("parameter", "profile") VALUES (?, ?);'); - $inspp->bind_param( 1, $param_id ); - $inspp->bind_param( 2, $profile_ids{ $data[1] } ); - $inspp->execute(); + if ( !defined( $profile_ids{ $data[1] } ) ) { + my $insp = $dbh->prepare('INSERT INTO PROFILE ("name", "description") VALUES(?, ?);'); + $insp->bind_param( 1, "MSO_SELECT_" . $data[1] ); + $insp->bind_param( 2, "Profile for " . $data[1] . " MSO settings" ); + $insp->execute(); + my $profile_id = $dbh->last_insert_id( undef, undef, "profile", undef ); + $profile_ids{ $data[1] } = $profile_id; + } + if ( defined( $data[2] ) ) { + my @lines = split( /__RETURN__/, $data[2] ); + foreach my $line (@lines) { + if ( $line =~ /set-config proxy.config.http.parent_origin/ ) { + my $setting = $line; + $setting =~ s/set-config\s+proxy.config.http.parent_origin.//; + print $data[1] . " ->" . $setting . "\n"; + $setting =~ s/^ *//; + my ( $name, $value ) = split( /\s+/, $setting ); + print $name . " -> " . $value . "\n"; + my $insh = $dbh->prepare('INSERT INTO PARAMETER ("name", "config_file", "value") VALUES (?, ?, ?);'); + $insh->bind_param( 1, $name ); + $insh->bind_param( 2, 'parent.config' ); + $insh->bind_param( 3, $value ); + $insh->execute(); + my $param_id = $dbh->last_insert_id( undef, undef, "parameter", undef ); + print "Last inserted: " . $param_id; + my $inspp = $dbh->prepare('INSERT INTO PROFILE_PARAMETER ("parameter", "profile") VALUES (?, ?);'); + $inspp->bind_param( 1, $param_id ); + $inspp->bind_param( 2, $profile_ids{ $data[1] } ); + $inspp->execute(); + } } } + my $insh = $dbh->prepare('INSERT INTO PARAMETER ("name", "config_file", "value") VALUES (?, ?, ?);'); + $insh->bind_param( 1, "algorithm" ); + $insh->bind_param( 2, 'parent.config' ); + my $mso_num = defined( $data[4] ) ? $data[4] : 0; + $insh->bind_param( 3, $mso_algorithm_choices[$mso_num] ); + $insh->execute(); + my $param_id = $dbh->last_insert_id( undef, undef, "parameter", undef ); + print "Last inserted: " . $param_id; + my $inspp = $dbh->prepare('INSERT INTO PROFILE_PARAMETER ("parameter", "profile") VALUES (?, ?);'); + $inspp->bind_param( 1, $param_id ); + $inspp->bind_param( 2, $profile_ids{ $data[1] } ); + $inspp->execute(); } $dbh->disconnect(); http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/1d5d9b5b/traffic_ops/app/lib/Schema/Result/Cdn.pm ---------------------------------------------------------------------- diff --git a/traffic_ops/app/lib/Schema/Result/Cdn.pm b/traffic_ops/app/lib/Schema/Result/Cdn.pm index 39669cb..28b7f6b 100644 --- a/traffic_ops/app/lib/Schema/Result/Cdn.pm +++ b/traffic_ops/app/lib/Schema/Result/Cdn.pm @@ -48,6 +48,11 @@ __PACKAGE__->table("cdn"); default_value: false is_nullable: 0 +=head2 domain_name + + data_type: 'text' + is_nullable: 0 + =cut __PACKAGE__->add_columns( @@ -69,6 +74,8 @@ __PACKAGE__->add_columns( }, "dnssec_enabled", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "domain_name", + { data_type => "text", is_nullable => 0 }, ); =head1 PRIMARY KEY @@ -85,7 +92,7 @@ __PACKAGE__->set_primary_key("id"); =head1 UNIQUE CONSTRAINTS -=head2 C<idx_24701_cdn_cdn_unique> +=head2 C<idx_18210_cdn_cdn_unique> =over 4 @@ -95,7 +102,7 @@ __PACKAGE__->set_primary_key("id"); =cut -__PACKAGE__->add_unique_constraint("idx_24701_cdn_cdn_unique", ["name"]); +__PACKAGE__->add_unique_constraint("idx_18210_cdn_cdn_unique", ["name"]); =head1 RELATIONS @@ -145,8 +152,8 @@ __PACKAGE__->might_have( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-09 09:10:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yBLkvGMimI0emk0nO5/CAA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2016-12-26 10:44:56 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:AQZpzzOuEpgmacUrJGl+LQ # You can replace this text with custom code or comments, and it will be preserved on regeneration