Fix support for postgres and mysql

master
kaiyou 6 years ago
parent a881a1a839
commit e022513a94

@ -24,10 +24,10 @@ class IdnaDomain(db.TypeDecorator):
""" Stores a Unicode string in it's IDNA representation (ASCII only) """ Stores a Unicode string in it's IDNA representation (ASCII only)
""" """
impl = db.String(80) impl = db.String(80, collation="NOCASE")
def process_bind_param(self, value, dialect): def process_bind_param(self, value, dialect):
return idna.encode(value).decode("ascii") return idna.encode(value).decode("ascii").lower()
def process_result_value(self, value, dialect): def process_result_value(self, value, dialect):
return idna.decode(value) return idna.decode(value)
@ -45,7 +45,7 @@ class IdnaEmail(db.TypeDecorator):
return "{0}@{1}".format( return "{0}@{1}".format(
localpart, localpart,
idna.encode(domain_name).decode('ascii'), idna.encode(domain_name).decode('ascii'),
) ).lower()
except ValueError: except ValueError:
pass pass

@ -16,7 +16,7 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
with op.batch_alter_table('user') as batch: with op.batch_alter_table('user') as batch:
batch.alter_column('email', type_=sa.String(length=255, collation="NOCASE")) batch.alter_column('email', type_=sa.String(length=255))
def downgrade(): def downgrade():

@ -35,7 +35,7 @@ def upgrade():
) )
# set default to 80% # set default to 80%
with op.batch_alter_table('user') as batch: with op.batch_alter_table('user') as batch:
batch.alter_column('spam_threshold', default=80.) batch.alter_column('spam_threshold', server_default="80.")
def downgrade(): def downgrade():
connection = op.get_bind() connection = op.get_bind()
@ -50,4 +50,4 @@ def downgrade():
) )
# set default to 10/15 # set default to 10/15
with op.batch_alter_table('user') as batch: with op.batch_alter_table('user') as batch:
batch.alter_column('spam_threshold', default=10.) batch.alter_column('spam_threshold', server_default="10.")

@ -16,9 +16,9 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
with op.batch_alter_table('user') as batch: with op.batch_alter_table('user') as batch:
batch.alter_column('email', type_=sa.String(length=255, collation="NOCASE")) batch.alter_column('email', type_=sa.String(length=255))
with op.batch_alter_table('alias') as batch: with op.batch_alter_table('alias') as batch:
batch.alter_column('email', type_=sa.String(length=255, collation="NOCASE")) batch.alter_column('email', type_=sa.String(length=255))
def downgrade(): def downgrade():

@ -29,7 +29,7 @@ def upgrade():
sa.Column('updated_at', sa.Date(), nullable=True), sa.Column('updated_at', sa.Date(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True), sa.Column('comment', sa.String(length=255), nullable=True),
sa.Column('localpart', sa.String(length=80), nullable=False), sa.Column('localpart', sa.String(length=80), nullable=False),
sa.Column('destination', sa.String(), nullable=False), sa.Column('destination', sa.String(length=1023), nullable=False),
sa.Column('domain_name', sa.String(length=80), nullable=False), sa.Column('domain_name', sa.String(length=80), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False), sa.Column('email', sa.String(length=255), nullable=False),
sa.ForeignKeyConstraint(['domain_name'], ['domain.name'], ), sa.ForeignKeyConstraint(['domain_name'], ['domain.name'], ),
@ -64,7 +64,7 @@ def upgrade():
sa.Column('comment', sa.String(length=255), nullable=True), sa.Column('comment', sa.String(length=255), nullable=True),
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_email', sa.String(length=255), nullable=False), sa.Column('user_email', sa.String(length=255), nullable=False),
sa.Column('protocol', sa.Enum('imap', 'pop3'), nullable=False), sa.Column('protocol', sa.Enum('imap', 'pop3', name='enum_protocol'), nullable=False),
sa.Column('host', sa.String(length=255), nullable=False), sa.Column('host', sa.String(length=255), nullable=False),
sa.Column('port', sa.Integer(), nullable=False), sa.Column('port', sa.Integer(), nullable=False),
sa.Column('tls', sa.Boolean(), nullable=False), sa.Column('tls', sa.Boolean(), nullable=False),

@ -18,3 +18,5 @@ PyOpenSSL
dnspython dnspython
bcrypt bcrypt
tenacity tenacity
mysqlclient
psycopg2

Loading…
Cancel
Save