Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zeeguu/core/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from .user_language import UserLanguage

from .user_article import UserArticle
from .starred_article import StarredArticle
from .article_difficulty_feedback import ArticleDifficultyFeedback

from .feed import Feed
Expand Down
6 changes: 5 additions & 1 deletion zeeguu/core/model/context_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class ContextType(db.Model):
EXAMPLE_SENTENCE,
]

__table_args__ = {"mysql_collate": "utf8_bin"}
# Named for the index production already has, so nobody generates a second one.
__table_args__ = (
db.UniqueConstraint("type", name="unique_context_type"),
{"mysql_collate": "utf8_bin"},
)

id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(45))
Expand Down
8 changes: 7 additions & 1 deletion zeeguu/core/model/level_adapted_article_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class LevelAdaptedArticleText(db.Model):
added — renaming it would have churned the two context joins and every FK.)
"""

__table_args__ = {"mysql_collate": "utf8_bin"}
# Named for the index production already has (added by
# tools/migrations/26-08-12--add_article_level_summary.sql), so nobody
# generates a second one.
__table_args__ = (
db.UniqueConstraint("article_id", "cefr_level", name="uq_article_level"),
{"mysql_collate": "utf8_bin"},
)

id = db.Column(db.Integer, primary_key=True)

Expand Down
7 changes: 6 additions & 1 deletion zeeguu/core/model/new_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@


class NewText(db.Model):
__table_args__ = {"mysql_collate": "utf8_bin"}
# HASH_INDEX is production's own name for this index; keep it so nobody
# generates a second one.
__table_args__ = (
db.UniqueConstraint("content_hash", name="HASH_INDEX"),
{"mysql_collate": "utf8_bin"},
)

id = db.Column(db.Integer, primary_key=True)

Expand Down
7 changes: 6 additions & 1 deletion zeeguu/core/model/source_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@


class SourceText(db.Model):
__table_args__ = {"mysql_collate": "utf8_bin"}
# HASH_INDEX is production's own name for this index; keep it so nobody
# generates a second one. It is what find_or_create's hash lookup relies on.
__table_args__ = (
db.UniqueConstraint("content_hash", name="HASH_INDEX"),
{"mysql_collate": "utf8_bin"},
)

id = db.Column(db.Integer, primary_key=True)
# this mapes to TEXT in the mysql which can hold about 15K words
Expand Down
13 changes: 9 additions & 4 deletions zeeguu/core/model/starred_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ class StarredArticle(db.Model):

"""

__table_args__ = {"mysql_collate": "utf8_bin"}
# url_id is production's own name for this index; keep it so nobody
# generates a second one. This was a bare UniqueConstraint further down the
# class body -- which does attach to the table -- but the module was missing
# from zeeguu.core.model's imports, so the table never reached
# db.create_all() and the test database had no starred_article at all.
__table_args__ = (
UniqueConstraint("url_id", "user_id", name="url_id"),
{"mysql_collate": "utf8_bin"},
)

id = Column(Integer, primary_key=True)

Expand All @@ -43,9 +51,6 @@ class StarredArticle(db.Model):
# Useful for ordering past read articles
starred_date = Column(DateTime)

# Together an url_id and user_id identify an article
UniqueConstraint(url_id, user_id)

def __init__(self, user, url, _title: str, language):
self.user = user
self.url = url
Expand Down
7 changes: 6 additions & 1 deletion zeeguu/core/model/teacher_cohort_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@


class TeacherCohortMap(db.Model):
__table_args__ = {"mysql_collate": "utf8_bin"}
# user_id_2 is production's own (auto-generated) name for this index; keep it
# so nobody generates a second one under a tidier name.
__table_args__ = (
db.UniqueConstraint("user_id", "cohort_id", name="user_id_2"),
{"mysql_collate": "utf8_bin"},
)

id = Column(Integer, primary_key=True)

Expand Down
6 changes: 5 additions & 1 deletion zeeguu/core/model/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@


class Text(db.Model):
__table_args__ = {"mysql_collate": "utf8_bin"}
# Named for the index production already has, so nobody generates a second one.
__table_args__ = (
db.UniqueConstraint("content_hash", name="content_hash"),
{"mysql_collate": "utf8_bin"},
)

id = db.Column(db.Integer, primary_key=True)

Expand Down
5 changes: 5 additions & 0 deletions zeeguu/core/model/user_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class UserAvatar(db.Model):
__tablename__ = "user_avatar"
# One avatar per user. Named for the index production already has
# (tools/migrations/26-03-13--add_user_avatar.sql), so nobody generates a
# second one -- and so update_or_create's find-then-insert cannot quietly
# produce two avatars for a user in the test database.
__table_args__ = (db.UniqueConstraint("user_id", name="user_id"),)

id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
Expand Down
10 changes: 9 additions & 1 deletion zeeguu/core/model/user_onboarding_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ class UserOnboardingMessage(db.Model):
when that dismissal was performed. If not, this field will be null

"""
__table_args__ = {"mysql_collate": "utf8_bin"}
# Named for the index production already has, so nobody generates a second one.
__table_args__ = (
db.UniqueConstraint(
"user_id",
"onboarding_message_id",
name="ux_user_onboarding_message_user_message",
),
{"mysql_collate": "utf8_bin"},
)

id = db.Column(db.Integer, primary_key=True)

Expand Down
10 changes: 9 additions & 1 deletion zeeguu/core/model/user_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@


class UserWord(db.Model):
__table_args__ = {"mysql_collate": "utf8_bin"}
# Named for the index production already has (added by
# tools/migrations/25-05-24--adding_the_user_word_table.sql), so nobody
# generates a second one under a different name. Declared here so the
# SQLite test database refuses the duplicate pairs MySQL refuses -- without
# it, a test exercising the find_or_create race passes against unfixed code.
__table_args__ = (
db.UniqueConstraint("user_id", "meaning_id", name="unique_user_word"),
{"mysql_collate": "utf8_bin"},
)
__tablename__ = "user_word" # Explicitly set table name for migration

id = db.Column(db.Integer, primary_key=True)
Expand Down
Loading