Skip to content
Snippets Groups Projects
Commit 8770dec7 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add citext module for case-insensitive string type

The citext module provides a case-insensitive character string type.
Use CIText for QRCodeMixin name column.
name should be case-insensitive to avoid duplicate names.
parent 190d5c94
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ def register_cli(app):
@app.cli.command()
def initdb():
"""Create the database tables and initialize them with default values"""
db.engine.execute('CREATE EXTENSION IF NOT EXISTS citext')
db.create_all()
for instance in defaults:
db.session.add(instance)
......
......@@ -13,6 +13,7 @@ import uuid
import qrcode
from sqlalchemy.types import TypeDecorator, CHAR
from sqlalchemy.dialects.postgresql import UUID
from citext import CIText
from flask_login import UserMixin
from .extensions import db, login_manager, ldap_manager
from . import utils
......@@ -126,7 +127,7 @@ class User(db.Model, UserMixin):
class QRCodeMixin:
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False, unique=True)
name = db.Column(CIText, nullable=False, unique=True)
def image(self):
"""Return a QRCode image to identify a record
......
......@@ -56,4 +56,5 @@ dependencies:
- ldap3==2.2.4
- pyasn1==0.2.3
- pyjwt==1.4.2
- sqlalchemy-citext==1.3.post0
- visitor==0.1.3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment