Skip to content

Commit

Permalink
fix: removed obsolete _db_migrate() function from SimpleAuth.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
redimp committed Sep 10, 2024
1 parent 44a308b commit f89829d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
14 changes: 1 addition & 13 deletions otterwiki/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion otterwiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f89829d

Please sign in to comment.