from sqlalchemy import Integer from sqlalchemy.dialects.mysql import INTEGER UnsignedInt = Integer() UnsignedInt = UnsignedInt.with_variant(INTEGER(unsigned=True), 'mysql')
import ipaddress from datetime import datetime from flask_login import UserMixin from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.sql import func from werkzeug.security import generate_password_hash, check_password_hash from app import db, login from sqlalchemy.dialects import postgresql, mysql, sqlite from sqlalchemy import BigInteger, Integer UnsignedIntType = Integer() UnsignedIntType = UnsignedIntType.with_variant(mysql.INTEGER(unsigned=True), 'mysql') BigIntegerType = BigInteger() BigIntegerType = BigIntegerType.with_variant(postgresql.BIGINT(), 'postgresql') BigIntegerType = BigIntegerType.with_variant(mysql.BIGINT(), 'mysql') BigIntegerType = BigIntegerType.with_variant(sqlite.INTEGER(), 'sqlite') # TO-DO: server_default=text('now()') """ from pytz import timezone from datetime import datetime UTC = timezone('UTC') def time_now(): return datetime.now(UTC)
'uq': 'uq_%(table_name)s_%(column_0_name)s', 'ck': 'ck_%(table_name)s_%(column_0_name)s', 'fk': 'fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s', 'pk': 'pk_%(table_name)s' } # Prevent constant migrations from sa.DateTime(timezone=True) to mysql.DATETIME(). DATETIME_TYPE = DateTime(timezone=True) DATETIME_TYPE = DATETIME_TYPE.with_variant(mysql.DATETIME(), 'mysql') # mysql boolean BOOLEAN_TYPE = Boolean() BOOLEAN_TYPE = BOOLEAN_TYPE.with_variant(mysql.TINYINT(display_width=1), 'mysql') # Unsigned integer. UNSIGNEDINT_TYPE = Integer() UNSIGNEDINT_TYPE = UNSIGNEDINT_TYPE.with_variant(mysql.INTEGER(unsigned=True), 'mysql') # Unsigned integer. UNSIGNEDSMALLINT_TYPE = SmallInteger() UNSIGNEDSMALLINT_TYPE = UNSIGNEDSMALLINT_TYPE.with_variant( mysql.SMALLINT(unsigned=True), 'mysql') # The “pre ping” feature will normally emit SQL equivalent to “SELECT 1” each time a connection is checked out # from the pool; if an error is raised that is detected as a “disconnect” situation, the connection will be # immediately recycled, and all other pooled connections older than the current time are invalidated, so that # the next time they are checked out, they will also be recycled before use. class SQLAlchemy(_BaseSQLAlchemy): def apply_pool_defaults(self, app, options): super(SQLAlchemy, self).apply_pool_defaults(app, options) options["pool_pre_ping"] = True