You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by fr...@apache.org on 2017/04/20 18:40:15 UTC

[26/44] incubator-trafficcontrol git commit: superuser only creates the 'db_user' and creates databases (and assigns ownership to the db_user) and then db_user takes it from there...drop table, loadschema, migrate, seed...

superuser only creates the 'db_user' and creates databases (and assigns ownership to the db_user) and then db_user takes it from there...drop table, loadschema, migrate, seed...

(cherry picked from commit 60e0dae5d4e4db9b497dcf90f4d1ef96dc7c2aa7)


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

Branch: refs/heads/2.0.x
Commit: bc22f3d988b9d04c2e64327fb42c676477746287
Parents: 8dca9f7
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Thu Apr 13 15:55:11 2017 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Apr 19 15:36:17 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/db/admin.pl   | 19 ++++++++++---------
 traffic_ops/app/db/dbconf.yml |  6 +++---
 2 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bc22f3d9/traffic_ops/app/db/admin.pl
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/admin.pl b/traffic_ops/app/db/admin.pl
index 6f78f26..b7dfcc7 100755
--- a/traffic_ops/app/db/admin.pl
+++ b/traffic_ops/app/db/admin.pl
@@ -40,10 +40,10 @@ my $usage = "\n"
 	. "NOTE: \n"
 	. "Postgres Superuser: The 'postgres' superuser needs to be created to run $PROGRAM_NAME and setup databases.\n"
 	. "If the 'postgres' superuser has not been created or password has not been set then run the following commands accordingly. \n\n"
-	. "Create the 'postgres' user (if not created):\n"
-	. "     \$ createuser postgres\n\n"
+	. "Create the 'postgres' user as a super user (if not created):\n"
+	. "     \$ createuser postgres -s -r -d\n\n"
 	. "Set the 'postgres' user password:\n"
-	. "     CREATE ROLE postgres WITH CREATEROLE LOGIN ENCRYPTED PASSWORD 'yourpassword'; \n\n"
+	. "     CREATE ROLE postgres WITH CREATEROLE CREATEDB LOGIN ENCRYPTED PASSWORD 'yourpassword'; \n\n"
 	. "Postgres Password: file allows for easy command line access by defaulting the user and password for the database\n"
 	. "without prompts.\n\n"
 	. " Postgres .pgpass file format:\n"
@@ -52,6 +52,7 @@ my $usage = "\n"
 	. " Example Contents\n"
 	. " ----------------------\n"
 	. " *:*:*:postgres:yourpassword \n"
+	. " *:*:*:traffic_ops:yourpassword \n"
 	. " ----------------------\n\n"
 	. " Save the following example into this file $HOME/.pgpass with the permissions of this file\n"
 	. " so only $USER can read and write.\n\n"
@@ -78,7 +79,7 @@ my $db_protocol;
 # you don't have to specify --env=development for dev workstations
 my $db_name     = 'to_development';
 my $db_super_user = 'postgres';
-my $db_user = 'traffic_ops';
+my $db_user = '';
 my $db_password = '';
 my $host_ip     = '';
 my $host_port   = '';
@@ -166,7 +167,7 @@ sub parse_dbconf_yml_pg_driver {
 
 	$host_ip     = $hash->{host};
 	$host_port   = $hash->{port};
-	$db_super_user = $hash->{user};
+	$db_user = $hash->{user};
 	$db_password = $hash->{password};
 	$db_name     = $hash->{dbname};
 }
@@ -196,18 +197,18 @@ sub load_schema {
 
 sub dropdb {
 	print "Dropping database: $db_name\n";
-	if ( system("dropdb -h $host_ip -p $host_port -U $db_super_user -e --if-exists $db_name;") != 0 ) {
+	if ( system("dropdb -h $host_ip -p $host_port -U $db_user -e --if-exists $db_name;") != 0 ) {
 		die "Can't drop db $db_name\n";
 	}
 }
 
 sub createdb {
-	my $db_exists = `psql -h $host_ip -U $db_user -p $host_port -tAc "SELECT 1 FROM pg_database WHERE datname='$db_name'"`;
+	my $db_exists = `psql -h $host_ip -U $db_super_user -p $host_port -tAc "SELECT 1 FROM pg_database WHERE datname='$db_name'"`;
 	if ($db_exists) {
 		print "Database $db_name already exists\n";
 		return;
 	}
-    my $cmd = "createdb -h $host_ip -p $host_port -U $db_user --owner $db_user $db_name;";
+    my $cmd = "createdb -h $host_ip -p $host_port -U $db_super_user --owner $db_user $db_name;";
 	if ( system($cmd) != 0 ) {
 		die "Can't create db $db_name\n";
 	}
@@ -219,7 +220,7 @@ sub create_user {
 	my $user_exists = `psql -h $host_ip -p $host_port -U $db_super_user -tAc "SELECT 1 FROM pg_roles WHERE rolname='$db_user'"`;
 
 	if (!$user_exists) {
-		my $cmd = "CREATE USER $db_user WITH CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD '$db_password'";
+		my $cmd = "CREATE USER $db_user WITH LOGIN ENCRYPTED PASSWORD '$db_password'";
 		if ( system(qq{psql -h $host_ip -p $host_port -U $db_super_user -tAc "$cmd"}) != 0 ) {
 			die "Can't create user $db_user\n";
 		}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bc22f3d9/traffic_ops/app/db/dbconf.yml
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/dbconf.yml b/traffic_ops/app/db/dbconf.yml
index ed624e7..6c79b95 100755
--- a/traffic_ops/app/db/dbconf.yml
+++ b/traffic_ops/app/db/dbconf.yml
@@ -19,15 +19,15 @@ name: dbconf.yml
 
 development:
   driver: postgres
-  open: host=127.0.0.1 port=5432 user=to_development password=twelve dbname=to_development sslmode=disable
+  open: host=127.0.0.1 port=5432 user=traffic_ops password=twelve dbname=to_development sslmode=disable
 
 test:
   driver: postgres
-  open: host=127.0.0.1 port=5432 user=to_test password=twelve dbname=to_test sslmode=disable
+  open: host=127.0.0.1 port=5432 user=traffic_ops password=twelve dbname=to_test sslmode=disable
 
 integration:
   driver: postgres
-  open: host=127.0.0.1 port=5432 user=to_integration password=twelve dbname=to_integration sslmode=disable
+  open: host=127.0.0.1 port=5432 user=traffic_ops password=twelve dbname=to_integration sslmode=disable
 
 production:
   driver: postgres