diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/alembic.ini (renamed from src/migrations/alembic.ini) | 1 | ||||
-rw-r--r-- | src/conf.py | 2 | ||||
-rw-r--r-- | src/migrations/env.py | 29 | ||||
-rw-r--r-- | src/migrations/versions/db64b766362f_add_notes_column_for_articles.py | 22 | ||||
-rw-r--r-- | src/web/models/article.py | 1 |
5 files changed, 38 insertions, 17 deletions
diff --git a/src/migrations/alembic.ini b/src/alembic.ini index f8ed4801..a8008437 100644 --- a/src/migrations/alembic.ini +++ b/src/alembic.ini @@ -1,6 +1,7 @@ # A generic, single database configuration. [alembic] +script_location = src/migrations # template used to generate migration files # file_template = %%(rev)s_%%(slug)s diff --git a/src/conf.py b/src/conf.py index 1827a7b3..a3e7e3bb 100644 --- a/src/conf.py +++ b/src/conf.py @@ -79,7 +79,7 @@ ADMIN_EMAIL = config.get('misc', 'admin_email') RECAPTCHA_PUBLIC_KEY = config.get('misc', 'recaptcha_public_key') RECAPTCHA_PRIVATE_KEY = config.get('misc', 'recaptcha_private_key') -LOG_PATH = config.get('misc', 'log_path') +LOG_PATH = os.path.abspath(config.get('misc', 'log_path')) NB_WORKER = config.getint('misc', 'nb_worker') API_LOGIN = config.get('crawler', 'api_login') API_PASSWD = config.get('crawler', 'api_passwd') diff --git a/src/migrations/env.py b/src/migrations/env.py index 70961ce2..355c8dd1 100644 --- a/src/migrations/env.py +++ b/src/migrations/env.py @@ -9,7 +9,7 @@ config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. -fileConfig(config.config_file_name) +fileConfig("./alembic.ini") # add your model's MetaData object here # for 'autogenerate' support @@ -19,6 +19,7 @@ from flask import current_app config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI')) target_metadata = current_app.extensions['migrate'].db.metadata + # other values from the config, defined by the needs of env.py, # can be acquired: # my_important_option = config.get_main_option("my_important_option") @@ -49,25 +50,21 @@ def run_migrations_online(): and associate a connection with the context. """ - engine = engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool) - - connection = engine.connect() - context.configure( - connection=connection, - target_metadata=target_metadata - ) - - try: + connectable = engine_from_config( + config.get_section(config.config_ini_section), + prefix='sqlalchemy.', + poolclass=pool.NullPool) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata + ) + with context.begin_transaction(): context.run_migrations() - finally: - connection.close() if context.is_offline_mode(): run_migrations_offline() else: run_migrations_online() - diff --git a/src/migrations/versions/db64b766362f_add_notes_column_for_articles.py b/src/migrations/versions/db64b766362f_add_notes_column_for_articles.py new file mode 100644 index 00000000..3d25b004 --- /dev/null +++ b/src/migrations/versions/db64b766362f_add_notes_column_for_articles.py @@ -0,0 +1,22 @@ +"""Add notes column for articles. + +Revision ID: db64b766362f +Revises: 25ca960a207 +Create Date: 2016-01-06 19:03:25.511074 + +""" + +# revision identifiers, used by Alembic. +revision = 'db64b766362f' +down_revision = '25ca960a207' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('article', sa.Column('notes', sa.String(), nullable=True)) + + +def downgrade(): + op.drop_column('article', 'notes') diff --git a/src/web/models/article.py b/src/web/models/article.py index c25d09d9..54eefe75 100644 --- a/src/web/models/article.py +++ b/src/web/models/article.py @@ -42,6 +42,7 @@ class Article(db.Model): content = db.Column(db.String()) readed = db.Column(db.Boolean(), default=False) like = db.Column(db.Boolean(), default=False) + #notes = db.Column(db.String(), default="") date = db.Column(db.DateTime(), default=datetime.now) retrieved_date = db.Column(db.DateTime(), default=datetime.now) |