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 first round of pgtools #642

Merged
merged 17 commits into from
Apr 24, 2019
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:

before_install:
- export GALAXY_REPO=https://github.com/galaxyproject/galaxy
- export GALAXY_RELEASE=release_18.09
- export GALAXY_RELEASE=release_19.01
- export PLANEMO_CONDA_PREFIX="$HOME/conda"
- unset JAVA_HOME

Expand Down
28 changes: 28 additions & 0 deletions tools/pg_tools/.shed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: pgtools
owner: bgruening
description: tool suite for dealing with Postgresql databases from Galaxy's history

long_description: |
The postgresql tools, are using a postgresql database in user-space.
Databases are packed into a tarball and stored in the user-history.

These tools are based on https://github.com/solidsnack/pglite to interact with postgresql in user-space.

categories:
- Data Export
- Data Source
remote_repository_url: https://github.com/bgruening/galaxytools/tools/pgtools
homepage_url: https://www.postgresql.org

auto_tool_repositories:
name_template: "{{ tool_id }}"
description_template: "Postgresql toolbox: {{ tool_name }}"
suite:
name: "postgresql_suite"
description: "A suite of Galaxy tools for dealing with Postgresql databases from Galaxy's history"

long_description: |
The postgresql tools, are using a postgresql database in user-space.
Databases are packed into a tarball and stored in the user-history.

These tools are based on https://github.com/solidsnack/pglite to interact with postgresql in user-space.
76 changes: 76 additions & 0 deletions tools/pg_tools/macros.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0"?>
<macros>
<xml name="inputs_outputs">
<inputs>
<param format="tabular" help="" label="Input tabular dataset" name="in_file" type="data" />
<yield />
</inputs>
<outputs>
<data format="tabular" name="out_file" label="${tool.name} on ${on_string}" />
</outputs>
</xml>

<xml name="requirements">
<requirements>
<requirement type="package" version="@PG_VERSION@">postgresql</requirement>
<requirement type="package" version="0.1">pglite</requirement>
</requirements>
</xml>

<token name="@PG_VERSION@">11.2</token>

<token name="@HELP_FOOTER@">
The postgresql tools, are using a postgresql database in user-space. Databases are packed into a tarball and stored in the user-history.
</token>

<token name="@UNTAR_INFILE@"><![CDATA[
tar -xjvf '$infile' &&
export PWD=`pwd` &&
sed -i.bak "s|unix_socket_directories.*|unix_socket_directories = '\$PWD/postgresql/'|" ./postgresql/db/postgresql.conf
]]>
</token>

<token name="@PG_SETUP@"><![CDATA[
pglite setup -d ./postgresql &&
@PG_START@
]]>
</token>

<token name="@PSQL@"><![CDATA[
psql "\$(pglite url -d ./postgresql)"
]]>
</token>

<token name="@STATUS_RUNNING@"><![CDATA[
timeout 60 bash -c 'until pglite status -d ./postgresql | grep -F -q "server is running"; do sleep 1; done' &&
pglite status -d ./postgresql &&
timeout 60 bash -c 'until ls -la ./postgresql | grep -F -q ".s.PGSQL.5432"; do sleep 1; done'
&& pglite status -d ./postgresql
]]>
</token>

<token name="@STOPPED@"><![CDATA[
timeout 60 bash -c 'until pglite status -d ./postgresql | grep -F -q "no server running"; do sleep 1; done'
]]>
</token>

<token name="@PG_START@"><![CDATA[
pglite start -d ./postgresql &&
@STATUS_RUNNING@
]]>
</token>

<token name="@PG_STOP@"><![CDATA[
pglite stop -d ./postgresql &&
@STOPPED@
]]>
</token>

