Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Apache license to psql docker files #122

Closed
wants to merge 193 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
e0ebcfa
updating database config files.
jheitz200 Jun 30, 2016
ea6731f
adding postgres and removing mysql.
jheitz200 Jun 30, 2016
0a77db3
working on migrating to postgres.
jheitz200 Jul 7, 2016
a715fd8
updating db conf to work with postgres. updating schema file and remo…
jheitz200 Jul 7, 2016
889adc0
updating sql.
jheitz200 Jul 7, 2016
ad52782
working on db/admin script.
jheitz200 Jul 8, 2016
97f89a1
fixing stuff.
jheitz200 Jul 8, 2016
a3f6630
adding temp migration.
jheitz200 Jul 14, 2016
aeefb5c
updating admin.pl to create, delete, and show users.
jheitz200 Jul 18, 2016
1676646
removing id's from fixtures.
jheitz200 Jul 21, 2016
9639a2f
updating test helper to reset sequence ids every time the tests run.
jheitz200 Jul 21, 2016
b899fb2
organizing fixtures alphabetically to guarantee insertion order.
jheitz200 Jul 21, 2016
8c8680b
fixing tests.
jheitz200 Jul 21, 2016
95af445
fixing tests and fixtures.
jheitz200 Jul 22, 2016
6f63546
fixing tests.
jheitz200 Jul 22, 2016
69503a9
fixing tests
jheitz200 Jul 25, 2016
2ef8b27
fixing tests.
jheitz200 Jul 25, 2016
e9139ad
fixing integration.
jheitz200 Aug 1, 2016
af0c115
fixing integration fixtures.
jheitz200 Aug 2, 2016
969a182
fixing integration tests.
jheitz200 Aug 2, 2016
9135384
fixing tests.
jheitz200 Aug 3, 2016
16843c6
updating test helpers.
jheitz200 Aug 4, 2016
32afdf5
fixing dbdump.
jheitz200 Aug 5, 2016
65abbb6
updating schema and migrations.
jheitz200 Aug 8, 2016
536abd8
fixing tests after merging master
jheitz200 Aug 11, 2016
a90c84c
updating create tables sql.
jheitz200 Aug 22, 2016
d62e327
no migrations in the branch. removing ones added with master merge.
mitchell852 Sep 1, 2016
490f5d0
updates create_tables based on updated schema
mitchell852 Sep 2, 2016
a96ae3e
removes offline_reason migration and just rolls it into create_tables…
mitchell852 Sep 16, 2016
8eb5ecf
updates prod dbname
mitchell852 Sep 19, 2016
e363f58
renamed the users to match the databases
dewrich Oct 4, 2016
7a7575d
renames migration to be at the end of the migration list
mitchell852 Sep 22, 2016
2c06a49
fixes broken server tests
mitchell852 Sep 22, 2016
831ba45
Fix t/api/1.2/server.t in psql branch
Sep 24, 2016
47589cc
Fix tests and fixtures for pg. Update schema for tinyint to smallint …
Sep 24, 2016
97e76f7
rpm spec -- remove mysql, add postgres
dangogh Sep 15, 2016
0bd9404
update TO dockerfile for postgres: up to centos 7; use cpanm; add pos…
dangogh Sep 28, 2016
4d8b383
TO: move most rpm installs to requires in .spec
dangogh Sep 28, 2016
189fb1e
initial docker-compose
dangogh Sep 29, 2016
29ba3b8
build traffic_ops from docker-compose
dangogh Sep 30, 2016
fe2512b
move docker-compose files to infrastructure
dangogh Sep 30, 2016
133fb82
remote postgres-devel dependency
dangogh Oct 4, 2016
7378551
add perl-JSON to TO rpm requires
dangogh Oct 4, 2016
aa622d0
adds usage comments to build/docker-compose.yml
dangogh Oct 4, 2016
0e4d60c
README for docker build for rpms
dangogh Oct 5, 2016
558ddb2
Docker build: portal requires gcc; make all Docker build files consis…
dangogh Oct 6, 2016
f7c243f
use env defaults if unset for docker build clone
dangogh Oct 7, 2016
e427d9a
simplify; remove clone volume
dangogh Oct 8, 2016
3287dbf
add requires to TO rpm spec for clean carton install
dangogh Oct 9, 2016
d0fe09a
eliminate .json suffix on remaining api calls
dangogh Oct 11, 2016
334a65d
Fix for #2006 to include the primary keys in the group_by
dewrich Oct 12, 2016
be8ef1d
use ON CONFLICT DO NOTHING instead of IGNORE for psql
dangogh Oct 27, 2016
0e44357
add docker setup to run pgloader
dangogh Oct 17, 2016
4d2b1c8
merge master
dangogh Nov 7, 2016
d69de3c
Fix for Issue #TC-33
dewrich Nov 7, 2016
744499d
the migration basically includes 2 things -1) converts double to nume…
mitchell852 Nov 9, 2016
5c1cbc4
more tweaks to migration and added the goose down part
mitchell852 Nov 9, 2016
57baf3a
adds bool migration for goose_db_version.is_applied field
mitchell852 Nov 9, 2016
5006eac
updated to correct the float types to return as floats
dewrich Nov 10, 2016
a627d15
fix merge issues
dangogh Nov 11, 2016
fa7da76
psql fix - status_name is required in the group by clause
mitchell852 Nov 14, 2016
e30afe9
This closes #77.
dangogh Nov 14, 2016
4c30936
Fixed the TO UI.Tools.DBDump facility
dewrich Nov 11, 2016
ca55e93
This closes #79
mitchell852 Nov 14, 2016
477fb3a
This closes #74
mitchell852 Nov 14, 2016
cd5407b
Rename TM2 commonError to wrapErr
rob05c Nov 4, 2016
9d119b3
add TM2 log.Write
rob05c Nov 7, 2016
968c13c
Change TM2 HTTP dispatch to use a map
rob05c Nov 7, 2016
524f917
Fix TM2 to Stop time.Ticker
rob05c Nov 9, 2016
b879ff9
changed repo path from github.com/Comcast to github.com/apache/incuba…
bluke7922 Nov 10, 2016
dceef53
lock the sslkeys screen to prevent scrolling issue. This fixes: TC-42
dneuman64 Nov 14, 2016
ea10588
removes applied migrations
mitchell852 Nov 14, 2016
4895aeb
This closes #80
dangogh Nov 14, 2016
610a17d
runs reverse_schema after mysql to psql data migration and column typ…
mitchell852 Nov 15, 2016
95e2703
This closes #83
dangogh Nov 15, 2016
5883265
updates create_tables.sql to reflect the schema of the postgres db po…
mitchell852 Nov 15, 2016
022e345
This closes #84.
dangogh Nov 15, 2016
8be8688
psql migration needs to work when no data is loaded. i.e. during --en…
mitchell852 Nov 15, 2016
fcc673f
This closes #85.
dangogh Nov 15, 2016
ea64178
sets doubles and the proper smallints to numeric and bool respectively
mitchell852 Nov 15, 2016
6e41cfb
moves the sql uses to fix datatypes for a migrated database into a no…
mitchell852 Nov 15, 2016
f2a500b
the migrations dir is now empty. this will ensure that it is there.
mitchell852 Nov 15, 2016
3bdfae3
This closes #87.
dangogh Nov 15, 2016
6a3b03e
updates to api to handle booleans properly
mitchell852 Nov 16, 2016
e919e28
This closes #88.
dangogh Nov 17, 2016
0a4d243
handles change of dsid in api from string to int
mitchell852 Nov 16, 2016
7978fc7
This closes #89.
dangogh Nov 17, 2016
25f0411
Merge branch 'master' of github.com:apache/incubator-trafficcontrol i…
dangogh Nov 17, 2016
38bbde3
removes routes that somehow got duplicated
mitchell852 Nov 17, 2016
cc7f42b
This closes #90.
dangogh Nov 17, 2016
4f0e1af
casts miss_lat and miss_long to a float as it is in the db
mitchell852 Nov 17, 2016
4aa4af9
This closes #93.
dangogh Nov 18, 2016
d71603a
Reverse schema with text
knutsel Nov 18, 2016
0305073
This closes #97
mitchell852 Nov 18, 2016
be81315
add traffic ops client container to grab TO from old server
dangogh Nov 16, 2016
cee22b7
update psql migration README
dangogh Nov 17, 2016
88cf38c
add more casts
dangogh Nov 19, 2016
29eb317
This closes #91
dneuman64 Nov 21, 2016
cf14ba3
update server.go and server fixture for new API
dneuman64 Nov 21, 2016
d844c7a
updated from master and added id sorting
dewrich Nov 16, 2016
3aa8385
more fixture migration from master
dewrich Nov 16, 2016
68fb685
checkpoint update for fixture alignment
dewrich Nov 16, 2016
028cdd3
realigned the ids so that the fixture ids are higher than the generat…
dewrich Nov 17, 2016
abfcc14
fixed the deliveryserviceserver fixtures, and test
dewrich Nov 17, 2016
e6a0fd8
fixed the health.t testcase and data
dewrich Nov 17, 2016
a430a00
more id realignment
dewrich Nov 17, 2016
a2f026a
fixed data alignment and t/staticdnsentry.t
dewrich Nov 17, 2016
095195b
removed because the type ids are incorrect
dewrich Nov 17, 2016
929688d
removed because it didnt test anything real
dewrich Nov 17, 2016
399c0e5
fixed the role result after data alignment
dewrich Nov 17, 2016
15f5241
corrected test result
dewrich Nov 17, 2016
54e9a36
fixed the job api
dewrich Nov 17, 2016
050bf6b
fixed the role, and types test case alignment
dewrich Nov 17, 2016
d8a0ad0
fixed the log fixture tm_user pointer
dewrich Nov 17, 2016
3f80691
fixed the data alignment
dewrich Nov 17, 2016
804ee1b
fixed the delivery servivce id
dewrich Nov 17, 2016
2c877a8
fixed test data
dewrich Nov 17, 2016
cf4c004
fixed the cachegroup test case
dewrich Nov 17, 2016
dc02042
restored from master
dewrich Nov 17, 2016
65358e7
realigned the test data
dewrich Nov 17, 2016
50154c9
made changes to fix the cachegroup and parameter test cases
dewrich Nov 17, 2016
491d595
fixed the cdn test case
dewrich Nov 17, 2016
a640fe9
fixed the test case data alignment
dewrich Nov 17, 2016
274d241
fixed the test data alignment
dewrich Nov 17, 2016
12a6558
fixed the test data alignment
dewrich Nov 17, 2016
a1ecae8
fixed the test data alignment
dewrich Nov 17, 2016
d2570e3
fixed the test data alignment
dewrich Nov 17, 2016
456cbec
fixed the regex and federal_external test cases
dewrich Nov 18, 2016
1c91202
fixed region test cases
dewrich Nov 18, 2016
1d46a30
fixed profile test cases
dewrich Nov 18, 2016
2132274
removed redundant test case and merged with server.t
dewrich Nov 18, 2016
c2b001c
fixed the profile.t test case
dewrich Nov 18, 2016
674556e
fixed perl warning of prior defined variable
dewrich Nov 18, 2016
4aeef7d
merged server_create.t
dewrich Nov 18, 2016
b7659bb
fixed the profile_parameter.t test case
dewrich Nov 18, 2016
9935d88
added id order by to have consistent results
dewrich Nov 21, 2016
54f376b
removed steering_internal.t see JIRA issue #TC-38
dewrich Nov 21, 2016
8fed76a
This closes #100.
dangogh Nov 21, 2016
324134b
pgloader takes care of converting double to numeric so this file is n…
mitchell852 Nov 21, 2016
427b99e
This closes #98.
dangogh Nov 21, 2016
1392b61
add component licenses
dangogh Nov 17, 2016
7ac91fa
realigned data to fix the Riak based tests
dewrich Nov 21, 2016
ed69921
This closes #102
mitchell852 Nov 21, 2016
4c47364
Merge branch 'master' of github.com:apache/incubator-trafficcontrol i…
dangogh Nov 21, 2016
c444a40
update Deliverservice and associated tests/fixtures for psql
dneuman64 Nov 21, 2016
028ac96
update HwInfo.pm to always return an int for limit
dneuman64 Nov 22, 2016
09d6bdf
update hardware client for psql
dneuman64 Nov 22, 2016
f6f3f15
added second entry to hardware
dneuman64 Nov 22, 2016
cbd5e09
Remove version for response structs
dneuman64 Nov 22, 2016
dae0f12
update user client for psql
dneuman64 Nov 22, 2016
b0a50a6
not_like doesn't work with bigint or integers in general probably
mitchell852 Nov 22, 2016
3162178
This closes #103.
dangogh Nov 28, 2016
23e49aa
if not in git tree, no tarball
dangogh Nov 12, 2016
08656fb
revcount and commit from buildno
dangogh Nov 13, 2016
860c102
if not in git tree, no tarball
dangogh Nov 12, 2016
0dc9f69
revcount and commit from buildno
dangogh Nov 13, 2016
ec0d162
use $BUILD_NUMBER from env for traffic_router version
dangogh Nov 21, 2016
0358622
change MultiSiteOrigin to bool
dneuman64 Nov 28, 2016
2d2aac9
update cachegroup to support real floats returned from API
dneuman64 Nov 28, 2016
dc81269
Merge branch 'to-client-psql' of https://github.com/dneuman64/incubat…
mitchell852 Nov 28, 2016
0cfb4ec
This closes #104
mitchell852 Nov 28, 2016
e810bf1
if not in git tree, no tarball
dangogh Nov 12, 2016
d78f911
revcount and commit from buildno
dangogh Nov 13, 2016
e4084dc
if not in git tree, no tarball
dangogh Nov 12, 2016
06a565a
revcount and commit from buildno
dangogh Nov 13, 2016
1317b3f
separate BUILD_NUMBER and RHEL_NUMBER during build
dangogh Nov 28, 2016
6aab649
cd to traffic_monitor prior to mvn call
dangogh Nov 29, 2016
4fe8db0
[TC-54] - Obtain the ATS user's UID after package installation during…
elsloo Nov 28, 2016
2a7dbec
use env BUILD_NUMBER and RHEL_NUMBER for release name
dangogh Nov 29, 2016
c05986a
up traffic_monitor and traffic_router to version 1.9.0
dangogh Nov 29, 2016
c565864
cd to traffic_router prior to setting version
dangogh Nov 29, 2016
e8ae0a0
fix ref to TC_VERSION
dangogh Nov 29, 2016
7861fa1
add volume for postgres persistent data
dangogh Nov 30, 2016
875c19e
dnssecEnabled is required on a create and it should come across as a …
mitchell852 Nov 30, 2016
678f49c
This closes #113.
dangogh Dec 1, 2016
146b1c9
Merge branch 'psql-migration' of https://github.com/dangogh/incubator…
mitchell852 Dec 1, 2016
1e0926d
This closes #114
mitchell852 Dec 1, 2016
3da94ae
fixed mday to remove -1 calc
dewrich Dec 1, 2016
5bada9d
This closes #115
mitchell852 Dec 1, 2016
68108a6
if not in git tree, no tarball
dangogh Nov 12, 2016
a47ce7e
revcount and commit from buildno
dangogh Nov 13, 2016
f89845a
Update LICENSE, NOTICE with Maxmind CCSA-4.0 IL and attribution
limited Dec 1, 2016
5ceb8cb
explicitly define project name when creating the tarball
dangogh Dec 1, 2016
570d605
Merge branch 'master' of https://github.com/apache/incubator-trafficc…
dangogh Dec 4, 2016
140ca3e
add convert service for docker-compose for psql conversion
dangogh Dec 1, 2016
624f1ba
add another step to convert bools
dangogh Dec 4, 2016
33e5502
This closes #120
mitchell852 Dec 5, 2016
6a3f36b
add to .rat-exludes for files not needing license
dangogh Dec 5, 2016
e377589
add Apache licenses to more files
dangogh Dec 5, 2016
12ab333
license for sql files
dangogh Dec 5, 2016
fc92ab9
Merge branch 'master' of github.com:apache/incubator-trafficcontrol i…
dangogh Dec 6, 2016
f13fb5c
Merge branch 'rat-and-apache-license' into apache-license-docker
dangogh Dec 6, 2016
6fbfb62
add Apache license to pg-migration files
dangogh Dec 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .rat-excludes
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
./docs/*
VERSION
BUILD_NUMBER
.*.md
README.*
.git.*
.rat-excludes
.keep
docs
vendor
misc
profile\..*
profiles
.*.json
.*.cfg
.*.conf
.*.js
jquery.*
jMenu.*
traffic_ops/lib/Schema/Results
.*.jsx
\.classpath
\.project
etc
.*.prop
tomcat
perl5
.*.css
.*.crt
.*.key
.bowerrc
traffic_server
checks
.*.csv
.*.svg
.*.xml.test
.*.config.dist
CrStates
.*.logrotate
.jshintrc
testFiles
.*.txt
20 changes: 4 additions & 16 deletions infrastructure/docker/traffic_ops/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
############################################################
# Dockerfile to build Traffic Ops 1.6.0 container images
# Based on CentOS 6.6
# Based on CentOS 7.2
############################################################

# Example Build and Run:
Expand All @@ -27,16 +27,11 @@
#
# docker run --name my-traffic-ops --hostname my-traffic-ops --net cdnet --publish 443:443 --env MYSQL_IP=my-traffic-ops-mysql --env MYSQL_PORT=3306 --env MYSQL_ROOT_PASS=secretrootpass --env MYSQL_TRAFFIC_OPS_PASS=supersecretpassword --env ADMIN_USER=superroot --env ADMIN_PASS=supersecreterpassward --env CERT_COUNTRY=US --env CERT_STATE=Colorado --env CERT_CITY=Denver --env CERT_COMPANY=NotComcast --env TRAFFIC_VAULT_PASS=marginallylesssecret --env DOMAIN=cdnet --detach traffic_ops:1.5.1

FROM centos:6.6
FROM centos:7
MAINTAINER Dan Kirkwood

RUN yum -y update
RUN yum install -y tar gcc-c++ perl perl-core openssl-devel mysql-devel expect curl
RUN yum clean all

RUN curl -L https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm | perl - App::cpanminus \
&& cpanm Carton \
&& rm -rf /root/.cpanm
RUN yum install -y perl cpanminus perl-Test-CPAN-Meta
RUN cpanm Carton

# Override RPM arg to use a different one using --build-arg RPM=... Can be local file or http://...
ARG RPM=http://traffic-control-cdn.net/downloads/1.7.0/RELEASE-1.7.0/traffic_ops-1.7.0-3908.5b77f60f.x86_64.rpm
Expand All @@ -48,13 +43,6 @@ RUN rm /$(basename $RPM)

RUN cd /opt/traffic_ops/app && carton

# TODO: workaround for installing on CentOS 7 -- fix this!
RUN chmod a+x /opt/traffic_ops/app/bin/* \
/opt/traffic_ops/app/script/* \
/opt/traffic_ops/app/db/*.pl \
/opt/traffic_ops/app/db/*.sh \
/opt/traffic_ops/install/bin/*

RUN export PERL5LIB=/opt/traffic_ops/app/local/lib/perl5/:/opt/traffic_ops/install/lib/ \
&& export TERM=xterm \
&& export USER=root \
Expand Down
8 changes: 4 additions & 4 deletions traffic_ops/app/conf/development/database.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

{
"description": "Local MySQL database on port 3306",
"description": "Local PostgreSQL database on port 5432",
"dbname": "to_development",
"hostname": "localhost",
"user": "to_user",
"user": "to_development",
"password": "twelve",
"port": "3306",
"type": "mysql"
"port": "5432",
"type": "Pg"
}
8 changes: 4 additions & 4 deletions traffic_ops/app/conf/integration/database.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"description": "Local MySQL database on port 3306",
"description": "Local PostgreSQL database on port 5432",
"dbname": "to_integration",
"hostname": "localhost",
"user": "to_user",
"user": "to_integration",
"password": "twelve",
"port": "3306",
"type": "mysql"
"port": "5432",
"type": "Pg"
}
8 changes: 4 additions & 4 deletions traffic_ops/app/conf/production/database.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

{
"description": "Local MySQL database on port 3306",
"dbname": "traffic_ops_db",
"description": "Local PostgreSQL database on port 5432",
"dbname": "traffic_ops",
"hostname": "localhost",
"user": "traffic_ops",
"password": "password",
"port": "3306",
"type": "mysql"
"port": "5432",
"type": "Pg"
}
8 changes: 4 additions & 4 deletions traffic_ops/app/conf/test/database.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"description": "Local MySQL database on port 3306",
"description": "Local PostgreSQL database on port 5432",
"dbname": "to_test",
"hostname": "localhost",
"user": "to_user",
"user": "to_test",
"password": "twelve",
"port": "3306",
"type": "mysql"
"port": "5432",
"type": "Pg"
}
4 changes: 2 additions & 2 deletions traffic_ops/app/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ requires 'Config::Properties';
requires 'Context::Preserve';
requires 'Data::GUID';
requires 'DBD::SQLite';
#requires 'Time::HiRes'; # required by DBD::mysql
requires 'DBD::mysql', '==4.029';
requires 'DBD::Pg';
requires 'DBI';
requires 'DBIx::Class';
requires 'DBIx::Class::Core';
Expand Down Expand Up @@ -275,3 +274,4 @@ requires 'Net::DNS::SEC::Private';
requires 'LWP::Protocol::https';
requires 'Net::CIDR';
requires 'Data::Validate::IP';
requires 'YAML';
156 changes: 73 additions & 83 deletions traffic_ops/app/db/admin.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env perl
#!/usr/bin/env perl
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,6 +24,9 @@
use Schema;
use CPAN::Meta;
use File::Find::Rule;

use YAML;
use YAML qw(LoadFile);
use DBIx::Class::Schema::Loader qw/make_schema_at/;

my $usage = "\n"
Expand All @@ -32,71 +35,56 @@
. "Purpose: This script is used to manage database. The environments are\n"
. " defined in the dbconf.yml, as well as the database names.\n\n"
. "arguments: \n\n"
. "create - Execute db 'create' the database for the current environment.\n"
. "createdb - Execute db 'createdb' the database for the current environment.\n"
. "dropdb - Execute db 'dropdb' on the database for the current environment.\n"
. "down - Roll back a single migration from the current version.\n"
. "drop - Execute db 'drop' on the database for the current environment.\n"
. "createuser - Execute 'createuser' the user for the current environment.\n"
. "dropuser - Execute 'dropuser' the user for the current environment.\n"
. "showusers - Execute sql to show all of the user for the current environment.\n"
. "redo - Roll back the most recently applied migration, then run it again.\n"
. "reset - Execute db drop, create, load_schema, migrate on the database for the current environment.\n"
. "reset - Execute db 'dropdb', 'createdb', load_schema, migrate on the database for the current environment.\n"
. "reverse_schema - Reverse engineer the lib/Schema/Result files from the environment database.\n"
. "seed - Execute sql from db/seeds.sql for loading static data.\n"
. "setup - Execute db drop, create, load_schema, migrate, seed on the database for the current environment.\n"
. "setup - Execute db dropdb, createdb, load_schema, migrate, seed on the database for the current environment.\n"
. "status - Print the status of all migrations.\n"
. "upgrade - Execute migrate then seed on the database for the current environment.\n";

my $environment = 'development';
my $db_string = 'tcp:127.0.0.1:3306*twelve_monkeys/twelve_monkeys/twelve';
my $db_protocol;

# This is defaulted to 'to_development' so
# you don't have to specify --env=development for dev workstations
my $db_name = 'to_development';
my $db_username = 'to_user';
my $db_username = 'to_development';
my $db_password = '';
my $host_ip = '';
my $host_port = '';
GetOptions( "env=s" => \$environment );
$ENV{'MOJO_MODE'} = $environment;
my $dbh = Schema->database_handle;

sub database_handle_no_dbname {
my $self = shift;
my $db_info = Schema->get_dbinfo();
our $user = $db_info->{user};
our $pass = $db_info->{password};
our $dsn = get_dsn_no_dbname();

return DBI->connect( $dsn, $user, $pass, { AutoCommit => 1 } );
}

sub get_dsn_no_dbname {
my $self = shift;

my $db_info = Schema->get_dbinfo();
our $dbname = $db_info->{dbname};
our $hostname = $db_info->{hostname};
our $port = $db_info->{port};
our $type = $db_info->{type};
our $dsn = "DBI:$type:host=$hostname;port=$port";
}

my $dbh_no_dbname = database_handle_no_dbname;

my $schema = Schema->connect_to_database;

parse_dbconf_yml_mysql_driver();
parse_dbconf_yml_pg_driver();

STDERR->autoflush(1);
my $argument = shift(@ARGV);
if ( defined($argument) ) {
if ( $argument eq 'create' ) {
create();
if ( $argument eq 'createdb' ) {
createdb();
}
elsif ( $argument eq 'dropdb' ) {
dropdb();
}
elsif ( $argument eq 'drop' ) {
drop();
elsif ( $argument eq 'createuser' ) {
createuser();
}
elsif ( $argument eq 'dropuser' ) {
dropuser();
}
elsif ( $argument eq 'showusers' ) {
showusers();
}
elsif ( $argument eq 'reset' ) {
drop();
create();
dropdb();
createdb();
load_schema();
migrate('up');
}
Expand All @@ -105,8 +93,8 @@ sub get_dsn_no_dbname {
seed();
}
elsif ( $argument eq 'setup' ) {
drop();
create();
dropdb();
createdb();
load_schema();
migrate('up');
seed();
Expand Down Expand Up @@ -135,70 +123,72 @@ sub get_dsn_no_dbname {
elsif ( $argument eq 'reverse_schema' ) {
reverse_schema();
}
else {
print $usage;
}
}
else {
print $usage;
}

exit(0);

sub parse_dbconf_yml_mysql_driver {
my ($db_conf) = @_;

my @files = File::Find::Rule->file()->name('dbconf.yml')->in('.');
my $meta = Parse::CPAN::Meta->load_file( $files[0] );

# Mysql connection string parsing, if db changes added switch here
# based on the driver: in dbconf.xml
my $db_connection_string = $meta->{$environment}->{open};

my @options = split( ':', $db_connection_string );
$db_protocol = $options[0];

$host_ip = $options[1];
my @port_options = split( '\*', $options[2] );
$host_port = $port_options[0];

my $rest_of_options = $port_options[1];
my @db_options = split( '/', $rest_of_options );
$db_name = $db_options[0];
$db_username = $db_options[1];
$db_password = $db_options[2];
sub parse_dbconf_yml_pg_driver {
my $db_conf = LoadFile('db/dbconf.yml');
my $db_connection = $db_conf->{$environment};
$db_protocol = $db_connection->{driver};
my $open = $db_connection->{open};

# Goose requires the 'open' line in the dbconf file to be a scalar.
# example:
# open: host=127.0.0.1 port=5432 user=to_user password=twelve dbname=to_development sslmode=disable
# We need access to these values for db connections so I am manipulating the 'open'
# line so that it can be loaded into a hash.
$open = join "\n", map { s/=/ : /; $_ } split " ", $open;
my $hash = Load $open;

$host_ip = $hash->{host};
$host_port = $hash->{port};
$db_name = $hash->{dbname};
$db_username = $hash->{user};
$db_password = $hash->{password};
}

sub migrate {
my ($command) = @_;

print "Migrating database...\n";
system( 'goose --env=' . $environment . ' ' . $command );
}

sub seed {
print "Seeding database...\n";
system("mysql -h $host_ip -P $host_port $db_name -u$db_username -p$db_password < db/seeds.sql");
print "Seeding database.\n";
system("psql -h $host_ip -p $host_port -d $db_name -U $db_username -e < db/seeds.sql");
}

sub load_schema {
print "Creating database tables...\n";
system("mysql -h $host_ip -P $host_port $db_name -u$db_username -p$db_password < db/create_tables.sql");
print "Creating database tables.\n";
system("psql -h $host_ip -p $host_port -d $db_name -U $db_username -e < db/create_tables.sql");
}

sub drop {
my $q = "drop database " . $db_name;
print "Executing '" . $q . "'\n";
if ( defined($dbh) ) {
my $stmt = $dbh_no_dbname->prepare($q);
$stmt->execute();
}
else {
print "No database to drop\n";
}
sub dropdb {
system("dropdb -h $host_ip -p $host_port -U $db_username -e --if-exists $db_name;");
}

sub createdb {
system("createdb -h $host_ip -p $host_port -U $db_username -e $db_name;");
}

sub createuser {
system("createuser -h $host_ip -p $host_port -P -e --superuser $db_username;");
}

sub dropuser {
system("dropuser -h $host_ip -p $host_port -i -e $db_username;");
}

sub create {
my $q = "create database " . $db_name;
print "Executing '" . $q . "'\n";
my $stmt = $dbh_no_dbname->prepare($q);
$stmt->execute();
sub showusers {
system("psql postgres -c '\\du';");
}

sub reverse_schema {
Expand Down
Loading