You've already forked Mailu
mirror of
https://github.com/Mailu/Mailu.git
synced 2025-11-27 22:18:22 +02:00
Fix remaining migration scripts and remove initdb/flushdb from manage.py
This commit is contained in:
35
.env.dist
35
.env.dist
@@ -29,34 +29,24 @@ HOSTNAME=mail.mailu.io
|
|||||||
# Postmaster local part (will append the main mail domain)
|
# Postmaster local part (will append the main mail domain)
|
||||||
POSTMASTER=admin
|
POSTMASTER=admin
|
||||||
|
|
||||||
# Docker-compose project name, this will prepended to containers names.
|
# Choose how secure connections will behave (value: letsencrypt, cert, notls)
|
||||||
COMPOSE_PROJECT_NAME=mailu
|
TLS_FLAVOR=cert
|
||||||
|
|
||||||
# Default password scheme used for newly created accounts and changed passwords
|
|
||||||
# (value: SHA512-CRYPT, SHA256-CRYPT, MD5-CRYPT, CRYPT)
|
|
||||||
PASSWORD_SCHEME=SHA512-CRYPT
|
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# Optional features
|
# 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
|
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)
|
# Choose which webmail to run if any (values: roundcube, rainloop, none)
|
||||||
WEBMAIL=none
|
WEBMAIL=none
|
||||||
|
|
||||||
# Expose the admin interface in publicly (values: yes, no)
|
|
||||||
EXPOSE_ADMIN=no
|
|
||||||
|
|
||||||
# Dav server implementation (value: radicale, none)
|
# Dav server implementation (value: radicale, none)
|
||||||
WEBDAV=none
|
WEBDAV=none
|
||||||
|
|
||||||
# Antivirus solution (value: none, clamav)
|
# Antivirus solution (value: clamav, none)
|
||||||
ANTIVIRUS=clamav
|
ANTIVIRUS=none
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# Mail settings
|
# Mail settings
|
||||||
@@ -85,15 +75,16 @@ DMARC_RUA=admin
|
|||||||
DMARC_RUF=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
|
# SSL DHPARAM Bits
|
||||||
NGINX_SSL_DHPARAM_BITS=2048
|
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 import app, manager, db
|
||||||
from mailu.admin import models
|
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
|
@manager.command
|
||||||
def admin(localpart, domain_name, password):
|
def admin(localpart, domain_name, password):
|
||||||
|
|||||||
@@ -13,23 +13,35 @@ down_revision = '27ae2f102682'
|
|||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
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():
|
def upgrade():
|
||||||
|
connection = op.get_bind()
|
||||||
# Make sure that every value is already an Integer
|
# Make sure that every value is already an Integer
|
||||||
for user in models.User.query.all():
|
for user in connection.execute(user_table.select()):
|
||||||
user.spam_threshold = int(user.spam_threshold)
|
connection.execute(
|
||||||
db.session.commit()
|
user_table.update().where(
|
||||||
|
user_table.c.email == user.email
|
||||||
|
).values(
|
||||||
|
spam_threshold=int(user.spam_threshold)
|
||||||
|
)
|
||||||
|
)
|
||||||
# Migrate the table
|
# Migrate the table
|
||||||
with op.batch_alter_table('user') as batch:
|
with op.batch_alter_table('user') as batch:
|
||||||
batch.alter_column(
|
batch.alter_column(
|
||||||
'spam_threshold', existing_type=db.Numeric(), type_=db.Integer())
|
'spam_threshold', existing_type=sa.Numeric(), type_=sa.Integer())
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
# Migrate the table
|
# Migrate the table
|
||||||
with op.batch_alter_table('user') as batch:
|
with op.batch_alter_table('user') as batch:
|
||||||
batch.alter_column(
|
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
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
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():
|
def upgrade():
|
||||||
|
connection = op.get_bind()
|
||||||
# spam_threshold is a X/15 based value, we're converting it to percent.
|
# spam_threshold is a X/15 based value, we're converting it to percent.
|
||||||
for user in User.query.all():
|
for user in connection.execute(user_table.select()):
|
||||||
user.spam_threshold = int(100. * float(user.spam_threshold or 0.) / 15.)
|
connection.execute(
|
||||||
db.session.commit()
|
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%
|
# 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', default=80.)
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
connection = op.get_bind()
|
||||||
# spam_threshold is a X/15 based value, we're converting it from percent.
|
# spam_threshold is a X/15 based value, we're converting it from percent.
|
||||||
for user in User.query.all():
|
for user in connection.execute(user_table.select()):
|
||||||
user.spam_threshold = int(15. * float(user.spam_threshold or 0.) / 100.)
|
connection.execute(
|
||||||
db.session.commit()
|
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
|
# 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', default=10.)
|
||||||
|
|||||||
@@ -13,18 +13,24 @@ down_revision = '2335c80a6bc3'
|
|||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from mailu import app, db
|
from mailu import app
|
||||||
from mailu.admin import models
|
|
||||||
|
|
||||||
|
fetch_table = sa.Table(
|
||||||
|
'fetch',
|
||||||
|
sa.MetaData(),
|
||||||
|
sa.Column('keep', sa.Boolean())
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
|
connection = op.get_bind()
|
||||||
op.add_column('fetch', sa.Column('keep', sa.Boolean(), nullable=False, server_default=sa.sql.expression.false()))
|
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
|
# also apply the current config value if set
|
||||||
if app.config.get("FETCHMAIL_KEEP", "False") == "True":
|
if app.config.get("FETCHMAIL_KEEP", "False") == "True":
|
||||||
for fetch in models.Fetch.query.all():
|
connection.execute(
|
||||||
fetch.keep = True
|
fetch_table.update().values(keep=True)
|
||||||
db.session.commit()
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|||||||
Reference in New Issue
Block a user