From e4042c4b31267670e52a7d3f8154d9aaf5651ffa Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 6 Jan 2016 21:54:31 +0100 Subject: it seemms that alembic do not find the models --- src/alembic.ini | 46 ++++++++++++++++++++++ src/conf.py | 2 +- src/migrations/alembic.ini | 45 --------------------- src/migrations/env.py | 29 ++++++-------- .../db64b766362f_add_notes_column_for_articles.py | 22 +++++++++++ src/web/models/article.py | 1 + 6 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 src/alembic.ini delete mode 100644 src/migrations/alembic.ini create mode 100644 src/migrations/versions/db64b766362f_add_notes_column_for_articles.py diff --git a/src/alembic.ini b/src/alembic.ini new file mode 100644 index 00000000..a8008437 --- /dev/null +++ b/src/alembic.ini @@ -0,0 +1,46 @@ +# A generic, single database configuration. + +[alembic] +script_location = src/migrations +# 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 + + +# 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 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/alembic.ini b/src/migrations/alembic.ini deleted file mode 100644 index f8ed4801..00000000 --- a/src/migrations/alembic.ini +++ /dev/null @@ -1,45 +0,0 @@ -# A generic, single database configuration. - -[alembic] -# 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 - - -# 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 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) -- cgit