diff --git a/app/model/address.py b/app/model/address.py index 5073861..ff6557d 100644 --- a/app/model/address.py +++ b/app/model/address.py @@ -7,21 +7,21 @@ from app.model.model import Model, View class AddressModel(db.Model, Model): __tablename__ = "address" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) country_id = db.Column(db.Integer, db.ForeignKey("country.id")) country = db.relationship("CountryModel") - number = db.Column(db.String(2000)) + number = db.Column(db.String(20)) street = db.Column(db.String(2000)) miscellaneous = db.Column(db.String(2000)) city = db.Column(db.String(2000)) - zipcode = db.Column(db.String(2000)) - building = db.Column(db.String(2000)) - floor = db.Column(db.String(2000)) - stair = db.Column(db.String(2000)) - office = db.Column(db.String(2000)) - latitude = db.Column(db.String(2000)) - longitude = db.Column(db.String(2000)) + zipcode = db.Column(db.String(20)) + building = db.Column(db.String(20)) + floor = db.Column(db.String(20)) + stair = db.Column(db.String(20)) + office = db.Column(db.String(20)) + latitude = db.Column(db.String(20)) + longitude = db.Column(db.String(20)) class AdminView(View): diff --git a/app/model/contact.py b/app/model/contact.py index 08131f7..f964936 100644 --- a/app/model/contact.py +++ b/app/model/contact.py @@ -15,8 +15,8 @@ class ContactModel(db.Model, Model): address = db.relationship( "AddressModel", backref=db.backref("contacts", lazy="dynamic") ) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) value = db.Column(db.String(2000)) def __repr__(self): diff --git a/app/model/country.py b/app/model/country.py index d10e499..fb01e3b 100644 --- a/app/model/country.py +++ b/app/model/country.py @@ -7,9 +7,9 @@ from app.model.model import Model, View class CountryModel(db.Model, Model): __tablename__ = "country" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) - code = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) + code = db.Column(db.String(20)) @property def flag(self): diff --git a/app/model/decision.py b/app/model/decision.py index 1d76cc0..34287d6 100644 --- a/app/model/decision.py +++ b/app/model/decision.py @@ -15,7 +15,7 @@ class DecisionModel(db.Model, Model): recommendation = db.relationship( "RecommendationModel", backref=db.backref("decisions", lazy="dynamic") ) - value = db.Column(db.String(2000)) + value = db.Column(db.String(200)) def __repr__(self): return self.value diff --git a/app/model/entity.py b/app/model/entity.py index a44eeeb..de39ac7 100644 --- a/app/model/entity.py +++ b/app/model/entity.py @@ -9,14 +9,14 @@ from app.model.model import Model, View class EntityModel(db.Model, Model): __tablename__ = "entity" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) - code = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) + code = db.Column(db.String(20)) picture = db.Column(db.String(2000)) type_id = db.Column(db.Integer, db.ForeignKey("type.id")) type = db.relationship("TypeModel") - start = db.Column(db.DateTime) - end = db.Column(db.DateTime) + start = db.Column(db.Date) + end = db.Column(db.Date) country_id = db.Column(db.Integer, db.ForeignKey("country.id")) country = db.relationship("CountryModel") parent_id = db.Column(db.Integer, db.ForeignKey("entity.id")) diff --git a/app/model/matter.py b/app/model/matter.py index 12315a6..482498a 100644 --- a/app/model/matter.py +++ b/app/model/matter.py @@ -9,8 +9,8 @@ from app.model.model import Model, View class MatterModel(db.Model, Model): __tablename__ = "matter" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000), unique=True) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200), unique=True) description = db.Column(db.Text) active = db.Column(db.Boolean, default=False) diff --git a/app/model/membership.py b/app/model/membership.py index 9873658..85081fa 100644 --- a/app/model/membership.py +++ b/app/model/membership.py @@ -15,8 +15,8 @@ class MembershipModel(db.Model, Model): role = db.relationship( "RoleModel", backref=db.backref("memberships", lazy="dynamic") ) - start = db.Column(db.DateTime) - end = db.Column(db.DateTime) + start = db.Column(db.Date) + end = db.Column(db.Date) entity_id = db.Column(db.Integer, db.ForeignKey("entity.id")) entity = db.relationship( "EntityModel", backref=db.backref("memberships", lazy="dynamic") diff --git a/app/model/model.py b/app/model/model.py index 453412d..6ecd793 100644 --- a/app/model/model.py +++ b/app/model/model.py @@ -11,14 +11,14 @@ from app import db class View(ModelView): def is_accessible(self): - # TODO: develop mode + # TODO: develop mode, refer to current_app.config.debug return True if not current_user.is_authenticated: return False return current_user.is_authenticated and current_user.admin def inaccessible_callback(self, name, **kwargs): - # TODO: develop mode + # TODO: develop mode, refer to current_app.config.debug return redirect(url_for("core.login")) return redirect(url_for("admin.login", next=request.url)) @@ -55,4 +55,4 @@ class Model: result_dict[key] = getattr(self, key).strftime("%Y-%m-%d") else: result_dict[key] = getattr(self, key) - return result_dict \ No newline at end of file + return result_dict diff --git a/app/model/recommendation.py b/app/model/recommendation.py index 24ee8b9..c0537a4 100644 --- a/app/model/recommendation.py +++ b/app/model/recommendation.py @@ -17,12 +17,12 @@ class RecommendationModel(db.Model, Model): entity = db.relationship( "EntityModel", backref=db.backref("recommendations", lazy="dynamic") ) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000), unique=True) - code = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) + code = db.Column(db.String(20)) date = db.Column(db.Date) description = db.Column(db.Text) - value = db.Column(db.String(2000)) + value = db.Column(db.String(200)) weight = db.Column(db.Integer, default=1) def __repr__(self): diff --git a/app/model/representative.py b/app/model/representative.py index 38816be..2387e18 100644 --- a/app/model/representative.py +++ b/app/model/representative.py @@ -8,9 +8,9 @@ from app.model.country import CountryModel class RepresentativeModel(db.Model, Model): __tablename__ = "representative" id = db.Column(db.Integer, primary_key=True) - code = db.Column(db.String(2000), unique=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) + code = db.Column(db.String(20), unique=True) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) active = db.Column(db.Boolean, default=False) picture = db.Column(db.String(2000)) nationality_id = db.Column(db.Integer, db.ForeignKey("country.id")) diff --git a/app/model/role.py b/app/model/role.py index 521237b..dfac67a 100644 --- a/app/model/role.py +++ b/app/model/role.py @@ -7,9 +7,9 @@ from app.model.model import Model, View class RoleModel(db.Model, Model): __tablename__ = "role" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) - code = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) + code = db.Column(db.String(20)) def __repr__(self): return self.name diff --git a/app/model/type.py b/app/model/type.py index 2409778..dc001ed 100644 --- a/app/model/type.py +++ b/app/model/type.py @@ -9,9 +9,9 @@ from app.model.model import Model, View class TypeModel(db.Model, Model): __tablename__ = "type" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(2000)) - slug = db.Column(db.String(2000)) - code = db.Column(db.String(2000)) + name = db.Column(db.String(200)) + slug = db.Column(db.String(200)) + code = db.Column(db.String(20)) def __repr__(self): return self.name diff --git a/migrations/alembic.ini b/migrations/alembic.ini index f8ed480..ec9d45c 100644 --- a/migrations/alembic.ini +++ b/migrations/alembic.ini @@ -11,7 +11,7 @@ # Logging configuration [loggers] -keys = root,sqlalchemy,alembic +keys = root,sqlalchemy,alembic,flask_migrate [handlers] keys = console @@ -34,6 +34,11 @@ level = INFO handlers = qualname = alembic +[logger_flask_migrate] +level = INFO +handlers = +qualname = flask_migrate + [handler_console] class = StreamHandler args = (sys.stderr,) diff --git a/migrations/env.py b/migrations/env.py index 8b3fb33..68feded 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -3,8 +3,6 @@ from __future__ import with_statement import logging from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool from flask import current_app from alembic import context @@ -24,7 +22,8 @@ logger = logging.getLogger('alembic.env') # target_metadata = mymodel.Base.metadata config.set_main_option( 'sqlalchemy.url', - str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) + str(current_app.extensions['migrate'].db.get_engine().url).replace( + '%', '%%')) target_metadata = current_app.extensions['migrate'].db.metadata # other values from the config, defined by the needs of env.py, @@ -72,11 +71,7 @@ def run_migrations_online(): directives[:] = [] logger.info('No changes in schema detected.') - connectable = engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool, - ) + connectable = current_app.extensions['migrate'].db.get_engine() with connectable.connect() as connection: context.configure( diff --git a/migrations/versions/e0001237a466_.py b/migrations/versions/6ce21d3cdf0e_.py similarity index 68% rename from migrations/versions/e0001237a466_.py rename to migrations/versions/6ce21d3cdf0e_.py index de11b2d..3681829 100644 --- a/migrations/versions/e0001237a466_.py +++ b/migrations/versions/6ce21d3cdf0e_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: e0001237a466 +Revision ID: 6ce21d3cdf0e Revises: -Create Date: 2021-07-16 19:43:05.321519 +Create Date: 2021-07-24 09:44:44.681657 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'e0001237a466' +revision = '6ce21d3cdf0e' down_revision = None branch_labels = None depends_on = None @@ -20,15 +20,15 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('country', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), - sa.Column('code', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), + sa.Column('code', sa.String(length=20), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('matter', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.Column('active', sa.Boolean(), nullable=True), sa.PrimaryKeyConstraint('id'), @@ -36,46 +36,46 @@ def upgrade(): ) op.create_table('role', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), - sa.Column('code', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), + sa.Column('code', sa.String(length=20), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('type', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), - sa.Column('code', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), + sa.Column('code', sa.String(length=20), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('address', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), sa.Column('country_id', sa.Integer(), nullable=True), - sa.Column('number', sa.String(length=2000), nullable=True), + sa.Column('number', sa.String(length=20), nullable=True), sa.Column('street', sa.String(length=2000), nullable=True), sa.Column('miscellaneous', sa.String(length=2000), nullable=True), sa.Column('city', sa.String(length=2000), nullable=True), - sa.Column('zipcode', sa.String(length=2000), nullable=True), - sa.Column('building', sa.String(length=2000), nullable=True), - sa.Column('floor', sa.String(length=2000), nullable=True), - sa.Column('stair', sa.String(length=2000), nullable=True), - sa.Column('office', sa.String(length=2000), nullable=True), - sa.Column('latitude', sa.String(length=2000), nullable=True), - sa.Column('longitude', sa.String(length=2000), nullable=True), + sa.Column('zipcode', sa.String(length=20), nullable=True), + sa.Column('building', sa.String(length=20), nullable=True), + sa.Column('floor', sa.String(length=20), nullable=True), + sa.Column('stair', sa.String(length=20), nullable=True), + sa.Column('office', sa.String(length=20), nullable=True), + sa.Column('latitude', sa.String(length=20), nullable=True), + sa.Column('longitude', sa.String(length=20), nullable=True), sa.ForeignKeyConstraint(['country_id'], ['country.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('entity', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), - sa.Column('code', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), + sa.Column('code', sa.String(length=20), nullable=True), sa.Column('picture', sa.String(length=2000), nullable=True), sa.Column('type_id', sa.Integer(), nullable=True), - sa.Column('start', sa.DateTime(), nullable=True), - sa.Column('end', sa.DateTime(), nullable=True), + sa.Column('start', sa.Date(), nullable=True), + sa.Column('end', sa.Date(), nullable=True), sa.Column('country_id', sa.Integer(), nullable=True), sa.Column('parent_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['country_id'], ['country.id'], ), @@ -85,8 +85,10 @@ def upgrade(): ) op.create_table('representative', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), + sa.Column('code', sa.String(length=20), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), + sa.Column('active', sa.Boolean(), nullable=True), sa.Column('picture', sa.String(length=2000), nullable=True), sa.Column('nationality_id', sa.Integer(), nullable=True), sa.Column('sex', sa.String(length=1), nullable=True), @@ -95,14 +97,14 @@ def upgrade(): sa.Column('job', sa.String(length=2000), nullable=True), sa.ForeignKeyConstraint(['nationality_id'], ['country.id'], ), sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('slug') + sa.UniqueConstraint('code') ) op.create_table('contact', sa.Column('id', sa.Integer(), nullable=False), sa.Column('representative_id', sa.Integer(), nullable=True), sa.Column('address_id', sa.Integer(), nullable=True), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), sa.Column('value', sa.String(length=2000), nullable=True), sa.ForeignKeyConstraint(['address_id'], ['address.id'], ), sa.ForeignKeyConstraint(['representative_id'], ['representative.id'], ), @@ -112,8 +114,8 @@ def upgrade(): sa.Column('id', sa.Integer(), nullable=False), sa.Column('representative_id', sa.Integer(), nullable=True), sa.Column('role_id', sa.Integer(), nullable=True), - sa.Column('start', sa.DateTime(), nullable=True), - sa.Column('end', sa.DateTime(), nullable=True), + sa.Column('start', sa.Date(), nullable=True), + sa.Column('end', sa.Date(), nullable=True), sa.Column('entity_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['entity_id'], ['entity.id'], ), sa.ForeignKeyConstraint(['representative_id'], ['representative.id'], ), @@ -124,23 +126,22 @@ def upgrade(): sa.Column('id', sa.Integer(), nullable=False), sa.Column('matter_id', sa.Integer(), nullable=True), sa.Column('entity_id', sa.Integer(), nullable=True), - sa.Column('name', sa.String(length=2000), nullable=True), - sa.Column('slug', sa.String(length=2000), nullable=True), - sa.Column('code', sa.String(length=2000), nullable=True), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('slug', sa.String(length=200), nullable=True), + sa.Column('code', sa.String(length=20), nullable=True), sa.Column('date', sa.Date(), nullable=True), sa.Column('description', sa.Text(), nullable=True), - sa.Column('value', sa.String(length=2000), nullable=True), + sa.Column('value', sa.String(length=200), nullable=True), sa.Column('weight', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['entity_id'], ['entity.id'], ), sa.ForeignKeyConstraint(['matter_id'], ['matter.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('slug') + sa.PrimaryKeyConstraint('id') ) op.create_table('stance', sa.Column('id', sa.Integer(), nullable=False), sa.Column('representative_id', sa.Integer(), nullable=True), sa.Column('matter_id', sa.Integer(), nullable=True), - sa.Column('date', sa.DateTime(), nullable=True), + sa.Column('date', sa.Date(), nullable=True), sa.Column('subject', sa.String(length=2000), nullable=True), sa.Column('extract', sa.Text(), nullable=True), sa.Column('source_url', sa.String(length=2000), nullable=True), @@ -153,7 +154,7 @@ def upgrade(): sa.Column('id', sa.Integer(), nullable=False), sa.Column('representative_id', sa.Integer(), nullable=True), sa.Column('recommendation_id', sa.Integer(), nullable=True), - sa.Column('value', sa.String(length=2000), nullable=True), + sa.Column('value', sa.String(length=200), nullable=True), sa.ForeignKeyConstraint(['recommendation_id'], ['recommendation.id'], ), sa.ForeignKeyConstraint(['representative_id'], ['representative.id'], ), sa.PrimaryKeyConstraint('id') diff --git a/migrations/versions/8b260b23ba3a_.py b/migrations/versions/8b260b23ba3a_.py deleted file mode 100644 index 65b3ef2..0000000 --- a/migrations/versions/8b260b23ba3a_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 8b260b23ba3a -Revises: e0001237a466 -Create Date: 2021-07-21 14:03:53.023739 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '8b260b23ba3a' -down_revision = 'e0001237a466' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('representative', sa.Column('code', sa.String(length=2000), nullable=True)) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('representative', 'code') - # ### end Alembic commands ### diff --git a/migrations/versions/ac34a07322f6_.py b/migrations/versions/ac34a07322f6_.py deleted file mode 100644 index 93ddb64..0000000 --- a/migrations/versions/ac34a07322f6_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: ac34a07322f6 -Revises: b83b29dc60b0 -Create Date: 2021-07-21 15:36:01.454538 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'ac34a07322f6' -down_revision = 'b83b29dc60b0' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('representative', sa.Column('active', sa.Boolean(), nullable=True)) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('representative', 'active') - # ### end Alembic commands ### diff --git a/migrations/versions/b83b29dc60b0_.py b/migrations/versions/b83b29dc60b0_.py deleted file mode 100644 index c5c0e17..0000000 --- a/migrations/versions/b83b29dc60b0_.py +++ /dev/null @@ -1,30 +0,0 @@ -"""empty message - -Revision ID: b83b29dc60b0 -Revises: 8b260b23ba3a -Create Date: 2021-07-21 14:04:54.107335 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b83b29dc60b0' -down_revision = '8b260b23ba3a' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('representative_slug_key', 'representative', type_='unique') - op.create_unique_constraint(None, 'representative', ['code']) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'representative', type_='unique') - op.create_unique_constraint('representative_slug_key', 'representative', ['slug']) - # ### end Alembic commands ### diff --git a/requirements.txt b/requirements.txt index 046f3fa..d2a5f05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,5 @@ flask_sqlalchemy flask_wtf python-slugify requests +mysqlclient +