Browse Source

Convert all PostgreSQL integer keys to bigint

There is one special exception in here: the unread_user_ids column in
the message_conversations table had to be left as an integer array,
since the PostgreSQL intarray extension doesn't work with bigints. The
trigger that updates that column also needed a minor tweak.

This isn't good, but I don't really like how that was done anyway (it
was for the purpose of group messages that don't even exist), so it
could probably just be eliminated.
merge-requests/135/head
Deimos 3 years ago
parent
commit
fe42c7a685
  1. 4
      tildes/sql/init/triggers/message_replies/message_conversations.sql
  2. 19
      tildes/tildes/models/comment/comment.py
  3. 6
      tildes/tildes/models/comment/comment_bookmark.py
  4. 6
      tildes/tildes/models/comment/comment_label.py
  5. 6
      tildes/tildes/models/comment/comment_notification.py
  6. 6
      tildes/tildes/models/comment/comment_vote.py
  7. 4
      tildes/tildes/models/financials.py
  8. 13
      tildes/tildes/models/group/group.py
  9. 6
      tildes/tildes/models/group/group_script.py
  10. 4
      tildes/tildes/models/group/group_stat.py
  11. 6
      tildes/tildes/models/group/group_subscription.py
  12. 4
      tildes/tildes/models/group/group_wiki_page.py
  13. 12
      tildes/tildes/models/log/log.py
  14. 21
      tildes/tildes/models/message/message.py
  15. 4
      tildes/tildes/models/scraper/scraper_result.py
  16. 9
      tildes/tildes/models/topic/topic.py
  17. 6
      tildes/tildes/models/topic/topic_bookmark.py
  18. 6
      tildes/tildes/models/topic/topic_ignore.py
  19. 14
      tildes/tildes/models/topic/topic_schedule.py
  20. 6
      tildes/tildes/models/topic/topic_visit.py
  21. 6
      tildes/tildes/models/topic/topic_vote.py
  22. 5
      tildes/tildes/models/user/user.py
  23. 6
      tildes/tildes/models/user/user_group_settings.py
  24. 6
      tildes/tildes/models/user/user_invite_code.py
  25. 8
      tildes/tildes/models/user/user_permissions.py
  26. 4
      tildes/tildes/models/user/user_rate_limit.py

4
tildes/sql/init/triggers/message_replies/message_conversations.sql

@ -11,8 +11,8 @@ BEGIN
SET num_replies = num_replies + 1,
last_reply_time = NEW.created_time,
unread_user_ids = unread_user_ids |
CASE WHEN sender_id = NEW.sender_id THEN recipient_id
ELSE sender_id
CASE WHEN sender_id = NEW.sender_id THEN recipient_id::integer
ELSE sender_id::integer
END
WHERE conversation_id = NEW.conversation_id;
ELSIF (TG_OP = 'DELETE') THEN

19
tildes/tildes/models/comment/comment.py

@ -15,7 +15,16 @@ from pyramid.security import (
Everyone,
principals_allowed_by_permission,
)
from sqlalchemy import Boolean, Column, ForeignKey, Index, Integer, Text, TIMESTAMP
from sqlalchemy import (
BigInteger,
Boolean,
Column,
ForeignKey,
Index,
Integer,
Text,
TIMESTAMP,
)
from sqlalchemy.dialects.postgresql import TSVECTOR
from sqlalchemy.orm import deferred, relationship
from sqlalchemy.sql.expression import text
@ -72,15 +81,15 @@ class Comment(DatabaseModel):
__tablename__ = "comments"
comment_id: int = Column(Integer, primary_key=True)
comment_id: int = Column(BigInteger, primary_key=True)
topic_id: int = Column(
Integer, ForeignKey("topics.topic_id"), nullable=False, index=True
BigInteger, ForeignKey("topics.topic_id"), nullable=False, index=True
)
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, index=True
BigInteger, ForeignKey("users.user_id"), nullable=False, index=True
)
parent_comment_id: Optional[int] = Column(
Integer, ForeignKey("comments.comment_id"), index=True
BigInteger, ForeignKey("comments.comment_id"), index=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

6
tildes/tildes/models/comment/comment_bookmark.py

@ -2,7 +2,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -17,10 +17,10 @@ class CommentBookmark(DatabaseModel):
__tablename__ = "comment_bookmarks"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
comment_id: int = Column(
Integer, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

6
tildes/tildes/models/comment/comment_label.py

@ -6,7 +6,7 @@
from datetime import datetime
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, REAL, Text, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, REAL, Text, TIMESTAMP
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.orm import backref, relationship
from sqlalchemy.sql.expression import text
@ -31,13 +31,13 @@ class CommentLabel(DatabaseModel):
__tablename__ = "comment_labels"
comment_id: int = Column(
Integer, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
)
label: CommentLabelOption = Column(
ENUM(CommentLabelOption), nullable=False, primary_key=True
)
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True), nullable=False, server_default=text("NOW()")

6
tildes/tildes/models/comment/comment_notification.py

@ -8,7 +8,7 @@ from datetime import datetime
from typing import List, Tuple
from pyramid.security import Allow, DENY_ALL
from sqlalchemy import Boolean, Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Boolean, Column, ForeignKey, TIMESTAMP
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.orm import relationship, Session
from sqlalchemy.sql.expression import text
@ -37,10 +37,10 @@ class CommentNotification(DatabaseModel):
__tablename__ = "comment_notifications"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
comment_id: int = Column(
Integer, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
)
notification_type: CommentNotificationType = Column(
ENUM(CommentNotificationType), nullable=False

6
tildes/tildes/models/comment/comment_vote.py

@ -5,7 +5,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -28,10 +28,10 @@ class CommentVote(DatabaseModel):
__tablename__ = "comment_votes"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
comment_id: int = Column(
Integer, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("comments.comment_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

4
tildes/tildes/models/financials.py

@ -6,7 +6,7 @@
from decimal import Decimal
from psycopg2.extras import DateRange
from sqlalchemy import Column, Index, Integer, Numeric, Text
from sqlalchemy import BigInteger, Column, Index, Numeric, Text
from sqlalchemy.dialects.postgresql import DATERANGE, ENUM
from tildes.enums import FinancialEntryType
@ -18,7 +18,7 @@ class Financials(DatabaseModel):
__tablename__ = "financials"
entry_id: int = Column(Integer, primary_key=True)
entry_id: int = Column(BigInteger, primary_key=True)
entry_type: FinancialEntryType = Column(ENUM(FinancialEntryType), nullable=False)
description: str = Column(Text)
amount: Decimal = Column(Numeric(scale=2), nullable=False)

13
tildes/tildes/models/group/group.py

@ -7,7 +7,16 @@ from datetime import datetime
from typing import List, Optional
from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone
from sqlalchemy import Boolean, CheckConstraint, Column, Index, Integer, Text, TIMESTAMP
from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Column,
Index,
Integer,
Text,
TIMESTAMP,
)
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import deferred
from sqlalchemy.sql.expression import text
@ -34,7 +43,7 @@ class Group(DatabaseModel):
__tablename__ = "groups"
group_id: int = Column(Integer, primary_key=True)
group_id: int = Column(BigInteger, primary_key=True)
path: Ltree = Column(LtreeType, nullable=False, index=True, unique=True)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

6
tildes/tildes/models/group/group_script.py

@ -6,7 +6,7 @@
from typing import Optional
from pyramid.security import DENY_ALL
from sqlalchemy import Column, ForeignKey, Integer, Text
from sqlalchemy import BigInteger, Column, ForeignKey, Text
from sqlalchemy.orm import relationship
from tildes.models import DatabaseModel
@ -20,8 +20,8 @@ class GroupScript(DatabaseModel):
__tablename__ = "group_scripts"
script_id: int = Column(Integer, primary_key=True)
group_id: Optional[int] = Column(Integer, ForeignKey("groups.group_id"))
script_id: int = Column(BigInteger, primary_key=True)
group_id: Optional[int] = Column(BigInteger, ForeignKey("groups.group_id"))
code: str = Column(Text, nullable=False)
group: Optional[Group] = relationship("Group")

4
tildes/tildes/models/group/group_stat.py

@ -7,7 +7,7 @@ from datetime import datetime
from typing import Union
from psycopg2.extras import DateTimeTZRange
from sqlalchemy import Column, Float, ForeignKey, Index, Integer
from sqlalchemy import BigInteger, Column, Float, ForeignKey, Index
from sqlalchemy.dialects.postgresql import ENUM, TSTZRANGE
from sqlalchemy.orm import relationship
@ -23,7 +23,7 @@ class GroupStat(DatabaseModel):
__tablename__ = "group_stats"
group_id: int = Column(
Integer,
BigInteger,
ForeignKey("groups.group_id"),
nullable=False,
primary_key=True,

6
tildes/tildes/models/group/group_subscription.py

@ -5,7 +5,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -28,10 +28,10 @@ class GroupSubscription(DatabaseModel):
__tablename__ = "group_subscriptions"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("groups.group_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

4
tildes/tildes/models/group/group_wiki_page.py

@ -9,7 +9,7 @@ from typing import List, Optional
from pygit2 import Repository, Signature
from pyramid.security import Allow, DENY_ALL, Everyone
from sqlalchemy import CheckConstraint, Column, ForeignKey, Integer, Text, TIMESTAMP
from sqlalchemy import BigInteger, CheckConstraint, Column, ForeignKey, Text, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -38,7 +38,7 @@ class GroupWikiPage(DatabaseModel):
GITLAB_REPO_URL = "https://gitlab.com/tildes/tildes-wiki"
group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("groups.group_id"), nullable=False, primary_key=True
)
path: str = Column(CIText, nullable=False, primary_key=True)
page_name: str = Column(

12
tildes/tildes/models/log/log.py

@ -6,7 +6,7 @@
from typing import Any, Dict, Optional
from pyramid.request import Request
from sqlalchemy import BigInteger, Column, event, ForeignKey, Integer, Table, TIMESTAMP
from sqlalchemy import BigInteger, Column, event, ForeignKey, Table, TIMESTAMP
from sqlalchemy.dialects.postgresql import ENUM, INET, JSONB
from sqlalchemy.engine import Connection
from sqlalchemy.ext.declarative import declared_attr
@ -31,7 +31,7 @@ class BaseLog:
@declared_attr
def user_id(self) -> Column:
"""Return the user_id column."""
return Column(Integer, ForeignKey("users.user_id"), index=True)
return Column(BigInteger, ForeignKey("users.user_id"), index=True)
@declared_attr
def event_type(self) -> Column:
@ -96,7 +96,7 @@ class LogComment(DatabaseModel, BaseLog):
__tablename__ = "log_comments"
comment_id: int = Column(
Integer, ForeignKey("comments.comment_id"), index=True, nullable=False
BigInteger, ForeignKey("comments.comment_id"), index=True, nullable=False
)
comment: Comment = relationship("Comment")
@ -125,7 +125,7 @@ class LogTopic(DatabaseModel, BaseLog):
__tablename__ = "log_topics"
topic_id: int = Column(
Integer, ForeignKey("topics.topic_id"), index=True, nullable=False
BigInteger, ForeignKey("topics.topic_id"), index=True, nullable=False
)
topic: Topic = relationship("Topic")
@ -212,7 +212,7 @@ def create_inherited_tables(
# log_topics
connection.execute(
"CREATE TABLE log_topics (topic_id integer not null) INHERITS (log)"
"CREATE TABLE log_topics (topic_id bigint not null) INHERITS (log)"
)
fk_name = naming["fk"] % {
@ -230,7 +230,7 @@ def create_inherited_tables(
# log_comments
connection.execute(
"CREATE TABLE log_comments (comment_id integer not null) INHERITS (log)"
"CREATE TABLE log_comments (comment_id bigint not null) INHERITS (log)"
)
fk_name = naming["fk"] % {

21
tildes/tildes/models/message/message.py

@ -17,6 +17,7 @@ from typing import List, Optional, Sequence
from pyramid.security import Allow, DENY_ALL
from sqlalchemy import (
BigInteger,
CheckConstraint,
Column,
ForeignKey,
@ -60,12 +61,12 @@ class MessageConversation(DatabaseModel):
__tablename__ = "message_conversations"
conversation_id: int = Column(Integer, primary_key=True)
conversation_id: int = Column(BigInteger, primary_key=True)
sender_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, index=True
BigInteger, ForeignKey("users.user_id"), nullable=False, index=True
)
recipient_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, index=True
BigInteger, ForeignKey("users.user_id"), nullable=False, index=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),
@ -82,8 +83,14 @@ class MessageConversation(DatabaseModel):
)
markdown: str = deferred(Column(Text, nullable=False))
rendered_html: str = Column(Text, nullable=False)
num_replies: int = Column(Integer, nullable=False, server_default="0")
num_replies: int = Column(BigInteger, nullable=False, server_default="0")
last_reply_time: Optional[datetime] = Column(TIMESTAMP(timezone=True), index=True)
# This deliberately uses Integer instead of BigInteger, even though that's not
# correct, because the PostgreSQL intarray extension only supports integers. This
# is dangerous and *will* break if user_id values ever get larger than integers
# can hold. I'm comfortable doing something that will only be an issue if the site
# reaches 2.1 billion users though, I think this would be the least of the problems.
unread_user_ids: List[int] = Column(
ARRAY(Integer), nullable=False, server_default="{}"
)
@ -216,15 +223,15 @@ class MessageReply(DatabaseModel):
__tablename__ = "message_replies"
reply_id: int = Column(Integer, primary_key=True)
reply_id: int = Column(BigInteger, primary_key=True)
conversation_id: int = Column(
Integer,
BigInteger,
ForeignKey("message_conversations.conversation_id"),
nullable=False,
index=True,
)
sender_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, index=True
BigInteger, ForeignKey("users.user_id"), nullable=False, index=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

4
tildes/tildes/models/scraper/scraper_result.py

@ -6,7 +6,7 @@
from datetime import datetime
from typing import Any
from sqlalchemy import Column, Integer, Text, TIMESTAMP
from sqlalchemy import BigInteger, Column, Text, TIMESTAMP
from sqlalchemy.dialects.postgresql import ENUM, JSONB
from sqlalchemy.sql.expression import text
@ -19,7 +19,7 @@ class ScraperResult(DatabaseModel):
__tablename__ = "scraper_results"
result_id: int = Column(Integer, primary_key=True)
result_id: int = Column(BigInteger, primary_key=True)
url: str = Column(Text, nullable=False, index=True)
scraper_type: ScraperType = Column(ENUM(ScraperType), nullable=False)
scrape_time: datetime = Column(

9
tildes/tildes/models/topic/topic.py

@ -12,6 +12,7 @@ from urllib.parse import urlparse
from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone
from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Column,
@ -77,15 +78,15 @@ class Topic(DatabaseModel):
__tablename__ = "topics"
topic_id: int = Column(Integer, primary_key=True)
topic_id: int = Column(BigInteger, primary_key=True)
group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, index=True
BigInteger, ForeignKey("groups.group_id"), nullable=False, index=True
)
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, index=True
BigInteger, ForeignKey("users.user_id"), nullable=False, index=True
)
schedule_id: int = Column(
Integer, ForeignKey("topic_schedule.schedule_id"), index=True
BigInteger, ForeignKey("topic_schedule.schedule_id"), index=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

6
tildes/tildes/models/topic/topic_bookmark.py

@ -2,7 +2,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -17,10 +17,10 @@ class TopicBookmark(DatabaseModel):
__tablename__ = "topic_bookmarks"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
topic_id: int = Column(
Integer, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

6
tildes/tildes/models/topic/topic_ignore.py

@ -2,7 +2,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -17,10 +17,10 @@ class TopicIgnore(DatabaseModel):
__tablename__ = "topic_ignores"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
topic_id: int = Column(
Integer, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

14
tildes/tildes/models/topic/topic_schedule.py

@ -9,11 +9,11 @@ from typing import List, Optional
from dateutil.rrule import rrule
from jinja2.sandbox import SandboxedEnvironment
from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Column,
ForeignKey,
Integer,
Text,
TIMESTAMP,
)
@ -41,11 +41,13 @@ class TopicSchedule(DatabaseModel):
__tablename__ = "topic_schedule"
schedule_id: int = Column(Integer, primary_key=True)
schedule_id: int = Column(BigInteger, primary_key=True)
group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, index=True
BigInteger, ForeignKey("groups.group_id"), nullable=False, index=True
)
user_id: Optional[int] = Column(
BigInteger, ForeignKey("users.user_id"), nullable=True
)
user_id: Optional[int] = Column(Integer, ForeignKey("users.user_id"), nullable=True)
created_time: datetime = Column(
TIMESTAMP(timezone=True), nullable=False, server_default=text("NOW()")
)
@ -63,7 +65,9 @@ class TopicSchedule(DatabaseModel):
only_new_top_level_comments_in_latest: bool = Column(
Boolean, nullable=False, server_default="true"
)
latest_topic_id: int = Column(Integer, ForeignKey("topics.topic_id"), nullable=True)
latest_topic_id: int = Column(
BigInteger, ForeignKey("topics.topic_id"), nullable=True
)
group: Group = relationship("Group", innerjoin=True)
user: Optional[User] = relationship("User")

6
tildes/tildes/models/topic/topic_visit.py

@ -5,7 +5,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -29,10 +29,10 @@ class TopicVisit(DatabaseModel):
__tablename__ = "topic_visits"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
topic_id: int = Column(
Integer, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
)
visit_time: datetime = Column(
TIMESTAMP(timezone=True),

6
tildes/tildes/models/topic/topic_vote.py

@ -5,7 +5,7 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP
from sqlalchemy import BigInteger, Column, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -28,10 +28,10 @@ class TopicVote(DatabaseModel):
__tablename__ = "topic_votes"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
topic_id: int = Column(
Integer, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("topics.topic_id"), nullable=False, primary_key=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True),

5
tildes/tildes/models/user/user.py

@ -15,6 +15,7 @@ from pyramid.security import (
Everyone,
)
from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Column,
@ -68,7 +69,7 @@ class User(DatabaseModel):
__tablename__ = "users"
user_id: int = Column(Integer, primary_key=True)
user_id: int = Column(BigInteger, primary_key=True)
username: str = Column(CIText, nullable=False, unique=True)
password_hash: str = deferred(Column(Text, nullable=False))
email_address_hash: Optional[str] = deferred(Column(Text))
@ -92,7 +93,7 @@ class User(DatabaseModel):
)
num_unread_messages: int = Column(Integer, nullable=False, server_default="0")
num_unread_notifications: int = Column(Integer, nullable=False, server_default="0")
inviter_id: int = Column(Integer, ForeignKey("users.user_id"))
inviter_id: int = Column(BigInteger, ForeignKey("users.user_id"))
invite_codes_remaining: int = Column(Integer, nullable=False, server_default="0")
collapse_old_comments: bool = Column(Boolean, nullable=False, server_default="true")
comment_sort_order_default: Optional[CommentTreeSortOption] = Column(

6
tildes/tildes/models/user/user_group_settings.py

@ -5,7 +5,7 @@
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, Text
from sqlalchemy import BigInteger, Column, ForeignKey, Text
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.orm import relationship
@ -21,10 +21,10 @@ class UserGroupSettings(DatabaseModel):
__tablename__ = "user_group_settings"
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("users.user_id"), nullable=False, primary_key=True
)
group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True
BigInteger, ForeignKey("groups.group_id"), nullable=False, primary_key=True
)
default_order: Optional[TopicSortOption] = Column(ENUM(TopicSortOption))
default_period: Optional[str] = Column(Text)

6
tildes/tildes/models/user/user_invite_code.py

@ -7,7 +7,7 @@ import random
import string
from datetime import datetime
from sqlalchemy import CheckConstraint, Column, ForeignKey, Integer, Text, TIMESTAMP
from sqlalchemy import BigInteger, CheckConstraint, Column, ForeignKey, Text, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
@ -33,12 +33,12 @@ class UserInviteCode(DatabaseModel):
primary_key=True,
)
user_id: int = Column(
Integer, ForeignKey("users.user_id"), nullable=False, index=True
BigInteger, ForeignKey("users.user_id"), nullable=False, index=True
)
created_time: datetime = Column(
TIMESTAMP(timezone=True), nullable=False, server_default=text("NOW()")
)
invitee_id: int = Column(Integer, ForeignKey("users.user_id"))
invitee_id: int = Column(BigInteger, ForeignKey("users.user_id"))
user: User = relationship("User", innerjoin=True, foreign_keys=[user_id])

8
tildes/tildes/models/user/user_permissions.py

@ -3,7 +3,7 @@
"""Contains the UserPermissions class."""
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy import BigInteger, Column, ForeignKey
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.orm import relationship
@ -18,9 +18,9 @@ class UserPermissions(DatabaseModel):
__tablename__ = "user_permissions"
permission_id: int = Column(Integer, primary_key=True)
user_id: int = Column(Integer, ForeignKey("users.user_id"), nullable=False)
group_id: int = Column(Integer, ForeignKey("groups.group_id"), nullable=True)
permission_id: int = Column(BigInteger, primary_key=True)
user_id: int = Column(BigInteger, ForeignKey("users.user_id"), nullable=False)
group_id: int = Column(BigInteger, ForeignKey("groups.group_id"), nullable=True)
permission: UserPermission = Column(ENUM(UserPermission), nullable=False)
permission_type: UserPermissionType = Column(
ENUM(UserPermissionType), nullable=False, server_default="ALLOW"

4
tildes/tildes/models/user/user_rate_limit.py

@ -5,7 +5,7 @@
from datetime import timedelta
from sqlalchemy import Column, ForeignKey, Integer, Interval, Text
from sqlalchemy import BigInteger, Column, ForeignKey, Integer, Interval, Text
from sqlalchemy.orm import relationship
from tildes.models import DatabaseModel
@ -18,7 +18,7 @@ class UserRateLimit(DatabaseModel):
__tablename__ = "user_rate_limit"
user_id: int = Column(Integer, ForeignKey("users.user_id"), primary_key=True)
user_id: int = Column(BigInteger, ForeignKey("users.user_id"), primary_key=True)
action: str = Column(Text, primary_key=True)
period: timedelta = Column(Interval, nullable=False)
limit: int = Column(Integer, nullable=False)

Loading…
Cancel
Save