Make current migrations work with postgresql

master
Tim Möhlmann 6 years ago
parent 2ced020513
commit 9b9f3731f6
No known key found for this signature in database
GPG Key ID: 8677988D8072E8DE

@ -8,8 +8,9 @@ RUN mkdir -p /app
WORKDIR /app WORKDIR /app
COPY requirements-prod.txt requirements.txt COPY requirements-prod.txt requirements.txt
RUN apk add --no-cache openssl curl \ RUN apk add --no-cache libressl curl postgresql-client \
&& apk add --no-cache --virtual build-dep openssl-dev libffi-dev python3-dev build-base \ && apk add --no-cache --virtual build-dep \
libressl-dev libffi-dev python3-dev build-base postgresql-dev \
&& pip3 install -r requirements.txt \ && pip3 install -r requirements.txt \
&& apk del --no-cache build-dep && apk del --no-cache build-dep

@ -73,14 +73,20 @@ class ConfigManager(dict):
key: os.environ.get(key, value) key: os.environ.get(key, value)
for key, value in DEFAULT_CONFIG.items() for key, value in DEFAULT_CONFIG.items()
}) })
if self.config['SQL_FLAVOR'] != 'sqlite' if self.config['DB_FLAVOR'] != 'sqlite':
self.setsql() self.setsql()
app.config = self app.config = self
def setsql(self) def setsql(self):
if not self.config['DB_PW'] if not self.config['DB_PW']:
self.config['DB_PW'] = self.config['SECRET_KEY'] self.config['DB_PW'] = self.config['SECRET_KEY']
self.config['SQLALCHEMY_DATABASE_URI'] = '{driver}://{user}:{pw}@{url}/{db}'.format(driver=DB_FLAVOR,user=DB_USER,pw=DB_PW,url=DB_URL,db=DB_NAME) self.config['SQLALCHEMY_DATABASE_URI'] = '{driver}://{user}:{pw}@{url}/{db}'.format(
driver=self.config['DB_FLAVOR'],
user=self.config['DB_USER'],
pw=self.config['DB_PW'],
url=self.config['DB_URL'],
db=self.config['DB_NAME']
)
def setdefault(self, key, value): def setdefault(self, key, value):
if key not in self.config: if key not in self.config:

@ -287,7 +287,7 @@ class User(Base, Email):
# Settings # Settings
displayed_name = db.Column(db.String(160), nullable=False, default="") displayed_name = db.Column(db.String(160), nullable=False, default="")
spam_enabled = db.Column(db.Boolean(), nullable=False, default=True) spam_enabled = db.Column(db.Boolean(), nullable=False, default=True)
spam_threshold = db.Column(db.Integer(), nullable=False, default=80.0) spam_threshold = db.Column(db.Integer(), nullable=False, default=80)
# Flask-login attributes # Flask-login attributes
is_authenticated = True is_authenticated = True
@ -441,7 +441,7 @@ class Fetch(Base):
nullable=False) nullable=False)
user = db.relationship(User, user = db.relationship(User,
backref=db.backref('fetches', cascade='all, delete-orphan')) backref=db.backref('fetches', cascade='all, delete-orphan'))
protocol = db.Column(db.Enum('imap', 'pop3'), nullable=False) protocol = db.Column(db.Enum('imap', 'pop3', name='protocol'), nullable=False)
host = db.Column(db.String(255), nullable=False) host = db.Column(db.String(255), nullable=False)
port = db.Column(db.Integer(), nullable=False) port = db.Column(db.Integer(), nullable=False)
tls = db.Column(db.Boolean(), nullable=False) tls = db.Column(db.Boolean(), nullable=False)

@ -12,9 +12,11 @@ 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
def upgrade(): def upgrade():
if app.config['DB_FLAVOR'] == 'sqlite':
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, collation="NOCASE"))

@ -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')

@ -12,9 +12,11 @@ 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
def upgrade(): def upgrade():
if app.config['DB_FLAVOR'] == 'sqlite':
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, collation="NOCASE"))
with op.batch_alter_table('alias') as batch: with op.batch_alter_table('alias') as batch:

@ -44,3 +44,4 @@ visitor==0.1.3
Werkzeug==0.14.1 Werkzeug==0.14.1
WTForms==2.2.1 WTForms==2.2.1
WTForms-Components==0.10.3 WTForms-Components==0.10.3
psycopg2

Loading…
Cancel
Save