sets column names to be lowercase, uses utf8mb4 charset, utf8mb4_unicode_ci collation
This commit is contained in:
parent
d25e03d853
commit
be45a70c36
6 changed files with 62 additions and 7 deletions
|
@ -12,6 +12,7 @@ testing:
|
||||||
|
|
||||||
# actual database should be running MySQL
|
# actual database should be running MySQL
|
||||||
production:
|
production:
|
||||||
|
charset: utf8mb4
|
||||||
database: mysql
|
database: mysql
|
||||||
name: social
|
name: social
|
||||||
user: lbry
|
user: lbry
|
||||||
|
|
48
database/default_after.sql
Normal file
48
database/default_after.sql
Normal 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`);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ services:
|
||||||
mysql:
|
mysql:
|
||||||
image: mysql/mysql-server:5.7.27
|
image: mysql/mysql-server:5.7.27
|
||||||
restart: "no"
|
restart: "no"
|
||||||
|
command: --character_set_server=utf8mb4 --max_allowed_packet=1073741824
|
||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
- "3306:3306"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -13,24 +13,28 @@ from src.misc import clean
|
||||||
|
|
||||||
|
|
||||||
class Channel(Model):
|
class Channel(Model):
|
||||||
claim_id = CharField(column_name='ClaimId', primary_key=True, max_length=40)
|
claim_id = CharField(column_name='claimid', primary_key=True, max_length=40)
|
||||||
name = CharField(column_name='Name', max_length=256)
|
name = CharField(column_name='name', max_length=256)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
table_name = 'CHANNEL'
|
table_name = 'CHANNEL'
|
||||||
|
|
||||||
|
|
||||||
class Comment(Model):
|
class Comment(Model):
|
||||||
comment = CharField(column_name='Body', max_length=2000)
|
comment = CharField(
|
||||||
|
column_name='body',
|
||||||
|
max_length=5000,
|
||||||
|
|
||||||
|
)
|
||||||
channel = ForeignKeyField(
|
channel = ForeignKeyField(
|
||||||
backref='comments',
|
backref='comments',
|
||||||
column_name='ChannelId',
|
column_name='channelid',
|
||||||
field='claim_id',
|
field='claim_id',
|
||||||
model=Channel,
|
model=Channel,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
comment_id = CharField(column_name='CommentId', primary_key=True, max_length=64)
|
comment_id = CharField(column_name='commentid', primary_key=True, max_length=64)
|
||||||
is_hidden = BooleanField(column_name='IsHidden', constraints=[SQL("DEFAULT 0")])
|
is_hidden = BooleanField(column_name='ishidden', constraints=[SQL("DEFAULT 0")])
|
||||||
claim_id = CharField(max_length=40, column_name='LbryClaimId')
|
claim_id = CharField(max_length=40, column_name='LbryClaimId')
|
||||||
parent = ForeignKeyField(
|
parent = ForeignKeyField(
|
||||||
column_name='ParentId',
|
column_name='ParentId',
|
||||||
|
|
|
@ -16,7 +16,7 @@ async def get_claim_from_id(app, claim_id, **kwargs):
|
||||||
|
|
||||||
def clean_input_params(kwargs: dict):
|
def clean_input_params(kwargs: dict):
|
||||||
for k, v in kwargs.items():
|
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()
|
kwargs[k] = v.strip()
|
||||||
if k in ID_LIST:
|
if k in ID_LIST:
|
||||||
kwargs[k] = v.lower()
|
kwargs[k] = v.lower()
|
||||||
|
|
|
@ -28,6 +28,7 @@ def setup_database(app):
|
||||||
host=config[mode]['host'],
|
host=config[mode]['host'],
|
||||||
password=config[mode]['password'],
|
password=config[mode]['password'],
|
||||||
port=config[mode]['port'],
|
port=config[mode]['port'],
|
||||||
|
charset=config[mode]['charset'],
|
||||||
)
|
)
|
||||||
elif config[mode]['database'] == 'sqlite':
|
elif config[mode]['database'] == 'sqlite':
|
||||||
app['db'] = SqliteDatabase(
|
app['db'] = SqliteDatabase(
|
||||||
|
|
Loading…
Reference in a new issue