-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from gleopoldo/change-dump-host-and-user
Change dump host and user
- Loading branch information
Showing
18 changed files
with
598 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM ruby:2.0 | ||
|
||
ARG uid | ||
|
||
RUN apt-get update && apt-get install -y postgresql-client | ||
|
||
RUN useradd -M -u $uid mtools | ||
USER mtools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'open3' | ||
|
||
module MultitenancyTools | ||
module Dump | ||
class DataOnly | ||
def initialize(options) | ||
@schema = options.fetch(:schema) | ||
@db = options.fetch(:database) | ||
@host = options.fetch(:host, nil) | ||
@user = options.fetch(:username, nil) | ||
@table = options.fetch(:table) | ||
end | ||
|
||
def dump | ||
Open3.capture3(dump_args.shelljoin) | ||
end | ||
|
||
private | ||
|
||
def dump_args | ||
args = [ | ||
'pg_dump', | ||
'--table', "#{@schema}.#{@table}", | ||
'--no-privileges', | ||
'--no-tablespaces', | ||
'--no-owner', | ||
'--dbname', @db, | ||
'--data-only', | ||
'--inserts' | ||
] | ||
|
||
args << ['--host', @host] if @host.present? | ||
args << ['--username', @user] if @user.present? | ||
args.flatten | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'open3' | ||
|
||
module MultitenancyTools | ||
module Dump | ||
class SchemaOnly | ||
def initialize(options) | ||
@schema = options.fetch(:schema) | ||
@database = options.fetch(:database) | ||
@host = options.fetch(:host, nil) | ||
@user = options.fetch(:username, nil) | ||
end | ||
|
||
def dump | ||
Open3.capture3(dump_args.shelljoin) | ||
end | ||
|
||
private | ||
|
||
def dump_args | ||
args = [ | ||
'pg_dump', | ||
'--schema', @schema, | ||
'--schema-only', | ||
'--no-privileges', | ||
'--no-tablespaces', | ||
'--no-owner', | ||
'--dbname', @database, | ||
] | ||
|
||
args << ['--host', @host] if @host.present? | ||
args << ['--username', @user] if @user.present? | ||
args.flatten | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
export POSTGRES_CONTAINER_NAME="postgres" | ||
|
||
# removed old pg containers running in your machine | ||
# searches for containers with name "postgres" | ||
remove_old_pg_container() { | ||
container_id=$(docker ps -a --filter name="^$POSTGRES_CONTAINER_NAME$" --format {{.ID}}) | ||
|
||
if [ "$container_id" ]; then | ||
docker stop $container_id | ||
docker rm $container_id | ||
fi | ||
} | ||
|
||
# destroys previous postgres containers and starts a new one | ||
# with fresh data. This prevents problems in running it with | ||
# a prepoulated volume containing old tables. | ||
setup_db_container() { | ||
remove_old_pg_container | ||
|
||
docker run --detach \ | ||
--publish 5432:5432 \ | ||
--hostname $POSTGRES_CONTAINER_NAME \ | ||
--name $POSTGRES_CONTAINER_NAME postgres:9.3 | ||
} | ||
|
||
# ignores docker containers IDs outputs to stdout | ||
setup_db_container &>/dev/null | ||
|
||
# brings up main container with multitenancy tools environment | ||
docker run -it \ | ||
-v $PWD:/mtools \ | ||
--workdir /mtools --user $EUID \ | ||
--link $POSTGRES_CONTAINER_NAME mtools bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
docker build -t mtools:latest --build-arg uid=$EUID . |
Oops, something went wrong.