Be explicit about constraints instead
This commit is contained in:
parent
3772084cbf
commit
7f28097f55
@ -40,7 +40,10 @@ class CompletionHistory(sql.SqlTable):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__("CompletionHistory", ['url', 'title', 'last_atime'],
|
super().__init__("CompletionHistory", ['url', 'title', 'last_atime'],
|
||||||
constraints={'url': 'PRIMARY KEY'}, parent=parent)
|
constraints={'url': 'PRIMARY KEY',
|
||||||
|
'title': 'NOT NULL',
|
||||||
|
'last_atime': 'NOT NULL'},
|
||||||
|
parent=parent)
|
||||||
self.create_index('CompletionHistoryAtimeIndex', 'last_atime')
|
self.create_index('CompletionHistoryAtimeIndex', 'last_atime')
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +53,10 @@ class WebHistory(sql.SqlTable):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__("History", ['url', 'title', 'atime', 'redirect'],
|
super().__init__("History", ['url', 'title', 'atime', 'redirect'],
|
||||||
|
constraints={'url': 'NOT NULL',
|
||||||
|
'title': 'NOT NULL',
|
||||||
|
'atime': 'NOT NULL',
|
||||||
|
'redirect': 'NOT NULL'},
|
||||||
parent=parent)
|
parent=parent)
|
||||||
self.completion = CompletionHistory(parent=self)
|
self.completion = CompletionHistory(parent=self)
|
||||||
if sql.Query('pragma user_version').run().value() < _USER_VERSION:
|
if sql.Query('pragma user_version').run().value() < _USER_VERSION:
|
||||||
|
@ -161,8 +161,7 @@ class SqlTable(QObject):
|
|||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
constraints = constraints or {}
|
constraints = constraints or {}
|
||||||
default = 'NOT NULL'
|
column_defs = ['{} {}'.format(field, constraints.get(field, ''))
|
||||||
column_defs = ['{} {}'.format(field, constraints.get(field, default))
|
|
||||||
for field in fields]
|
for field in fields]
|
||||||
q = Query("CREATE TABLE IF NOT EXISTS {name} ({column_defs})"
|
q = Query("CREATE TABLE IF NOT EXISTS {name} ({column_defs})"
|
||||||
.format(name=name, column_defs=', '.join(column_defs)))
|
.format(name=name, column_defs=', '.join(column_defs)))
|
||||||
|
Loading…
Reference in New Issue
Block a user