Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Wire up postgres storage engine behind a "feature flag".
Browse files Browse the repository at this point in the history
  • Loading branch information
blairboy362 committed Aug 28, 2018
1 parent 1639abc commit e77dd37
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
18 changes: 14 additions & 4 deletions backdrop/read/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..core.flaskutils import generate_request_id
from ..core.response import crossdomain
from ..core.storage.mongo import MongoStorageEngine
from ..core.storage.postgres import PostgresStorageEngine
from ..core.timeutils import as_utc

ENVIRONMENT = getenv("ENVIRONMENT", "development")
Expand All @@ -29,10 +30,19 @@
app.config.from_object(
"backdrop.read.config.{}".format(ENVIRONMENT))

storage = MongoStorageEngine.create(
app.config['DATABASE_URL'],
app.config.get('CA_CERTIFICATE')
)
database_engine = app.config['DATABASE_ENGINE']
database_url = app.config['DATABASE_URL']

storage = None
if database_engine is 'mongo':
storage = MongoStorageEngine.create(
database_url,
app.config.get('CA_CERTIFICATE')
)
elif database_engine is 'postgres':
storage = PostgresStorageEngine(database_url)
else:
raise NotImplementedError('Database engine not implemented "%s"' % database_engine)

admin_api = client.AdminAPI(
app.config['STAGECRAFT_URL'],
Expand Down
3 changes: 3 additions & 0 deletions backdrop/read/config/development.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os

DATABASE_URL = 'mongodb://localhost:27017/backdrop_development'
DATABASE_ENGINE = 'mongo'
LOG_LEVEL = "DEBUG"

STAGECRAFT_URL = 'http://localhost:3103'
Expand Down
1 change: 1 addition & 0 deletions backdrop/read/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

PAAS = load_paas_settings()
DATABASE_URL = PAAS.get('DATABASE_URL')
DATABASE_ENGINE = os.getenv('DATABASE_ENGINE','mongo')
CA_CERTIFICATE = PAAS.get('CA_CERTIFICATE')
STAGECRAFT_URL = os.getenv('STAGECRAFT_URL')
SIGNON_API_USER_TOKEN = os.getenv('SIGNON_API_USER_TOKEN')
Expand Down
1 change: 1 addition & 0 deletions backdrop/read/config/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

PAAS = load_paas_settings()
DATABASE_URL = PAAS.get('DATABASE_URL')
DATABASE_ENGINE = os.getenv('DATABASE_ENGINE','mongo')
CA_CERTIFICATE = PAAS.get('CA_CERTIFICATE')
STAGECRAFT_URL = os.getenv('STAGECRAFT_URL')
SIGNON_API_USER_TOKEN = os.getenv('SIGNON_API_USER_TOKEN')
Expand Down
1 change: 1 addition & 0 deletions backdrop/read/config/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DATABASE_URL = 'mongodb://localhost:27017/backdrop_test'
DATABASE_ENGINE = 'mongo'
LOG_LEVEL = "ERROR"

DATA_SET_RATE_LIMIT = '10000/second'
Expand Down
18 changes: 14 additions & 4 deletions backdrop/write/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..core.errors import ParseError, ValidationError
from ..core.flaskutils import generate_request_id
from ..core.storage.mongo import MongoStorageEngine
from ..core.storage.postgres import PostgresStorageEngine

ENVIRONMENT = getenv("ENVIRONMENT", "development")

Expand All @@ -31,10 +32,19 @@
app.config.from_object(
"backdrop.write.config.{}".format(ENVIRONMENT))

storage = MongoStorageEngine.create(
app.config['DATABASE_URL'],
app.config.get('CA_CERTIFICATE')
)
database_engine = app.config['DATABASE_ENGINE']
database_url = app.config['DATABASE_URL']

storage = None
if database_engine is 'mongo':
storage = MongoStorageEngine.create(
database_url,
app.config.get('CA_CERTIFICATE')
)
elif database_engine is 'postgres':
storage = PostgresStorageEngine(database_url)
else:
raise NotImplementedError('Database engine not implemented "%s"' % database_engine)

admin_api = client.AdminAPI(
app.config['STAGECRAFT_URL'],
Expand Down

0 comments on commit e77dd37

Please sign in to comment.