diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py index ca62d9e6c..2c4c1f226 100644 --- a/qutebrowser/browser/history.py +++ b/qutebrowser/browser/history.py @@ -40,7 +40,10 @@ class CompletionHistory(sql.SqlTable): def __init__(self, parent=None): 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') @@ -50,6 +53,10 @@ class WebHistory(sql.SqlTable): def __init__(self, parent=None): super().__init__("History", ['url', 'title', 'atime', 'redirect'], + constraints={'url': 'NOT NULL', + 'title': 'NOT NULL', + 'atime': 'NOT NULL', + 'redirect': 'NOT NULL'}, parent=parent) self.completion = CompletionHistory(parent=self) if sql.Query('pragma user_version').run().value() < _USER_VERSION: diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py index 375d0464d..24e2035e6 100644 --- a/qutebrowser/misc/sql.py +++ b/qutebrowser/misc/sql.py @@ -150,7 +150,7 @@ class SqlTable(QObject): def __init__(self, name, fields, constraints=None, parent=None): """Create a new table in the sql database. - Raises SqlError if the table already exists. + Does nothing if the table already exists. Args: name: Name of the table. diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index 8ae3bb1f4..c093513cb 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -140,20 +140,24 @@ def test_sorting(max_items, before, after, model_validator, hist, config_stub): def test_remove_rows(hist, model_validator): - hist.insert({'url': 'foo', 'title': 'Foo'}) - hist.insert({'url': 'bar', 'title': 'Bar'}) + hist.insert({'url': 'foo', 'title': 'Foo', 'last_atime': 0}) + hist.insert({'url': 'bar', 'title': 'Bar', 'last_atime': 0}) cat = histcategory.HistoryCategory() model_validator.set_model(cat) cat.set_pattern('') hist.delete('url', 'foo') cat.removeRows(0, 1) - model_validator.validate([('bar', 'Bar', '')]) + model_validator.validate([('bar', 'Bar', '1970-01-01')]) def test_remove_rows_fetch(hist): """removeRows should fetch enough data to make the current index valid.""" # we cannot use model_validator as it will fetch everything up front - hist.insert_batch({'url': [str(i) for i in range(300)]}) + hist.insert_batch({ + 'url': [str(i) for i in range(300)], + 'title': [str(i) for i in range(300)], + 'last_atime': [0] * 300, + }) cat = histcategory.HistoryCategory() cat.set_pattern('')