From f7c68bfedccfc5bc241b8167185882a061c7e6ae Mon Sep 17 00:00:00 2001 From: Kanstantsin Kamkou Date: Sun, 6 Nov 2016 12:58:00 +0100 Subject: [PATCH] columns cleanup, refs #142 --- gitmostwanted/models/repo.py | 6 +++--- migration/env.py | 34 ++++++++++++---------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/gitmostwanted/models/repo.py b/gitmostwanted/models/repo.py index 55f5c5b..89fd370 100644 --- a/gitmostwanted/models/repo.py +++ b/gitmostwanted/models/repo.py @@ -1,4 +1,4 @@ -from sqlalchemy.dialects.mysql import SMALLINT +from sqlalchemy.dialects.mysql import INTEGER, SMALLINT from sqlalchemy.sql import expression from gitmostwanted.lib.status import Status from gitmostwanted.lib.regex import SearchTerm @@ -22,8 +22,8 @@ class Repo(db.Model): created_at = db.Column(db.DateTime, nullable=False, index=True) checked_at = db.Column(db.DateTime, index=True) mature = db.Column(db.Boolean, nullable=False, server_default=expression.false(), index=True) - worth = db.Column(SMALLINT(display_width=1), nullable=False, server_default='3', index=True) - stargazers_count = db.Column(db.Integer, nullable=False, server_default='0') + worth = db.Column(SMALLINT(display_width=2), nullable=False, server_default='3', index=True) + stargazers_count = db.Column(INTEGER(unsigned=True), nullable=False, server_default='0') status_updated_at = db.Column(db.DateTime) status = db.Column( db.Enum('promising', 'new', 'unknown', 'deleted', 'hopeless'), diff --git a/migration/env.py b/migration/env.py index 4e9d1a3..8754f36 100644 --- a/migration/env.py +++ b/migration/env.py @@ -1,12 +1,9 @@ -from __future__ import with_statement -from alembic import context -from sqlalchemy import engine_from_config, pool +from gitmostwanted.app import app from logging.config import fileConfig -from gitmostwanted.app import app, db +from sqlalchemy import engine_from_config, pool +from alembic import context # models -from gitmostwanted.models.repo import * -from gitmostwanted.models.user import * from gitmostwanted.models.report import * # this is the Alembic Config object, which provides @@ -31,6 +28,8 @@ # my_important_option = config.get_main_option("my_important_option") # ... etc. +config_custom = dict(target_metadata=target_metadata, compare_type=True) + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -44,9 +43,7 @@ def run_migrations_offline(): script output. """ - url = config.get_main_option("sqlalchemy.url") - context.configure(url=url, target_metadata=target_metadata) - + context.configure(url=config.get_main_option("sqlalchemy.url"), **config_custom) with context.begin_transaction(): context.run_migrations() @@ -58,21 +55,14 @@ def run_migrations_online(): and associate a connection with the context. """ - connectable = engine_from_config( + connectible = 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 - ) - + poolclass=pool.NullPool + ) + with connectible.connect() as connection: + context.configure(connection=connection, **config_custom) with context.begin_transaction(): context.run_migrations() -if context.is_offline_mode(): - run_migrations_offline() -else: - run_migrations_online() +run_migrations_offline() if context.is_offline_mode() else run_migrations_online()