Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions traffic_ops/app/db/pg-migration/Dockerfile-convert
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM postgres:9.6

MAINTAINER Dan Kirkwood

RUN apt-get update && apt-get -y install netcat
ADD pg-migration/runconvert.sh .
ADD convert_bools.sql .

CMD ./runconvert.sh
2 changes: 1 addition & 1 deletion traffic_ops/app/db/pg-migration/Dockerfile-pgloader
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ MAINTAINER Dan Kirkwood <dangogh@apache.org>
# install nc to check that postgres and mysql are ready..
RUN apt-get -y install netcat

ADD runpgloader.sh .
ADD pg-migration/runpgloader.sh .
CMD ./runpgloader.sh
35 changes: 30 additions & 5 deletions traffic_ops/app/db/pg-migration/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: '2'

volumes:
sync:

services:
# dataimport reads data from an existing traffic_ops server running mysql thru the API
dataimport:
build:
dockerfile: Dockerfile-traffic_ops-client
context: .
dockerfile: Dockerfile-traffic_ops-client
restart: "no"
environment:
- TO_USER
Expand All @@ -14,6 +18,7 @@ services:
volumes:
- ./mysql/initdb.d:/docker-entrypoint-initdb.d

# mysql_host loads mysql data locally and provides direct access for pgloader
mysql_host:
image: mysql:5.6
restart: "no"
Expand All @@ -28,24 +33,26 @@ services:
- ./mysql/conf.d:/etc/mysql/conf.d
- ./mysql/initdb.d:/docker-entrypoint-initdb.d

# postgres_host provides a postgres data to import data to
postgres_host:
build:
dockerfile: pg-migration/Dockerfile-postgres
context: ..
dockerfile: pg-migration/Dockerfile-postgres
restart: "no"
environment:
- POSTGRES_DB=traffic_ops
- POSTGRES_PASSWORD=twelve
- POSTGRES_USER=traffic_ops
volumes:
- /var/lib/postgresql/data:/var/lib/postgresql/data
- /opt/traffic_ops-db:/var/lib/postgresql/data
ports:
- 5432

# pgloader converts the data from mysql to postgres
pgloader:
build:
dockerfile: Dockerfile-pgloader
context: .
context: ..
dockerfile: pg-migration/Dockerfile-pgloader
restart: "no"
depends_on:
- mysql_host
Expand All @@ -59,3 +66,21 @@ services:
- POSTGRES_DB=traffic_ops
- POSTGRES_PASSWORD=twelve
- POSTGRES_USER=traffic_ops
volumes:
- sync:/sync

# convert runs necessary post-import conversion(s) in postgres
convert:
build:
context: ..
dockerfile: pg-migration/Dockerfile-convert
restart: "no"
depends_on:
- postgres_host
environment:
- POSTGRES_HOST=postgres_host
- POSTGRES_DB=traffic_ops
- POSTGRES_PASSWORD=twelve
- POSTGRES_USER=traffic_ops
volumes:
- sync:/sync

This file was deleted.

8 changes: 0 additions & 8 deletions traffic_ops/app/db/pg-migration/mysql/run.sh

This file was deleted.

17 changes: 17 additions & 0 deletions traffic_ops/app/db/pg-migration/runconvert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -x

set -x

waiting=/sync/waiting-for-pgloader
touch $waiting

# Wait for pgloader to finish
while [[ -f $waiting ]]; do
ls -l $waiting
sleep 3
done

echo "Looks like pgloader is finished.. Converting.."

# Load required conversion of booleans
psql postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB < ./convert_bools.sql
8 changes: 8 additions & 0 deletions traffic_ops/app/db/pg-migration/runpgloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ pgloader -v \
--cast 'type double to numeric drop typemod' \
mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST/traffic_ops_db \
postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB

waiting=/sync/waiting-for-pgloader
while [[ ! -f $waiting ]]; do
echo "Nothing waiting for pgloader?"
sleep 3
done

rm $waiting