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

Commit

Permalink
switch to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
miltontony committed Jul 9, 2014
1 parent a1f93bd commit 23cba8f
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 126 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ python:
install:
- "pip install coveralls coverage --use-wheel"
- "pip install -r requirements.pip --use-wheel"
before_script:
- psql -c 'create database mamasbm_test;' -U postgres
script:
- coverage run --source=mamasbm mamasbm/setup.py test
- MAMASBM_TEST_CONNECTION_STRING='postgresql://postgres@localhost:5432/mamasbm_test' coverage run --source=mamasbm mamasbm/setup.py test
after_success:
- coveralls
58 changes: 0 additions & 58 deletions mamasbm/alembic.ini

This file was deleted.

6 changes: 5 additions & 1 deletion mamasbm/development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[alembic]
script_location = migrations
pyramid_config_file = %(here)s/development.ini

[app:main]
use = egg:mamasbm

Expand All @@ -15,7 +19,7 @@ pyramid.includes =
pyramid_debugtoolbar
pyramid_tm

sqlalchemy.url = sqlite:///%(here)s/mamasbm.db
sqlalchemy.url = postgresql://postgres@localhost:5432/mamasbm

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
Expand Down
53 changes: 0 additions & 53 deletions mamasbm/mamasbm/tests.py

This file was deleted.

9 changes: 6 additions & 3 deletions mamasbm/mamasbm/web/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import transaction
from StringIO import StringIO

from mamasbm import main
from pyramid import testing
from unittest import TestCase
from webtest import TestApp

from mamasbm import main
from mamasbm.models import DBSession, Base, Profile
from mamasbm.web.csv_handler import CsvImporter
from mamasbm.web import factory
Expand All @@ -14,12 +14,15 @@
class TestProfilesView(TestCase):
def setUp(self):
self.config = testing.setUp()
self.app = TestApp(main({}, **{'sqlalchemy.url': 'sqlite://'}))
connection_string = os.environ.get(
"MAMASBM_TEST_CONNECTION_STRING", "sqlite://")
self.app = TestApp(main({}, **{'sqlalchemy.url': connection_string}))
Base.metadata.create_all()

def tearDown(self):
DBSession.remove()
testing.tearDown()
Base.metadata.drop_all()

def test_get_profiles_empty(self):
resp = self.app.get('/web/api/profiles.json', status=200)
Expand Down
15 changes: 8 additions & 7 deletions mamasbm/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.
Expand All @@ -41,6 +42,7 @@ def run_migrations_offline():
with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.
Expand All @@ -49,15 +51,15 @@ def run_migrations_online():
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
config.get_section('app:main'),
prefix='sqlalchemy.',
poolclass=pool.NullPool)

connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
connection=connection,
target_metadata=target_metadata
)

try:
with context.begin_transaction():
Expand All @@ -69,4 +71,3 @@ def run_migrations_online():
run_migrations_offline()
else:
run_migrations_online()

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def upgrade():
'message_profiles',
sa.Column('uuid', UUID(), nullable=False),
sa.Column('name', sa.Text(), nullable=True),
sa.Column('profile_id', sa.Integer(), nullable=True),
sa.Column('profile_id', UUID(), nullable=True),
sa.ForeignKeyConstraint(['profile_id'], ['profiles.uuid'], ),
sa.PrimaryKeyConstraint('uuid')
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

from alembic import op
import sqlalchemy as sa
from mamasbm.models import UUID


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('messages', sa.Column('message_profile_id', sa.Integer(), nullable=True))
op.add_column(
'messages', sa.Column('message_profile_id', UUID(), nullable=True))
### end Alembic commands ###


Expand Down
6 changes: 5 additions & 1 deletion mamasbm/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[alembic]
script_location = migrations
pyramid_config_file = %(here)s/production.ini

[app:main]
use = egg:mamasbm

Expand All @@ -14,7 +18,7 @@ pyramid.default_locale_name = en
pyramid.includes =
pyramid_tm

sqlalchemy.url = sqlite:///%(here)s/mamasbm.db
sqlalchemy.url = postgresql://postgres@localhost:5432/mamasbm

[server:main]
use = egg:waitress#main
Expand Down
1 change: 1 addition & 0 deletions requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ waitress
alembic
webtest
cornice
psycopg2
-e mamasbm

0 comments on commit 23cba8f

Please sign in to comment.