sets column names to be lowercase, uses utf8mb4 charset, utf8mb4_unicode_ci collation

This commit is contained in:
Oleg Silkin 2020-04-06 19:15:54 -04:00
parent d25e03d853
commit be45a70c36
6 changed files with 62 additions and 7 deletions

View file

@ -12,6 +12,7 @@ testing:
# actual database should be running MySQL
production:
charset: utf8mb4
database: mysql
name: social
user: lbry

View file

@ -0,0 +1,48 @@
USE `social`;
ALTER DATABASE `social`
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `CHANNEL`;
CREATE TABLE `CHANNEL` (
`claimid` VARCHAR(40) NOT NULL,
-- i cant tell if max name length is 255 or 256
`name` VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
CONSTRAINT `channel_pk` PRIMARY KEY (`claimid`)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `COMMENT`;
CREATE TABLE `COMMENT` (
`commentid` VARCHAR(64) NOT NULL,
`lbryclaimid` VARCHAR(40) NOT NULL,
`channelid` VARCHAR(40) DEFAULT NULL,
`body` VARCHAR(5000)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
NOT NULL,
`parentid` VARCHAR(64) DEFAULT NULL,
`signature` VARCHAR(128) DEFAULT NULL,
`signingts` VARCHAR(22) DEFAULT NULL,
`timestamp` INTEGER NOT NULL,
-- there's no way that the timestamp will ever reach 22 characters
`ishidden` BOOLEAN DEFAULT FALSE,
CONSTRAINT `COMMENT_PRIMARY_KEY` PRIMARY KEY (`commentid`),
CONSTRAINT `comment_signature_sk` UNIQUE (`signature`),
CONSTRAINT `comment_channel_fk` FOREIGN KEY (`channelid`) REFERENCES `CHANNEL` (`claimid`)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `comment_parent_fk` FOREIGN KEY (`parentid`) REFERENCES `COMMENT` (`commentid`)
ON UPDATE CASCADE ON DELETE CASCADE, -- setting null implies comment is top level
CONSTRAINT `channel_signature`
CHECK ( `signature` IS NOT NULL AND `signingts` IS NOT NULL)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
CREATE INDEX `claim_comment_index` ON `COMMENT` (`lbryclaimid`, `commentid`);
CREATE INDEX `channel_comment_index` ON `COMMENT` (`channelid`, `commentid`);

View file

@ -6,6 +6,7 @@ services:
mysql:
image: mysql/mysql-server:5.7.27
restart: "no"
command: --character_set_server=utf8mb4 --max_allowed_packet=1073741824
ports:
- "3306:3306"
environment:

View file

@ -13,24 +13,28 @@ from src.misc import clean
class Channel(Model):
claim_id = CharField(column_name='ClaimId', primary_key=True, max_length=40)
name = CharField(column_name='Name', max_length=256)
claim_id = CharField(column_name='claimid', primary_key=True, max_length=40)
name = CharField(column_name='name', max_length=256)
class Meta:
table_name = 'CHANNEL'
class Comment(Model):
comment = CharField(column_name='Body', max_length=2000)
comment = CharField(
column_name='body',
max_length=5000,
)
channel = ForeignKeyField(
backref='comments',
column_name='ChannelId',
column_name='channelid',
field='claim_id',
model=Channel,
null=True
)
comment_id = CharField(column_name='CommentId', primary_key=True, max_length=64)
is_hidden = BooleanField(column_name='IsHidden', constraints=[SQL("DEFAULT 0")])
comment_id = CharField(column_name='commentid', primary_key=True, max_length=64)
is_hidden = BooleanField(column_name='ishidden', constraints=[SQL("DEFAULT 0")])
claim_id = CharField(max_length=40, column_name='LbryClaimId')
parent = ForeignKeyField(
column_name='ParentId',

View file

@ -16,7 +16,7 @@ async def get_claim_from_id(app, claim_id, **kwargs):
def clean_input_params(kwargs: dict):
for k, v in kwargs.items():
if type(v) is str and k is not 'comment':
if type(v) is str and k != 'comment':
kwargs[k] = v.strip()
if k in ID_LIST:
kwargs[k] = v.lower()

View file

@ -28,6 +28,7 @@ def setup_database(app):
host=config[mode]['host'],
password=config[mode]['password'],
port=config[mode]['port'],
charset=config[mode]['charset'],
)
elif config[mode]['database'] == 'sqlite':
app['db'] = SqliteDatabase(