From f89829d9af5dba339b437bc343cb02b36096dc6e Mon Sep 17 00:00:00 2001 From: Ralph Thesen Date: Tue, 10 Sep 2024 23:28:36 +0200 Subject: [PATCH] fix: removed obsolete _db_migrate() function from SimpleAuth. - The _db_migrate function is a left over of the beta phase and was poorly implemented. - Fixed Column types and lengths (No breaking change for sqlite.) necessary for using postgres as database. Fixes #137. See comments for an example config with postgres. --- otterwiki/auth.py | 14 +------------- otterwiki/models.py | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/otterwiki/auth.py b/otterwiki/auth.py index 2f44fac..31cd929 100644 --- a/otterwiki/auth.py +++ b/otterwiki/auth.py @@ -44,7 +44,7 @@ class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128)) email = db.Column(db.String(128), index=True, unique=True) - password_hash = db.Column(db.String(128)) + password_hash = db.Column(db.String(512)) first_seen = db.Column(TimeStamp()) last_seen = db.Column(TimeStamp()) is_approved = db.Column(db.Boolean(), default=False) @@ -59,21 +59,9 @@ def __repr__(self): def __init__(self): with app.app_context(): - self._db_migrate() # create tables db.create_all() - def _db_migrate(self): - from sqlalchemy.exc import OperationalError - with db.engine.begin() as conn: - for column in ['email_confirmed', 'allow_read', 'allow_write', 'allow_upload']: - try: - sqlc = db.text("ALTER TABLE user ADD COLUMN {} BOOLEAN;".format(column)) - r = conn.execute(sqlc) - app.logger.warning("_db_migrate: Altered table 'user' added '{}'".format(column)) - except OperationalError: - pass - def user_loader(self, id): return self.User.query.filter_by(id=int(id)).first() diff --git a/otterwiki/models.py b/otterwiki/models.py index eff5d04..1a5a929 100644 --- a/otterwiki/models.py +++ b/otterwiki/models.py @@ -24,7 +24,7 @@ def process_result_value(self, value, dialect): class Preferences(db.Model): name = db.Column(db.String(256), primary_key=True) - value = db.Column(db.String(256)) + value = db.Column(db.Text) def __str__(self): return '{}: {}'.format(self.name, self.value)