[{"id":1764878,"web_url":"http://patchwork.ozlabs.org/comment/1764878/","msgid":"<1504808917.6238.13.camel@that.guru>","list_archive_url":null,"date":"2017-09-07T18:28:37","subject":"Re: [PATCH 3/4] Support testing with PostgreSQL","submitter":{"id":69991,"url":"http://patchwork.ozlabs.org/api/people/69991/","name":"Stephen Finucane","email":"stephen@that.guru"},"content":"On Mon, 2017-09-04 at 01:14 +1000, Daniel Axtens wrote:\n> This allows us to easily test against PostgreSQL using the same\n> tooling we normally use. This is helpful in (for example) shaking\n> out the test failures that were observed on ozlabs.org\n> \n> To use it:\n>   docker-compose -f docker-compose-pg.yml <usual arguments>\n> \n> (You may find it necessary to do a 'docker-compose down' first,\n> depending on what state the system is in and what command you're\n> running.)\n> \n> Signed-off-by: Daniel Axtens <dja@axtens.net>\n\nSome comments below.\n\n> ---\n>  docker-compose-pg.yml      | 30 ++++++++++++++++++++++++++\n>  requirements-test.txt      |  3 ++-\n>  tools/docker/Dockerfile    |  2 +-\n>  tools/docker/entrypoint.sh | 53 +++++++++++++++++++++++++++++++++++++-------\n> --\n>  4 files changed, 76 insertions(+), 12 deletions(-)\n>  create mode 100644 docker-compose-pg.yml\n> \n> diff --git a/docker-compose-pg.yml b/docker-compose-pg.yml\n> new file mode 100644\n> index 000000000000..34900418375e\n> --- /dev/null\n> +++ b/docker-compose-pg.yml\n> @@ -0,0 +1,30 @@\n> +# the version of docker-compose shipped in ubuntu 16.04 is\n> +# 1.5.2, which doesn't support version 2 syntax. Yay!\n> +# also, v1 doesn't support explicit build args, so if you're not\n> +# uid 1000, you will either need to manually hack the Dockerfile\n> +# or upgrade to v2 and use the build-arg to override it.\n\nOnly 7 months to 18.04, guys!\n\n> +\n> +db:\n> +  image: postgres\n\nAny particular version needed?\n\n> +  environment:\n> +    - POSTGRES_PASSWORD=super_sekrit_postgres_passwd\n> +  volumes:\n> +    - ./tools/docker/db/postdata:/var/lib/postgresql/data\n> +\n> +web:\n> +  build: .\n> +  dockerfile: ./tools/docker/Dockerfile\n> +  command: python3 manage.py runserver 0.0.0.0:8000\n> +  volumes:\n> +    - .:/home/patchwork/patchwork/\n> +  ports:\n> +    - \"8000:8000\"\n> +  links:\n> +    - db\n> +  environment:\n> +    - PGPASSWORD=super_sekrit_postgres_passwd\n> +    - PW_TEST_DB_HOST=db\n> +    - PW_TEST_DB_PORT=5432\n> +    - PW_TEST_DB_TYPE=postgres\n> +    - PW_TEST_DB_USER=postgres\n> +    - PW_TEST_DB_PASS=super_sekrit_postgres_passwd\n\nAny harm in just using 'password', like we do for mysql. It is for dev\npurposes, after all.\n\n> diff --git a/requirements-test.txt b/requirements-test.txt\n> index cead336c7c77..141cf661663d 100644\n> --- a/requirements-test.txt\n> +++ b/requirements-test.txt\n> @@ -1,4 +1,5 @@\n> -mysqlclient>=1.3,<1.4  # replace this with psycopg2 for a PostgreSQL backend\n> +mysqlclient>=1.3,<1.4\n> +psycopg2>=2.7,<2.8\n\nAre you sure this works? Last I checked, you needed PostgreSQL installed for\npsycopg2 to install correctly (think I spotted it when adding Vagrant support).\nCould you try rebuilding the MySQL-based container to validate this?\n\n>  django-debug-toolbar==1.8\n>  python-dateutil>2.0,<3.0\n>  selenium>=3.0,<4.0\n> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile\n> index ff05707a6049..946c646188e5 100644\n> --- a/tools/docker/Dockerfile\n> +++ b/tools/docker/Dockerfile\n> @@ -21,7 +21,7 @@ RUN apt-get update -qq && \\\n>      python3.5-dev python3-pip python3-setuptools python3-wheel \\\n>      python3.4-dev findutils=4.4.2-7 \\\n>      libmysqlclient-dev mysql-client curl unzip xvfb chromium-chromedriver \\\n> -    chromium-browser build-essential git && \\\n> +    chromium-browser build-essential git postgresql-client && \\\n\n...although maybe this resolves the issue. I'll wait to see if you tested this\n:)\n\n>      ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/\n>  \n>  # User\n> diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh\n> index 2f413b02e83e..4b656adaeb35 100755\n> --- a/tools/docker/entrypoint.sh\n> +++ b/tools/docker/entrypoint.sh\n> @@ -1,13 +1,31 @@\n>  #!/bin/bash\n> -set -euo pipefail\n> +set -eo pipefail\n> +\n> +if [ x${PW_TEST_DB_TYPE} = x ]; then\n> +    PW_TEST_DB_TYPE=mysql\n> +fi\n> +\n> +set -u\n\nWhy do we need to move the '-u' (undefined variable?) down here? Does Bash not\nprovide an equivalent of Python's 'getattr(ATTR, DEFAULT)'?\n\n>  \n>  # functions\n>  \n>  test_db_connection() {\n> -    mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping >\n> /dev/null 2> /dev/null\n> +    if [ ${PW_TEST_DB_TYPE} = \"postgres\" ]; then\n> +\techo ';' | psql -h $PW_TEST_DB_HOST -U postgres 2> /dev/null >\n> /dev/null\n> +    else\n> +\tmysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping\n> > /dev/null 2> /dev/null\n> +    fi\n>  }\n\nLooks good.\n\n> -reset_data() {\n> +test_database() {\n> +    if [ ${PW_TEST_DB_TYPE} = \"postgres\" ]; then\n> +\techo ';' | psql -h $PW_TEST_DB_HOST -U postgres patchwork 2>\n> /dev/null\n> +    else\n> +\techo ';' | mysql -h $PW_TEST_DB_HOST -u patchwork -ppassword\n> patchwork 2> /dev/null\n> +    fi\n> +}\n> +\n\nLooks good.\n\n> +reset_data_mysql() {\n>      mysql -u$db_user -p$db_pass -h $PW_TEST_DB_HOST << EOF\n>  DROP DATABASE IF EXISTS patchwork;\n>  CREATE DATABASE patchwork CHARACTER SET utf8;\n> @@ -15,6 +33,21 @@ GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY\n> 'password';\n>  GRANT ALL PRIVILEGES ON test_patchwork.* TO 'patchwork'@'%';\n>  FLUSH PRIVILEGES;\n>  EOF\n> +}\n> +\n> +reset_data_postgres() {\n> +    psql -h $PW_TEST_DB_HOST -U postgres <<EOF\n> +DROP DATABASE IF EXISTS patchwork;\n> +CREATE DATABASE patchwork WITH ENCODING = 'UTF8';\n> +EOF\n> +}\n> +\n> +reset_data() {\n> +    if [ x${PW_TEST_DB_TYPE} = x\"postgres\" ]; then\n> +\treset_data_postgres\n> +    else\n> +\treset_data_mysql\n> +    fi\n>  \n>      # load initial data\n>      python3 $PROJECT_HOME/manage.py migrate #> /dev/null\n> @@ -46,13 +79,13 @@ for x in /tmp/requirements-*.txt; do\n>      fi\n>  done\n>  \n> -# check if mysql is connected\n> +# check if db is connected\n>  if ! test_db_connection; then\n> -    echo \"MySQL seems not to be connected, or the patchwork user is broken\"\n> -    echo \"MySQL may still be starting. Waiting 5 seconds.\"\n> +    echo \"The database seems not to be connected, or the patchwork user is\n> broken\"\n> +    echo \"MySQL/Postgres may still be starting. Waiting 5 seconds.\"\n>      sleep 5\n>      if ! test_db_connection; then\n> -        echo \"Still cannot connect to MySQL.\"\n> +        echo \"Still cannot connect to database.\"\n>          echo \"Maybe you are starting the db for the first time. Waiting up\n> to 60 seconds.\"\n>          for i in {0..9}; do\n>              sleep 5\n> @@ -61,19 +94,19 @@ if ! test_db_connection; then\n>              fi\n>          done\n>          if ! test_db_connection; then\n> -            echo \"Still cannot connect to MySQL. Giving up.\"\n> +            echo \"Still cannot connect to database. Giving up.\"\n>              echo \"Are you using docker-compose? If not, have you set up the\n> link correctly?\"\n>              exit 1\n>          fi\n>      fi\n>  fi\n>  \n> -# rebuild mysql db\n> +# rebuild db\n>  # do this on --reset or if the db doesn't exist\n>  if [[ \"$1\" == \"--reset\" ]]; then\n>      shift\n>      reset_data\n> -elif ! ( echo ';' | mysql -h db -u patchwork -ppassword patchwork 2>\n> /dev/null ); then\n> +elif ! test_database; then\n>      reset_data\n>  fi\n>  \n\nYup, all this is fine by me.\n\nStephen","headers":{"Return-Path":"<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","patchwork@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","patchwork@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xp89l1q5Kz9s7C\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 04:29:15 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xp89k5NnvzDrWs\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 04:29:14 +1000 (AEST)","from duck.birch.relay.mailchannels.net\n\t(duck.birch.relay.mailchannels.net [23.83.209.52])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xp89B3YYJzDrWj\n\tfor <patchwork@lists.ozlabs.org>;\n\tFri,  8 Sep 2017 04:28:45 +1000 (AEST)","from relay.mailchannels.net (localhost [127.0.0.1])\n\tby relay.mailchannels.net (Postfix) with ESMTP id 3CEFD201A8F;\n\tThu,  7 Sep 2017 18:28:42 +0000 (UTC)","from one.mxroute.com (unknown [100.96.147.9])\n\t(Authenticated sender: mxroute)\n\tby relay.mailchannels.net (Postfix) with ESMTPA id AF863201C0E;\n\tThu,  7 Sep 2017 18:28:41 +0000 (UTC)","from one.mxroute.com (one-outgoing.mxroute.com [172.20.107.195])\n\t(using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384)\n\tby 0.0.0.0:2500 (trex/5.9.14); Thu, 07 Sep 2017 18:28:42 +0000"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" (0-bit key;\n\tunprotected) header.d=that.guru header.i=@that.guru\n\theader.b=\"BXClZwxI\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" (0-bit key;\n\tunprotected) header.d=that.guru header.i=@that.guru\n\theader.b=\"BXClZwxI\"; dkim-atps=neutral","ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=that.guru\n\t(client-ip=23.83.209.52; helo=duck.birch.relay.mailchannels.net;\n\tenvelope-from=stephen@that.guru; receiver=<UNKNOWN>)","lists.ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" (0-bit key;\n\tunprotected) header.d=that.guru header.i=@that.guru\n\theader.b=\"BXClZwxI\"; dkim-atps=neutral"],"X-Sender-Id":["mxroute|x-authuser|stephen@that.guru","mxroute|x-authuser|stephen@that.guru"],"X-MC-Relay":"Neutral","X-MailChannels-SenderId":"mxroute|x-authuser|stephen@that.guru","X-MailChannels-Auth-Id":"mxroute","X-White-Imminent":"5849ebd472f28062_1504808922050_2988631574","X-MC-Loop-Signature":"1504808922050:4209526676","X-MC-Ingress-Time":"1504808922050","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru;\n\ts=default;\n\th=Content-Transfer-Encoding:Mime-Version:Content-Type:References:\n\tIn-Reply-To:Date:To:From:Subject:Message-ID:Sender:Reply-To:Cc:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=wbYxuGWfiPQfzzUCpJWC/xFCnBWoZVdZ2TFLc5ciB2E=;\n\tb=BXClZwxI4Wl8HYLFWk1GtT9YSB\n\tGJ2SsEOYOyySPG+FF0NoHDWhg4hl/V8j5FCpq1VnQj9bGdDBri6w/2ewoK5T9P3U6ETMJbsv0IQB/\n\tpaO4rHU+BpezHNWqCOCRRNVUjXU7DpgQyPybdnz4D9YGsttkiyYjbg2TaDpBfbjM8llh9EcCNjyzN\n\tgmbCF9MZ2C1OyXYcQeTUSH+C5FGIoJKPDSCIKUXBvFCAt8M+iSr18nWnSNq9fWpK1HrTAb9vTALS7\n\tPReONe5r7KODwLnrD3bj6t3bhNm/90MYpAd63XaTJ8EfCwH0Eu0ghDlY6jMt7U5Rv9oRn98TH1wSy\n\tWCJUP/kQ==;","Message-ID":"<1504808917.6238.13.camel@that.guru>","Subject":"Re: [PATCH 3/4] Support testing with PostgreSQL","From":"Stephen Finucane <stephen@that.guru>","To":"Daniel Axtens <dja@axtens.net>, patchwork@lists.ozlabs.org","Date":"Thu, 07 Sep 2017 19:28:37 +0100","In-Reply-To":"<20170903151444.25660-4-dja@axtens.net>","References":"<20170903151444.25660-1-dja@axtens.net>\n\t<20170903151444.25660-4-dja@axtens.net>","X-Mailer":"Evolution 3.24.5 (3.24.5-1.fc26) ","Mime-Version":"1.0","X-AuthUser":"stephen@that.guru","X-BeenThere":"patchwork@lists.ozlabs.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"Patchwork development <patchwork.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/patchwork/>","List-Post":"<mailto:patchwork@lists.ozlabs.org>","List-Help":"<mailto:patchwork-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org","Sender":"\"Patchwork\"\n\t<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"}},{"id":1775390,"web_url":"http://patchwork.ozlabs.org/comment/1775390/","msgid":"<87mv5hy9pf.fsf@linkitivity.dja.id.au>","list_archive_url":null,"date":"2017-09-26T11:34:52","subject":"Re: [PATCH 3/4] Support testing with PostgreSQL","submitter":{"id":65792,"url":"http://patchwork.ozlabs.org/api/people/65792/","name":"Daniel Axtens","email":"dja@axtens.net"},"content":"Stephen Finucane <stephen@that.guru> writes:\n\n> On Mon, 2017-09-04 at 01:14 +1000, Daniel Axtens wrote:\n>> This allows us to easily test against PostgreSQL using the same\n>> tooling we normally use. This is helpful in (for example) shaking\n>> out the test failures that were observed on ozlabs.org\n>> \n>> To use it:\n>>   docker-compose -f docker-compose-pg.yml <usual arguments>\n>> \n>> (You may find it necessary to do a 'docker-compose down' first,\n>> depending on what state the system is in and what command you're\n>> running.)\n>> \n>> Signed-off-by: Daniel Axtens <dja@axtens.net>\n>\n> Some comments below.\n>\n>> ---\n>>  docker-compose-pg.yml      | 30 ++++++++++++++++++++++++++\n>>  requirements-test.txt      |  3 ++-\n>>  tools/docker/Dockerfile    |  2 +-\n>>  tools/docker/entrypoint.sh | 53 +++++++++++++++++++++++++++++++++++++-------\n>> --\n>>  4 files changed, 76 insertions(+), 12 deletions(-)\n>>  create mode 100644 docker-compose-pg.yml\n>> \n>> diff --git a/docker-compose-pg.yml b/docker-compose-pg.yml\n>> new file mode 100644\n>> index 000000000000..34900418375e\n>> --- /dev/null\n>> +++ b/docker-compose-pg.yml\n>> @@ -0,0 +1,30 @@\n>> +# the version of docker-compose shipped in ubuntu 16.04 is\n>> +# 1.5.2, which doesn't support version 2 syntax. Yay!\n>> +# also, v1 doesn't support explicit build args, so if you're not\n>> +# uid 1000, you will either need to manually hack the Dockerfile\n>> +# or upgrade to v2 and use the build-arg to override it.\n>\n> Only 7 months to 18.04, guys!\n>\n>> +\n>> +db:\n>> +  image: postgres\n>\n> Any particular version needed?\n\nThe default is pretty good, but I'll stick it to 9.6 for now.\n>\n>> +  environment:\n>> +    - POSTGRES_PASSWORD=super_sekrit_postgres_passwd\n>> +  volumes:\n>> +    - ./tools/docker/db/postdata:/var/lib/postgresql/data\n>> +\n>> +web:\n>> +  build: .\n>> +  dockerfile: ./tools/docker/Dockerfile\n>> +  command: python3 manage.py runserver 0.0.0.0:8000\n>> +  volumes:\n>> +    - .:/home/patchwork/patchwork/\n>> +  ports:\n>> +    - \"8000:8000\"\n>> +  links:\n>> +    - db\n>> +  environment:\n>> +    - PGPASSWORD=super_sekrit_postgres_passwd\n>> +    - PW_TEST_DB_HOST=db\n>> +    - PW_TEST_DB_PORT=5432\n>> +    - PW_TEST_DB_TYPE=postgres\n>> +    - PW_TEST_DB_USER=postgres\n>> +    - PW_TEST_DB_PASS=super_sekrit_postgres_passwd\n>\n> Any harm in just using 'password', like we do for mysql. It is for dev\n> purposes, after all.\n\nWill do in v2.\n\n>\n>> diff --git a/requirements-test.txt b/requirements-test.txt\n>> index cead336c7c77..141cf661663d 100644\n>> --- a/requirements-test.txt\n>> +++ b/requirements-test.txt\n>> @@ -1,4 +1,5 @@\n>> -mysqlclient>=1.3,<1.4  # replace this with psycopg2 for a PostgreSQL backend\n>> +mysqlclient>=1.3,<1.4\n>> +psycopg2>=2.7,<2.8\n>\n> Are you sure this works? Last I checked, you needed PostgreSQL installed for\n> psycopg2 to install correctly (think I spotted it when adding Vagrant support).\n> Could you try rebuilding the MySQL-based container to validate this?\n>\nHave checked locally and on Travis.\n\n>>  django-debug-toolbar==1.8\n>>  python-dateutil>2.0,<3.0\n>>  selenium>=3.0,<4.0\n>> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile\n>> index ff05707a6049..946c646188e5 100644\n>> --- a/tools/docker/Dockerfile\n>> +++ b/tools/docker/Dockerfile\n>> @@ -21,7 +21,7 @@ RUN apt-get update -qq && \\\n>>      python3.5-dev python3-pip python3-setuptools python3-wheel \\\n>>      python3.4-dev findutils=4.4.2-7 \\\n>>      libmysqlclient-dev mysql-client curl unzip xvfb chromium-chromedriver \\\n>> -    chromium-browser build-essential git && \\\n>> +    chromium-browser build-essential git postgresql-client && \\\n>\n> ...although maybe this resolves the issue. I'll wait to see if you tested this\n> :)\n>\nIt does indeed, and I have indeed :)\n\n>>      ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/\n>>  \n>>  # User\n>> diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh\n>> index 2f413b02e83e..4b656adaeb35 100755\n>> --- a/tools/docker/entrypoint.sh\n>> +++ b/tools/docker/entrypoint.sh\n>> @@ -1,13 +1,31 @@\n>>  #!/bin/bash\n>> -set -euo pipefail\n>> +set -eo pipefail\n>> +\n>> +if [ x${PW_TEST_DB_TYPE} = x ]; then\n>> +    PW_TEST_DB_TYPE=mysql\n>> +fi\n>> +\n>> +set -u\n>\n> Why do we need to move the '-u' (undefined variable?) down here? Does Bash not\n> provide an equivalent of Python's 'getattr(ATTR, DEFAULT)'?\n>\n\n-u causes the script to exit if an undefined variable is referenced,\nrather than just returning the empty string. So, if PW_TEST_DB_TYPE is\nunset the script will error out.\n\nThere is a bashism that might allow us to get around this, I'll check.\n(I use http://redsymbol.net/articles/unofficial-bash-strict-mode/ and I\nthink it has a section on this.)\n\nRegards,\nDaniel\n\n>>  \n>>  # functions\n>>  \n>>  test_db_connection() {\n>> -    mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping >\n>> /dev/null 2> /dev/null\n>> +    if [ ${PW_TEST_DB_TYPE} = \"postgres\" ]; then\n>> +\techo ';' | psql -h $PW_TEST_DB_HOST -U postgres 2> /dev/null >\n>> /dev/null\n>> +    else\n>> +\tmysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping\n>> > /dev/null 2> /dev/null\n>> +    fi\n>>  }\n>\n> Looks good.\n>\n>> -reset_data() {\n>> +test_database() {\n>> +    if [ ${PW_TEST_DB_TYPE} = \"postgres\" ]; then\n>> +\techo ';' | psql -h $PW_TEST_DB_HOST -U postgres patchwork 2>\n>> /dev/null\n>> +    else\n>> +\techo ';' | mysql -h $PW_TEST_DB_HOST -u patchwork -ppassword\n>> patchwork 2> /dev/null\n>> +    fi\n>> +}\n>> +\n>\n> Looks good.\n>\n>> +reset_data_mysql() {\n>>      mysql -u$db_user -p$db_pass -h $PW_TEST_DB_HOST << EOF\n>>  DROP DATABASE IF EXISTS patchwork;\n>>  CREATE DATABASE patchwork CHARACTER SET utf8;\n>> @@ -15,6 +33,21 @@ GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY\n>> 'password';\n>>  GRANT ALL PRIVILEGES ON test_patchwork.* TO 'patchwork'@'%';\n>>  FLUSH PRIVILEGES;\n>>  EOF\n>> +}\n>> +\n>> +reset_data_postgres() {\n>> +    psql -h $PW_TEST_DB_HOST -U postgres <<EOF\n>> +DROP DATABASE IF EXISTS patchwork;\n>> +CREATE DATABASE patchwork WITH ENCODING = 'UTF8';\n>> +EOF\n>> +}\n>> +\n>> +reset_data() {\n>> +    if [ x${PW_TEST_DB_TYPE} = x\"postgres\" ]; then\n>> +\treset_data_postgres\n>> +    else\n>> +\treset_data_mysql\n>> +    fi\n>>  \n>>      # load initial data\n>>      python3 $PROJECT_HOME/manage.py migrate #> /dev/null\n>> @@ -46,13 +79,13 @@ for x in /tmp/requirements-*.txt; do\n>>      fi\n>>  done\n>>  \n>> -# check if mysql is connected\n>> +# check if db is connected\n>>  if ! test_db_connection; then\n>> -    echo \"MySQL seems not to be connected, or the patchwork user is broken\"\n>> -    echo \"MySQL may still be starting. Waiting 5 seconds.\"\n>> +    echo \"The database seems not to be connected, or the patchwork user is\n>> broken\"\n>> +    echo \"MySQL/Postgres may still be starting. Waiting 5 seconds.\"\n>>      sleep 5\n>>      if ! test_db_connection; then\n>> -        echo \"Still cannot connect to MySQL.\"\n>> +        echo \"Still cannot connect to database.\"\n>>          echo \"Maybe you are starting the db for the first time. Waiting up\n>> to 60 seconds.\"\n>>          for i in {0..9}; do\n>>              sleep 5\n>> @@ -61,19 +94,19 @@ if ! test_db_connection; then\n>>              fi\n>>          done\n>>          if ! test_db_connection; then\n>> -            echo \"Still cannot connect to MySQL. Giving up.\"\n>> +            echo \"Still cannot connect to database. Giving up.\"\n>>              echo \"Are you using docker-compose? If not, have you set up the\n>> link correctly?\"\n>>              exit 1\n>>          fi\n>>      fi\n>>  fi\n>>  \n>> -# rebuild mysql db\n>> +# rebuild db\n>>  # do this on --reset or if the db doesn't exist\n>>  if [[ \"$1\" == \"--reset\" ]]; then\n>>      shift\n>>      reset_data\n>> -elif ! ( echo ';' | mysql -h db -u patchwork -ppassword patchwork 2>\n>> /dev/null ); then\n>> +elif ! test_database; then\n>>      reset_data\n>>  fi\n>>  \n>\n> Yup, all this is fine by me.\n>\n> Stephen","headers":{"Return-Path":"<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","patchwork@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","patchwork@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y1f7L3qssz9tXf\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 21:37:02 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3y1f7L2cxJzDsPs\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 21:37:02 +1000 (AEST)","from mail-pg0-x244.google.com (mail-pg0-x244.google.com\n\t[IPv6:2607:f8b0:400e:c05::244])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3y1f562f5vzDsPf\n\tfor <patchwork@lists.ozlabs.org>;\n\tTue, 26 Sep 2017 21:35:05 +1000 (AEST)","by mail-pg0-x244.google.com with SMTP id i130so6608605pgc.0\n\tfor <patchwork@lists.ozlabs.org>;\n\tTue, 26 Sep 2017 04:35:05 -0700 (PDT)","from localhost (114-198-116-25.dyn.iinet.net.au. [114.198.116.25])\n\tby smtp.gmail.com with ESMTPSA id\n\t70sm17340612pfh.63.2017.09.26.04.34.55\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 26 Sep 2017 04:34:56 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"mLhYfdEV\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"mLhYfdEV\"; dkim-atps=neutral","ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=axtens.net\n\t(client-ip=2607:f8b0:400e:c05::244; helo=mail-pg0-x244.google.com;\n\tenvelope-from=dja@axtens.net; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"mLhYfdEV\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google;\n\th=from:to:subject:in-reply-to:references:date:message-id:mime-version;\n\tbh=bpNzA17Pi6nuYgi8PB1kFZqDj299kVlE+WkDadTZc30=;\n\tb=mLhYfdEVUaGb6P4PcfBXfNmEBVVBYpeqB3fQtc22EeUY3O9ft9W7ODuSb+SnULd5+O\n\t0rPUeP1emHoC2R9PVDVc3qLClJ75cj5P70e8XIU4POLvnjsNNP/3oIZDMWBgPkvCOQxW\n\t8PMZ6oAUP5LZ/ISX0E56eFkY50b2WRKBpUXi4=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:in-reply-to:references:date\n\t:message-id:mime-version;\n\tbh=bpNzA17Pi6nuYgi8PB1kFZqDj299kVlE+WkDadTZc30=;\n\tb=VeWZTwCFZ8QreJNDbPWsStHJBuV0syomTze53NgI9qG1tkohtjHaLgspuUQIQfuXcm\n\tb647k4c8VtYWfBQOlFOrKQFSUpQUGaAUlmzQwXrx0ErrUclKXqu8ekpEL9LT/98mqiwP\n\t6dgSmwjJjxYBGAR3aHJ6nN6v18HGfi3V0YmuCXIypaU8LeBpISd3zHdenZtDDYe+UzmQ\n\tZb2vTgWJR784rHgw9xfjnsVkyWhNrtAqyw0KUd27DLtzgai+6yiNpwoBSp09zWNqq8NN\n\tdGyjYvDKmmkcf450QzbVf2uYMY/EJphH34pFYo46IHED2E8ar6z2PZwfhfLKYHz+G83d\n\tMKlw==","X-Gm-Message-State":"AHPjjUgMMiNYU/xhOO1uTaeOgznTx9aFQgZtGE0tClHArZCmKpsl1B1N\n\tp+hswXO5Ail8nh7X4xhhIN6xGKhgVL0=","X-Google-Smtp-Source":"AOwi7QD9s0ud8J+/khi/n75n2O8EbK+Mhddmvyjl7gaEWQBp4PcoaR9Cb/+LQuj0YhUucYKDJiDq4A==","X-Received":"by 10.99.147.82 with SMTP id w18mr10846271pgm.308.1506425703609; \n\tTue, 26 Sep 2017 04:35:03 -0700 (PDT)","From":"Daniel Axtens <dja@axtens.net>","To":"Stephen Finucane <stephen@that.guru>, patchwork@lists.ozlabs.org","Subject":"Re: [PATCH 3/4] Support testing with PostgreSQL","In-Reply-To":"<1504808917.6238.13.camel@that.guru>","References":"<20170903151444.25660-1-dja@axtens.net>\n\t<20170903151444.25660-4-dja@axtens.net>\n\t<1504808917.6238.13.camel@that.guru>","Date":"Tue, 26 Sep 2017 21:34:52 +1000","Message-ID":"<87mv5hy9pf.fsf@linkitivity.dja.id.au>","MIME-Version":"1.0","X-BeenThere":"patchwork@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Patchwork development <patchwork.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/patchwork/>","List-Post":"<mailto:patchwork@lists.ozlabs.org>","List-Help":"<mailto:patchwork-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org","Sender":"\"Patchwork\"\n\t<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"}}]