Fix remaining migration scripts and remove initdb/flushdb from manage.py

master
kaiyou 7 years ago
parent 829e4a5e28
commit a96478c496

@ -29,34 +29,24 @@ HOSTNAME=mail.mailu.io
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin
# Docker-compose project name, this will prepended to containers names.
COMPOSE_PROJECT_NAME=mailu
# Default password scheme used for newly created accounts and changed passwords
# (value: SHA512-CRYPT, SHA256-CRYPT, MD5-CRYPT, CRYPT)
PASSWORD_SCHEME=SHA512-CRYPT
# Choose how secure connections will behave (value: letsencrypt, cert, notls)
TLS_FLAVOR=cert
###################################
# Optional features
###################################
# Choose which frontend Web server to run if any (value: nginx, traefik, none)
# Choose which frontend Web server to run if any (value: traefik, none)
FRONTEND=none
# Choose how secure connections will behave (value: letsencrypt, cert, notls)
TLS_FLAVOR=cert
# Choose which webmail to run if any (values: roundcube, rainloop, none)
WEBMAIL=none
# Expose the admin interface in publicly (values: yes, no)
EXPOSE_ADMIN=no
# Dav server implementation (value: radicale, none)
WEBDAV=none
# Antivirus solution (value: none, clamav)
ANTIVIRUS=clamav
# Antivirus solution (value: clamav, none)
ANTIVIRUS=none
###################################
# Mail settings
@ -85,15 +75,16 @@ DMARC_RUA=admin
DMARC_RUF=admin
###################################
# Nginx settings
# Advanced settings
###################################
# Docker-compose project name, this will prepended to containers names.
COMPOSE_PROJECT_NAME=mailu
# Default password scheme used for newly created accounts and changed passwords
# (value: SHA512-CRYPT, SHA256-CRYPT, MD5-CRYPT, CRYPT)
PASSWORD_SCHEME=SHA512-CRYPT
# SSL DHPARAM Bits
NGINX_SSL_DHPARAM_BITS=2048
###################################
# Developers
###################################
# Uncomment this to enable debugging globally
# DEBUG=True

@ -1,23 +1,6 @@
from mailu import app, manager, db
from mailu.admin import models
import flask_migrate
@manager.command
def flushdb():
""" Flush the database
"""
db.drop_all()
@manager.command
def initdb():
""" Initialize the database
"""
db.create_all()
flask_migrate.stamp(revision="head")
@manager.command
def admin(localpart, domain_name, password):

@ -13,23 +13,35 @@ down_revision = '27ae2f102682'
from alembic import op
import sqlalchemy as sa
from mailu.admin import models
from mailu import db
user_table = sa.Table(
'user',
sa.MetaData(),
sa.Column('email', sa.String(255), primary_key=True),
sa.Column('spam_threshold', sa.Numeric())
)
def upgrade():
connection = op.get_bind()
# Make sure that every value is already an Integer
for user in models.User.query.all():
user.spam_threshold = int(user.spam_threshold)
db.session.commit()
for user in connection.execute(user_table.select()):
connection.execute(
user_table.update().where(
user_table.c.email == user.email
).values(
spam_threshold=int(user.spam_threshold)
)
)
# Migrate the table
with op.batch_alter_table('user') as batch:
batch.alter_column(
'spam_threshold', existing_type=db.Numeric(), type_=db.Integer())
'spam_threshold', existing_type=sa.Numeric(), type_=sa.Integer())
def downgrade():
# Migrate the table
with op.batch_alter_table('user') as batch:
batch.alter_column(
'spam_threshold', existing_type=db.Integer(), type_=db.Numeric())
'spam_threshold', existing_type=sa.Integer(), type_=sa.Numeric())

@ -13,25 +13,41 @@ down_revision = 'dc8c25cf5b98'
from alembic import op
import sqlalchemy as sa
from mailu.admin.models import User
from mailu import db
user_table = sa.Table(
'user',
sa.MetaData(),
sa.Column('email', sa.String(255), primary_key=True),
sa.Column('spam_threshold', sa.Numeric())
)
def upgrade():
connection = op.get_bind()
# spam_threshold is a X/15 based value, we're converting it to percent.
for user in User.query.all():
user.spam_threshold = int(100. * float(user.spam_threshold or 0.) / 15.)
db.session.commit()
for user in connection.execute(user_table.select()):
connection.execute(
user_table.update().where(
user_table.c.email == user.email
).values(
spam_threshold=int(100. * float(user.spam_threshold or 0.) / 15.)
)
)
# set default to 80%
with op.batch_alter_table('user') as batch:
batch.alter_column('spam_threshold', default=80.)
def downgrade():
connection = op.get_bind()
# spam_threshold is a X/15 based value, we're converting it from percent.
for user in User.query.all():
user.spam_threshold = int(15. * float(user.spam_threshold or 0.) / 100.)
db.session.commit()
for user in connection.execute(user_table.select()):
connection.execute(
user_table.update().where(
user_table.c.email == user.email
).values(
spam_threshold=int(15. * float(user.spam_threshold or 0.) / 100.)
)
)
# set default to 10/15
with op.batch_alter_table('user') as batch:
batch.alter_column('spam_threshold', default=10.)

@ -13,18 +13,24 @@ down_revision = '2335c80a6bc3'
from alembic import op
import sqlalchemy as sa
from mailu import app, db
from mailu.admin import models
from mailu import app
fetch_table = sa.Table(
'fetch',
sa.MetaData(),
sa.Column('keep', sa.Boolean())
)
def upgrade():
connection = op.get_bind()
op.add_column('fetch', sa.Column('keep', sa.Boolean(), nullable=False, server_default=sa.sql.expression.false()))
# also apply the current config value if set
if app.config.get("FETCHMAIL_KEEP", "False") == "True":
for fetch in models.Fetch.query.all():
fetch.keep = True
db.session.commit()
connection.execute(
fetch_table.update().values(keep=True)
)
def downgrade():

Loading…
Cancel
Save