Default to NOT NULL for table constraints

Ideally, we'd update all existing tables to add the new constraints, but sqlite
doesn't offer an easy way to do so: https://www.sqlite.org/lang_altertable.html

Since that migration really isn't worth the effort, we only set the constraint
for new tables...
This commit is contained in:
Florian Bruhin 2017-10-03 07:49:27 +02:00
parent b06a38ce7e
commit 1603b15cfd

View File

@ -161,7 +161,8 @@ class SqlTable(QObject):
self._name = name
constraints = constraints or {}
column_defs = ['{} {}'.format(field, constraints.get(field, ''))
default = 'NOT NULL'
column_defs = ['{} {}'.format(field, constraints.get(field, default))
for field in fields]
q = Query("CREATE TABLE IF NOT EXISTS {name} ({column_defs})"
.format(name=name, column_defs=', '.join(column_defs)))