remove unique contraint for user.nickname
This commit is contained in:
parent
bcfc8ba9b2
commit
4033958341
6 changed files with 36 additions and 9 deletions
|
@ -129,7 +129,7 @@ class Parser(object):
|
||||||
nickname, name = v.split(':', 1)
|
nickname, name = v.split(':', 1)
|
||||||
if nickname:
|
if nickname:
|
||||||
try:
|
try:
|
||||||
u = self._user.query.filter_by(nickname=nickname).one()
|
u = self._user.query.filter_by(nickname=nickname, peered=True).one()
|
||||||
except sqlalchemy.orm.exc.NoResultFound:
|
except sqlalchemy.orm.exc.NoResultFound:
|
||||||
ids = []
|
ids = []
|
||||||
return self.in_ids(ids, exclude)
|
return self.in_ids(ids, exclude)
|
||||||
|
|
|
@ -95,4 +95,4 @@ FULLTEXT_SUPPORT = fulltext.platform_supported()
|
||||||
if not FULLTEXT_SUPPORT:
|
if not FULLTEXT_SUPPORT:
|
||||||
config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext']
|
config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext']
|
||||||
|
|
||||||
DB_VERSION = 15
|
DB_VERSION = 16
|
||||||
|
|
|
@ -43,11 +43,11 @@ CREATE TABLE user (
|
||||||
peered BOOLEAN,
|
peered BOOLEAN,
|
||||||
online BOOLEAN,
|
online BOOLEAN,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
UNIQUE (nickname),
|
|
||||||
CHECK (queued IN (0, 1)),
|
CHECK (queued IN (0, 1)),
|
||||||
CHECK (peered IN (0, 1)),
|
CHECK (peered IN (0, 1)),
|
||||||
CHECK (online IN (0, 1))
|
CHECK (online IN (0, 1))
|
||||||
);
|
);
|
||||||
|
CREATE INDEX ix_user_nichname ON user (nichname);
|
||||||
CREATE TABLE metadata (
|
CREATE TABLE metadata (
|
||||||
created DATETIME,
|
created DATETIME,
|
||||||
modified DATETIME,
|
modified DATETIME,
|
||||||
|
|
|
@ -373,6 +373,8 @@ class Update(Thread):
|
||||||
db_version = migrate_13()
|
db_version = migrate_13()
|
||||||
if db_version < 15:
|
if db_version < 15:
|
||||||
db_version = migrate_15()
|
db_version = migrate_15()
|
||||||
|
if db_version < 16:
|
||||||
|
db_version = migrate_16()
|
||||||
settings.server['db_version'] = db_version
|
settings.server['db_version'] = db_version
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -437,7 +439,7 @@ def migrate_5():
|
||||||
'DROP INDEX IF EXISTS user_metadata_index',
|
'DROP INDEX IF EXISTS user_metadata_index',
|
||||||
'CREATE UNIQUE INDEX user_metadata_index ON user_metadata(item_id, user_id)',
|
'CREATE UNIQUE INDEX user_metadata_index ON user_metadata(item_id, user_id)',
|
||||||
'UPDATE sort SET sharemetadata = 0',
|
'UPDATE sort SET sharemetadata = 0',
|
||||||
]),
|
])
|
||||||
with db.session() as session:
|
with db.session() as session:
|
||||||
import user.models
|
import user.models
|
||||||
for m in user.models.Metadata.query:
|
for m in user.models.Metadata.query:
|
||||||
|
@ -631,3 +633,28 @@ def migrate_15():
|
||||||
del u.info['local']
|
del u.info['local']
|
||||||
u.save()
|
u.save()
|
||||||
return 15
|
return 15
|
||||||
|
|
||||||
|
def migrate_16():
|
||||||
|
db.run_sql([
|
||||||
|
'''CREATE TABLE user2 (
|
||||||
|
created DATETIME,
|
||||||
|
modified DATETIME,
|
||||||
|
id VARCHAR(43) NOT NULL,
|
||||||
|
info BLOB,
|
||||||
|
nickname VARCHAR(256),
|
||||||
|
pending VARCHAR(64),
|
||||||
|
queued BOOLEAN,
|
||||||
|
peered BOOLEAN,
|
||||||
|
online BOOLEAN,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CHECK (queued IN (0, 1)),
|
||||||
|
CHECK (peered IN (0, 1)),
|
||||||
|
CHECK (online IN (0, 1))
|
||||||
|
)''',
|
||||||
|
'''INSERT INTO user2 (created, modified, id, info, nickname, pending, queued, peered, online)
|
||||||
|
SELECT created, modified, id, info, nickname, pending, queued, peered, online FROM user''',
|
||||||
|
'DROP TABLE user',
|
||||||
|
'ALTER TABLE user2 RENAME TO user',
|
||||||
|
'CREATE INDEX IF NOT EXISTS ix_user_nickname ON user (nickname)'
|
||||||
|
])
|
||||||
|
return 16
|
||||||
|
|
|
@ -30,7 +30,7 @@ class User(db.Model):
|
||||||
id = sa.Column(sa.String(43), primary_key=True)
|
id = sa.Column(sa.String(43), primary_key=True)
|
||||||
info = sa.Column(MutableDict.as_mutable(sa.PickleType(pickler=json_pickler)))
|
info = sa.Column(MutableDict.as_mutable(sa.PickleType(pickler=json_pickler)))
|
||||||
|
|
||||||
nickname = sa.Column(sa.String(256), unique=True)
|
nickname = sa.Column(sa.String(256), index=True)
|
||||||
|
|
||||||
pending = sa.Column(sa.String(64)) # sent|received
|
pending = sa.Column(sa.String(64)) # sent|received
|
||||||
queued = sa.Column(sa.Boolean())
|
queued = sa.Column(sa.Boolean())
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from tornado.websocket import WebSocketHandler, WebSocketClosedError
|
||||||
from tornado.websocket import WebSocketHandler
|
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
from tornado.iostream import StreamClosedError
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from oxtornado import json_dumps
|
from oxtornado import json_dumps
|
||||||
|
@ -72,9 +72,9 @@ class Handler(WebSocketHandler):
|
||||||
try:
|
try:
|
||||||
task = self.write_message(message)
|
task = self.write_message(message)
|
||||||
await task
|
await task
|
||||||
except tornado.iostream.StreamClosedError as e:
|
except StreamClosedError as e:
|
||||||
self.on_close()
|
self.on_close()
|
||||||
except tornado.websocket.WebSocketClosedError as e:
|
except WebSocketClosedError as e:
|
||||||
self.on_close()
|
self.on_close()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue