Revert "Implement CIText as NOCASE alternative in postgresql"

This reverts commit 0f3c1b9d15.
master
kaiyou 6 years ago
parent f52ae5535c
commit 76925e82f3

@ -1,11 +1,10 @@
from mailu import dkim, configuration from mailu import dkim
from sqlalchemy.ext import declarative from sqlalchemy.ext import declarative
from passlib import context, hash from passlib import context, hash
from datetime import datetime, date from datetime import datetime, date
from email.mime import text from email.mime import text
from flask import current_app as app from flask import current_app as app
from citext import CIText
import flask_sqlalchemy import flask_sqlalchemy
import sqlalchemy import sqlalchemy
@ -19,7 +18,6 @@ import dns
db = flask_sqlalchemy.SQLAlchemy() db = flask_sqlalchemy.SQLAlchemy()
config = configuration.ConfigManager()
class IdnaDomain(db.TypeDecorator): class IdnaDomain(db.TypeDecorator):
@ -58,10 +56,6 @@ class IdnaEmail(db.TypeDecorator):
idna.decode(domain_name), idna.decode(domain_name),
) )
def __init__(self):
if config['DB_FLAVOR'] == 'postgresql':
self.impl = CIText()
class CommaSeparatedList(db.TypeDecorator): class CommaSeparatedList(db.TypeDecorator):
""" Stores a list as a comma-separated string, compatible with Postfix. """ Stores a list as a comma-separated string, compatible with Postfix.

@ -13,16 +13,12 @@ down_revision = '49d77a93118e'
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from flask import current_app as app from flask import current_app as app
from citext import CIText
def upgrade(): def upgrade():
if app.config['DB_FLAVOR'] == "postgresql": if app.config['DB_FLAVOR'] == 'sqlite':
email_type = CIText()
else:
email_type = sa.String(length=255, collation="NOCASE")
with op.batch_alter_table('user') as batch: with op.batch_alter_table('user') as batch:
batch.alter_column('email', type_=email_type) batch.alter_column('email', type_=sa.String(length=255, collation="NOCASE"))
def downgrade(): def downgrade():

@ -12,21 +12,15 @@ down_revision = '9c28df23f77e'
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from flask import current_app as app
from citext import CIText
def upgrade(): def upgrade():
if app.config['DB_FLAVOR'] == "postgresql":
email_type = CIText()
else:
email_type = sa.String(length=255, collation="NOCASE")
op.create_table('token', op.create_table('token',
sa.Column('created_at', sa.Date(), nullable=False), sa.Column('created_at', sa.Date(), nullable=False),
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('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_email', email_type), sa.Column('user_email', sa.String(length=255), nullable=False),
sa.Column('password', sa.String(length=255), nullable=False), sa.Column('password', sa.String(length=255), nullable=False),
sa.Column('ip', sa.String(length=255), nullable=True), sa.Column('ip', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['user_email'], ['user.email'], ), sa.ForeignKeyConstraint(['user_email'], ['user.email'], ),

@ -13,30 +13,14 @@ down_revision = 'c162ac88012a'
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from flask import current_app as app from flask import current_app as app
from citext import CIText
def upgrade(): def upgrade():
if app.config['DB_FLAVOR'] == "postgresql": if app.config['DB_FLAVOR'] == 'sqlite':
email_type = CIText()
with op.batch_alter_table('fetch') as batch:
batch.drop_constraint('fetch_user_email_fkey')
with op.batch_alter_table('manager') as batch:
batch.drop_constraint('manager_user_email_fkey')
else:
email_type = sa.String(length=255, collation="NOCASE")
with op.batch_alter_table('user') as batch: with op.batch_alter_table('user') as batch:
batch.alter_column('email', type_=email_type) batch.alter_column('email', type_=sa.String(length=255, collation="NOCASE"))
with op.batch_alter_table('alias') as batch: with op.batch_alter_table('alias') as batch:
batch.alter_column('email', type_=email_type) batch.alter_column('email', type_=sa.String(length=255, collation="NOCASE"))
with op.batch_alter_table('fetch') as batch:
batch.alter_column('user_email', type_=email_type)
if app.config['DB_FLAVOR'] == "postgresql":
batch.create_foreign_key("fetch_user_email_fkey", "user", ["user_email"], ["email"])
with op.batch_alter_table('manager') as batch:
batch.alter_column('user_email', type_=email_type)
if app.config['DB_FLAVOR'] == "postgresql":
batch.create_foreign_key("manager_user_email_fkey", "user", ["user_email"], ["email"])
def downgrade(): def downgrade():

@ -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', name='protocol'), nullable=False), sa.Column('protocol', sa.Enum('imap', 'pop3'), 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),

@ -45,5 +45,4 @@ Werkzeug==0.14.1
WTForms==2.2.1 WTForms==2.2.1
WTForms-Components==0.10.3 WTForms-Components==0.10.3
psycopg2 psycopg2
sqlalchemy-citext
tenacity tenacity

@ -7,7 +7,7 @@ RUN apk add --no-cache \
RUN pip3 install jinja2 RUN pip3 install jinja2
# Image specific layers under this line # Image specific layers under this line
RUN apk add --no-cache \ RUN apk add --no-cache \
postgresql postgresql-libs postgresql-contrib busybox-suid sudo tar \ postgresql postgresql-libs busybox-suid sudo tar \
&& apk add --virtual .build-deps gcc musl-dev postgresql-dev python3-dev \ && apk add --virtual .build-deps gcc musl-dev postgresql-dev python3-dev \
&& pip3 install psycopg2 anosql \ && pip3 install psycopg2 anosql \
&& apk --purge del .build-deps && apk --purge del .build-deps

@ -40,10 +40,3 @@ select 1
create create
database mailu database mailu
owner mailu; owner mailu;
-- name: create_citext!
-- Install the CIText extension
create
extension
if not exists
citext;

@ -8,7 +8,7 @@ import os
import subprocess import subprocess
def setup(): def setup():
conn = psycopg2.connect(user = 'postgres') conn = psycopg2.connect('user=postgres')
queries = anosql.load_queries('postgres', '/conf/queries.sql') queries = anosql.load_queries('postgres', '/conf/queries.sql')
# Mailu user # Mailu user
queries.create_mailu_user(conn) queries.create_mailu_user(conn)
@ -23,10 +23,6 @@ def setup():
queries.create_db(conn) queries.create_db(conn)
conn.set_isolation_level(1) conn.set_isolation_level(1)
conn.close() conn.close()
conn = psycopg2.connect(user = 'postgres', database= 'mailu')
queries.create_citext(conn)
conn.commit()
conn.close()
# Check if /data is empty # Check if /data is empty
if not os.listdir("/data"): if not os.listdir("/data"):

Loading…
Cancel
Save