Skip to content
Browse files

Add in the migration files, config file for testing

  • Loading branch information...
1 parent 7a6ce6d commit aff44654e90833854074b6536e434f10be9056bf @mitechie committed Jun 20, 2012
View
44 Makefile
@@ -59,31 +59,30 @@ $(BOOKIE_INI):
# DATABASE
#
# Need a series of commands to handle migrations
-bookie.db: db_setup
-test_bookie.db: BOOKIE_INI='test.ini'
-test_bookie.db: db_setup db_up
+bookie.db: develop
+ bin/alembic upgrade head
+test_bookie.db:
+ bin/alembic -c test_alembic.ini upgrade head
+
+# The upgade/etc commands are only for the live db. Test databases are
+# expected to be torn down and resetup each time.
.PHONY: db_up
-db_up: develop bookie.db
- $(MIGRATE) upgrade --url=$(SAURL) --repository=migrations
+db_up: bookie.db
+ bin/alembic upgrade head
-# make db_down ver=10
.PHONY: db_down
-db_down: develop bookie.db
- $(MIGRATE) downgrade --url=$(SAURL) --repository=migrations $(ver)
+db_down: bookie.db
+ bin/alembic downgrade
# make db_new desc="This is a new migration"
.PHONY: db_new
-db_new: develop bookie.db
- $(MIGRATE) script --url=$(SAURL) --repository=migrations "$(desc)"
+db_new: bookie.db
+ bin/alembic revision -m "$(desc)"
.PHONY: db_version
-db_version: develop bookie.db
- $(MIGRATE) version --url=$(SAURL) --repository=migrations
-
-.PHONY: db_setup
-db_setup: develop
- $(MIGRATE) version_control --url=$(SAURL) --repository=migrations
+db_version: bookie.db
+ bin/alembic current
.PHONY: first_bookmark
first_bookmark: develop
@@ -125,15 +124,12 @@ deps: venv
test:
$(NOSE) --with-id -x -s bookie/tests
+.PHONY: clean_testdb
+clean_testdb:
+ - rm test_bookie.db
+
.PHONY: builder_test
-builder_test:
- # we hard code the filename because we don't want to accidentally remove
- # the main bookie.db file. We're only cleaning tests.
- if [ -f test_bookie.db ]; then \
- rm test_bookie.db; \
- fi
- $(MIGRATE) version_control --url=$(SAURL) --repository=migrations
- $(MIGRATE) upgrade --url=$(SAURL) --repository=migrations
+builder_test: clean_testdb test_bookie.db
$(NOSE) --with-coverage --cover-package=bookie --cover-erase --with-xunit bookie/tests
.PHONY: mysql_test
View
2 bookie/models/__init__.py
@@ -623,7 +623,7 @@ class Bmark(Base):
__tablename__ = "bmarks"
bid = Column(Integer, autoincrement=True, primary_key=True)
- hash_id = Column(Unicode(22), ForeignKey('url_hash.hash_id'), unique=True)
+ hash_id = Column(Unicode(22), ForeignKey('url_hash.hash_id'))
description = Column(UnicodeText())
extended = Column(UnicodeText())
stored = Column(DateTime, default=datetime.now)
View
2 bookie/tests/test_models/test_bmarkmgr.py
@@ -37,7 +37,7 @@ def test_unique_ct(self):
)
DBSession.add(b)
- # add in our dupes
+ # Add in our dupes
c = Bmark(
url=common,
username=gen_random_word(10)
View
9 dbversions/env.py
@@ -9,10 +9,10 @@
from bookie.models import initialize_sql
-def load_bookie_ini():
+def load_bookie_ini(ini_file):
"""Load the settings for the bookie.ini file."""
ini = ConfigParser()
- ini_path = path.join(path.dirname(path.dirname(__file__)), 'bookie.ini')
+ ini_path = path.join(path.dirname(path.dirname(__file__)), ini_file)
ini.readfp(open(ini_path))
here = path.abspath(path.join(path.dirname(__file__), '../'))
ini.set('app:main', 'here', here)
@@ -22,7 +22,9 @@ def load_bookie_ini():
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
-bookie_config = load_bookie_ini()
+
+bookie_ini = config.get_main_option('app.ini', 'bookie.ini')
+bookie_config = load_bookie_ini(bookie_ini)
sa_url = bookie_config.get('app:main', 'sqlalchemy.url')
config.set_main_option('sqlalchemy.url', sa_url)
@@ -42,7 +44,6 @@ def load_bookie_ini():
# ... etc.
-
def run_migrations_offline():
"""Run migrations in 'offline' mode.
View
26 dbversions/versions/5920b225d05d_load_up_to_date.py
@@ -11,7 +11,6 @@
down_revision = None
from alembic import op
-from datetime import datetime
import sqlalchemy as sa
@@ -32,8 +31,6 @@ def upgrade():
sa.Column('api_key', sa.Unicode(length=12), nullable=True),
sa.Column('invite_ct', sa.Integer(), nullable=True),
sa.Column('invited_by', sa.Unicode(length=255), nullable=True),
- sa.CheckConstraint('TODO'),
- sa.CheckConstraint('TODO'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
@@ -67,7 +64,6 @@ def upgrade():
sa.ForeignKeyConstraint(['hash_id'], ['url_hash.hash_id'], ),
sa.ForeignKeyConstraint(['username'], ['users.username'], ),
sa.PrimaryKeyConstraint('bid'),
- sa.UniqueConstraint('hash_id')
)
op.create_table(u'activations',
@@ -100,6 +96,27 @@ def upgrade():
sa.ForeignKeyConstraint(['hash_id'], ['bmarks.hash_id'], ),
sa.PrimaryKeyConstraint('bid')
)
+
+ op.create_table('logging',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('user', sa.Unicode(255), nullable=False),
+ sa.Column('component', sa.Unicode(50), nullable=False),
+ sa.Column('status', sa.Unicode(10), nullable=False),
+ sa.Column('message', sa.Unicode(255), nullable=False),
+ sa.Column('payload', sa.UnicodeText),
+ sa.Column('tstamp', sa.DateTime),
+ sa.PrimaryKeyConstraint('id'),
+ )
+
+ op.create_table('import_queue',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('username', sa.Unicode(255)),
+ sa.Column('file_path', sa.Unicode(100), nullable=False),
+ sa.Column('tstamp', sa.DateTime),
+ sa.Column('status', sa.Integer),
+ sa.Column('completed', sa.DateTime),
+ sa.PrimaryKeyConstraint('id'),
+ )
### end Alembic commands ###
@@ -112,4 +129,5 @@ def downgrade():
op.drop_table('url_hash')
op.drop_table('tags')
op.drop_table('users')
+ op.drop_table('logging')
### end Alembic commands ###
View
41 dbversions/versions/9f274a38d84_sample_data.py
@@ -0,0 +1,41 @@
+"""
+
+Revision ID: 9f274a38d84
+Revises: 5920b225d05d
+Create Date: 2012-06-19 21:02:38.320088
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '9f274a38d84'
+down_revision = '5920b225d05d'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ """Preseed data into the system."""
+ current_context = op.get_context()
+ meta = current_context.opts['target_metadata']
+ user = sa.Table('users', meta, autoload=True)
+
+ # Add the initial admin user account.
+ op.bulk_insert(user, [{
+ 'username': u'admin',
+ 'password': u'$2a$10$LoSEVbN6833RtwbGQlMhJOROgkjHNH4gjmzkLrIxOX1xLXNvaKFyW',
+ 'email': u'testing@dummy.com',
+ 'activated': True,
+ 'is_admin': True,
+ 'api_key': u'123456',
+ }
+ ])
+
+
+def downgrade():
+ current_context = op.get_context()
+ meta = current_context.opts['target_metadata']
+ user = sa.Table('users', meta, autoload=True)
+
+ # remove all records to undo the preseed.
+ op.execute(user.delete())
View
52 test_alembic.ini
@@ -0,0 +1,52 @@
+# A generic, single database configuration.
+
+[alembic]
+# path to migration scripts
+script_location = dbversions
+
+# template used to generate migration files
+# file_template = %%(rev)s_%%(slug)s
+
+# set to 'true' to run the environment during
+# the 'revision' command, regardless of autogenerate
+# revision_environment = false
+
+# override the application ini we're going to use which causes us to pull in a
+# different database url.
+app.ini = test.ini
+
+
+# Logging configuration
+[loggers]
+keys = root,sqlalchemy,alembic
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+qualname =
+
+[logger_sqlalchemy]
+level = WARN
+handlers =
+qualname = sqlalchemy.engine
+
+[logger_alembic]
+level = INFO
+handlers =
+qualname = alembic
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(levelname)-5.5s [%(name)s] %(message)s
+datefmt = %H:%M:%S

0 comments on commit aff4465

Please sign in to comment.
Something went wrong with that request. Please try again.