Skip to content

Commit

Permalink
add postgresql support to docker, try catch for postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
binux committed Sep 29, 2015
1 parent 8866498 commit 583dfd1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER binux <[email protected]>
# install python
RUN apt-get update && \
apt-get install -y python python-dev python-distribute python-pip && \
apt-get install -y libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml python-mysqldb
apt-get install -y libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml python-mysqldb libpq-dev

# install requirements
ADD requirements.txt /opt/pyspider/requirements.txt
Expand Down
8 changes: 6 additions & 2 deletions pyspider/database/sqlalchemy/projectdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import six
import time
import sqlalchemy.exc

from sqlalchemy import create_engine, MetaData, Table, Column, String, Float, Text
from sqlalchemy.engine.url import make_url
Expand Down Expand Up @@ -41,8 +42,11 @@ def __init__(self, url):
if self.url.database:
database = self.url.database
self.url.database = None
engine = create_engine(self.url, convert_unicode=False)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % database)
try:
engine = create_engine(self.url, convert_unicode=False)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % database)
except sqlalchemy.exc.OperationalError:
pass
self.url.database = database
self.engine = create_engine(url, convert_unicode=False)
self.table.create(self.engine, checkfirst=True)
Expand Down
8 changes: 6 additions & 2 deletions pyspider/database/sqlalchemy/resultdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import six
import time
import json
import sqlalchemy.exc

from sqlalchemy import (create_engine, MetaData, Table, Column,
String, Float, LargeBinary)
Expand Down Expand Up @@ -40,8 +41,11 @@ def __init__(self, url):
if self.url.database:
database = self.url.database
self.url.database = None
engine = create_engine(self.url, convert_unicode=True)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % database)
try:
engine = create_engine(self.url, convert_unicode=True)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % database)
except sqlalchemy.exc.OperationalError:
pass
self.url.database = database
self.engine = create_engine(url, convert_unicode=True)

Expand Down
8 changes: 6 additions & 2 deletions pyspider/database/sqlalchemy/taskdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import six
import time
import json
import sqlalchemy.exc

from sqlalchemy import (create_engine, MetaData, Table, Column, Index,
Integer, String, Float, LargeBinary, func)
Expand Down Expand Up @@ -46,8 +47,11 @@ def __init__(self, url):
if self.url.database:
database = self.url.database
self.url.database = None
engine = create_engine(self.url, convert_unicode=True)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % database)
try:
engine = create_engine(self.url, convert_unicode=True)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % database)
except sqlalchemy.exc.OperationalError:
pass
self.url.database = database
self.engine = create_engine(self.url, convert_unicode=True)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ six
amqp>=1.3.0
redis
kombu
psycopg2
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'SQLAlchemy>=0.9.7',
'redis',
'kombu',
'psycopg2',
]
if sys.version_info < (3, 0):
extras_require_all.extend([
Expand Down

0 comments on commit 583dfd1

Please sign in to comment.