<token name="@ARCHIVE_DATABASE@"><![CDATA[
tar -cvjf postgresql_out.tar.bz2 postgresql
]]>
</token>
<xml name="citations">
<citations></citations>
</xml>
</macros>
41 changes: 41 additions & 0 deletions tools/pg_tools/pg-dump.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<tool id="pg_dump" name="Dump" version="@PG_VERSION@">
<description>postgres database</description>
<macros>
<import>macros.xml</import>
</macros>
<expand macro="requirements" />
<command detect_errors="aggressive"><![CDATA[
@UNTAR_INFILE@ &&
@PG_START@ &&
pg_dump "\$(pglite url -d ./postgresql)" $no_owner -f '$outfile' &&
@PG_STOP@
]]>
</command>
<inputs>
<param name="infile" type="data" format="postgresql" label="Input database" />
<param name="no_owner" type="boolean" truevalue="--no-owner" falsevalue="" value="--no-owner"
label="Do not emit owner statements"
help="Do not output commands to set ownership of objects to match the original database. This is turned on by default because it is expected that the pg_dump tool will be used when exporting the data for use in a system external to Galaxy. Thus the authorization statements are likely to be different so we remove this."/>
</inputs>
<outputs>
<data format="txt" name="outfile" />
</outputs>
<tests>
<test>
<param value="pg_import_result1.pg.tar.bz2" name="infile"/>
<output file="init-galaxy-db.sql.in" name="outfile" ftype="txt" />
</test>
</tests>
<help>
<![CDATA[
pg_dump
-------

This tool produces a SQL dump of the database file, compatible with import into external postgres databases.

@HELP_FOOTER@

]]>
</help>
<expand macro="citations" />
</tool>
36 changes: 36 additions & 0 deletions tools/pg_tools/pg-import.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<tool id="pg_import" name="Postgresql" version="@PG_VERSION@">
<description>import sql dump</description>
<macros>
<import>macros.xml</import>
</macros>
<expand macro="requirements" />
<command detect_errors="aggressive"><![CDATA[
@PG_SETUP@ &&
ls -l ./postgresql &&
@PSQL@ -f '$infile' -L logfile.log &&
@PG_STOP@ &&
@ARCHIVE_DATABASE@ &&
cat logfile.log
]]>
</command>
<inputs>
<param format="txt" name="infile" type="data" label="Input SQL dump" />
</inputs>
<outputs>
<data format="postgresql" name="outfile" from_work_dir="postgresql_out.tar.bz2" />
</outputs>
<tests>
<test>
<param name="infile" value="init-galaxy-db.sql.in" ftype="txt" />
<output file="pg_import_result1.pg.tar.bz2" name="outfile" ftype="postgresql" compare="sim_size" delta="200000" />
</test>
</tests>
<help>
<![CDATA[

@HELP_FOOTER@

]]>
</help>
<expand macro="citations" />
</tool>
55 changes: 55 additions & 0 deletions tools/pg_tools/pg-query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<tool id="pg_query" name="Query" version="@PG_VERSION@">
<description>postgres database</description>
<macros>
<import>macros.xml</import>
</macros>
<expand macro="requirements" />
<command detect_errors="aggressive"><![CDATA[
@UNTAR_INFILE@ &&
@PG_START@ &&
##ls -l ./postgresql &&
a=" with CSV HEADER DELIMITER ' ';" &&
echo "COPY ($query) TO STDOUT"\$a | @PSQL@ -L logfile.log > '$outfile' &&
@PG_STOP@
&&
cat logfile.log
]]>
</command>
<inputs>
<param name="infile" type="data" format="postgresql" label="Input database" />
<param name="query" type="text" area="True" size="5x50" label="The query to be issued to the database">
<sanitizer invalid_char="">
<valid initial="string.printable">
<remove value="&apos;" />
</valid>
<mapping initial="none">
<add source="&apos;" target="&apos;&quot;&apos;&quot;&apos;" />
</mapping>
</sanitizer>
<validator type="expression" message="Query cannot be empty">value.strip()</validator>
</param>
</inputs>
<outputs>
<data format="txt" name="outfile" />
</outputs>
<tests>
<test>
<param name="infile" value="pg_import_result1.pg.tar.bz2" ftype="postgresql" />
<param name="query" value="select version from migrate_version" />
<output file="pg_query_result1.txt" name="outfile" />
</test>
<test>
<param name="infile" value="pg_import_result1.pg.tar.bz2" ftype="postgresql" />
<param name="query" value="select * from galaxy_user" />
<output file="pg_query_result2.txt" name="outfile" />
</test>
</tests>
<help>
<![CDATA[

@HELP_FOOTER@

]]>
</help>
<expand macro="citations" />
</tool>
Loading