adding thredded forums

This commit is contained in:
Torsten 2022-12-31 22:01:51 +02:00
parent 292a51ad3c
commit ae293e3395
10 changed files with 828 additions and 2 deletions

View File

@ -17,6 +17,7 @@ gem 'devise'
gem 'carrierwave', '>= 3.0.0.beta', '< 4.0' gem 'carrierwave', '>= 3.0.0.beta', '< 4.0'
gem "ruby2js" , git: "https://github.com/ruby2js/ruby2js/" , branch: "haml_fix" gem "ruby2js" , git: "https://github.com/ruby2js/ruby2js/" , branch: "haml_fix"
gem 'thredded', '~> 1.0'
gem "simple_form" , "5.1.0" gem "simple_form" , "5.1.0"
gem "simple_form_tailwind_css" gem "simple_form_tailwind_css"

View File

@ -69,6 +69,8 @@ GEM
rails-html-sanitizer (~> 1.1, >= 1.2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_hash (3.1.1) active_hash (3.1.1)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
active_record_union (1.3.0)
activerecord (>= 4.0)
activejob (7.0.4) activejob (7.0.4)
activesupport (= 7.0.4) activesupport (= 7.0.4)
globalid (>= 0.3.6) globalid (>= 0.3.6)
@ -92,6 +94,12 @@ GEM
addressable (2.8.1) addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0) public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2) ast (2.4.2)
autoprefixer-rails (10.4.7.0)
execjs (~> 2)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bcrypt (3.1.18) bcrypt (3.1.18)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.15.0) bootsnap (1.15.0)
@ -117,6 +125,8 @@ GEM
concurrent-ruby (1.1.10) concurrent-ruby (1.1.10)
crass (1.0.6) crass (1.0.6)
date (3.3.3) date (3.3.3)
db_text_search (1.0.0)
activerecord (>= 4.1.15)
debug (1.7.0) debug (1.7.0)
irb (>= 1.5.0) irb (>= 1.5.0)
reline (>= 0.3.1) reline (>= 0.3.1)
@ -128,8 +138,11 @@ GEM
warden (~> 1.2.3) warden (~> 1.2.3)
erubi (1.11.0) erubi (1.11.0)
erubis (2.7.0) erubis (2.7.0)
execjs (2.8.1)
ffi (1.15.5) ffi (1.15.5)
formatador (1.1.0) formatador (1.1.0)
friendly_id (5.5.0)
activerecord (>= 4.0.0)
git (1.13.0) git (1.13.0)
addressable (~> 2.8) addressable (~> 2.8)
rchardet (~> 1.8) rchardet (~> 1.8)
@ -159,11 +172,15 @@ GEM
railties (>= 5.1) railties (>= 5.1)
heroicon (1.0.0) heroicon (1.0.0)
rails (>= 5.2) rails (>= 5.2)
html-pipeline (2.14.3)
activesupport (>= 2)
nokogiri (>= 1.4)
html2haml (2.3.0) html2haml (2.3.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
haml (>= 4.0) haml (>= 4.0)
nokogiri (>= 1.6.0) nokogiri (>= 1.6.0)
ruby_parser (~> 3.5) ruby_parser (~> 3.5)
htmlentities (4.3.4)
i18n (1.12.0) i18n (1.12.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
image_processing (1.12.2) image_processing (1.12.2)
@ -172,9 +189,28 @@ GEM
importmap-rails (1.1.5) importmap-rails (1.1.5)
actionpack (>= 6.0.0) actionpack (>= 6.0.0)
railties (>= 6.0.0) railties (>= 6.0.0)
inline_svg (1.8.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.6.0) io-console (0.6.0)
irb (1.6.1) irb (1.6.1)
reline (>= 0.3.0) reline (>= 0.3.0)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
listen (3.7.1) listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3) rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10) rb-inotify (~> 0.9, >= 0.9.10)
@ -197,6 +233,8 @@ GEM
mini_mime (1.1.2) mini_mime (1.1.2)
minitest (5.16.3) minitest (5.16.3)
msgpack (1.6.0) msgpack (1.6.0)
multi_json (1.15.0)
mustache (1.1.1)
nenv (0.3.0) nenv (0.3.0)
net-imap (0.3.2) net-imap (0.3.2)
date date
@ -213,6 +251,13 @@ GEM
notiffany (0.1.3) notiffany (0.1.3)
nenv (~> 0.1) nenv (~> 0.1)
shellany (~> 0.0) shellany (~> 0.0)
onebox (2.2.19)
addressable (~> 2.8.0)
htmlentities (~> 4.3)
multi_json (~> 1.11)
mustache
nokogiri (~> 1.7)
sanitize
open4 (1.3.4) open4 (1.3.4)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parser (3.1.3.0) parser (3.1.3.0)
@ -227,6 +272,8 @@ GEM
public_suffix (5.0.1) public_suffix (5.0.1)
puma (5.6.5) puma (5.6.5)
nio4r (~> 2.0) nio4r (~> 2.0)
pundit (2.3.0)
activesupport (>= 3.0.0)
racc (1.6.1) racc (1.6.1)
rack (2.2.4) rack (2.2.4)
rack-test (2.0.2) rack-test (2.0.2)
@ -250,6 +297,8 @@ GEM
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.4.4) rails-html-sanitizer (1.4.4)
loofah (~> 2.19, >= 2.19.1) loofah (~> 2.19, >= 2.19.1)
rails_gravatar (1.0.4)
actionview
railties (7.0.4) railties (7.0.4)
actionpack (= 7.0.4) actionpack (= 7.0.4)
activesupport (= 7.0.4) activesupport (= 7.0.4)
@ -270,11 +319,15 @@ GEM
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 5.0) railties (>= 5.0)
rexml (3.2.5) rexml (3.2.5)
rinku (2.0.6)
ruby-vips (2.1.4) ruby-vips (2.1.4)
ffi (~> 1.12) ffi (~> 1.12)
ruby_parser (3.19.2) ruby_parser (3.19.2)
sexp_processor (~> 4.16) sexp_processor (~> 4.16)
rubyzip (2.3.2) rubyzip (2.3.2)
sanitize (6.0.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
sassc (2.4.0) sassc (2.4.0)
ffi (~> 1.9) ffi (~> 1.9)
sassc-rails (2.1.2) sassc-rails (2.1.2)
@ -298,6 +351,10 @@ GEM
sprockets (4.1.1) sprockets (4.1.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-es6 (0.9.2)
babel-source (>= 5.8.11)
babel-transpiler
sprockets (>= 3.0.0)
sprockets-rails (3.4.2) sprockets-rails (3.4.2)
actionpack (>= 5.2) actionpack (>= 5.2)
activesupport (>= 5.2) activesupport (>= 5.2)
@ -307,7 +364,29 @@ GEM
railties (>= 6.0.0) railties (>= 6.0.0)
temple (0.9.1) temple (0.9.1)
thor (1.2.1) thor (1.2.1)
thredded (1.0.1)
active_record_union (>= 1.3.0)
autoprefixer-rails
db_text_search
friendly_id
html-pipeline
htmlentities
inline_svg (>= 1.6.0)
kaminari
kramdown (>= 2.0.0)
kramdown-parser-gfm
nokogiri
onebox (>= 1.8.99)
pundit (>= 1.1.0)
rails (>= 5.2.0, != 6.0.0.rc2)
rails_gravatar
rinku
sanitize
sassc-rails (>= 2.0.0)
sprockets-es6
timeago_js (>= 3.0.2.2)
tilt (2.0.11) tilt (2.0.11)
timeago_js (3.0.2.2)
timeout (0.3.1) timeout (0.3.1)
tzinfo (2.0.5) tzinfo (2.0.5)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
@ -357,6 +436,7 @@ DEPENDENCIES
simple_form_tailwind_css simple_form_tailwind_css
sprockets-rails sprockets-rails
tailwindcss-rails tailwindcss-rails
thredded (~> 1.0)
web-console web-console
webdrivers webdrivers

View File

@ -12,3 +12,6 @@
* *
*= require_self *= require_self
*/ */
#thredded--container{
max-width: 60rem;
}

View File

@ -6,6 +6,9 @@ class Member < ApplicationRecord
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader
def admin
true
end
def admin? def admin?
true true
end end

View File

@ -1,6 +1,6 @@
#menu-dropdown.hidden.absolute.right-0.z-10.mt-4.w-36.origin-top-right.rounded-md.border.border-gray-100.bg-white.shadow-lg{:role => "menu"} #menu-dropdown.hidden.absolute.right-0.z-10.mt-4.w-36.origin-top-right.rounded-md.border.border-gray-100.bg-white.shadow-lg{:role => "menu"}
.p-2 .p-2
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => "#", :role => "menuitem"} %a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => "/forum", :role => "menuitem"}
Forum Forum
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => main_app.member_path(current_member), :role => "menuitem"} %a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => main_app.member_path(current_member), :role => "menuitem"}
Profile Profile

View File

@ -0,0 +1,23 @@
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title
Forum #{yield :thredded_page_title}
%meta{:content => "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0", :name => "viewport"}/
= stylesheet_link_tag "tailwind"
= stylesheet_link_tag 'thredded', 'data-turbolinks-track': 'reload'
= stylesheet_link_tag "application"
= csrf_meta_tag
= csp_meta_tag
= javascript_include_tag 'thredded', |
async: !Rails.application.config.assets.debug, |
defer: true, |
'data-turbolinks-track': 'reload' |
= RailsGravatar.prefetch_dns_tag
%meta{:content => "width=device-width, initial-scale=1, user-scalable=no", :name => "viewport"}/
%body
= render "layouts/header"
= render "layouts/messages"
= yield
= render "layouts/footer"

View File

@ -0,0 +1,191 @@
# frozen_string_literal: true
# Thredded configuration
# ==> User Configuration
# The name of the class your app uses for your users.
# By default the engine will use 'User' but if you have another name
# for your user class - change it here.
Thredded.user_class = 'Member'
# User name column, used in @mention syntax and *must* be unique.
# This is the column used to search for users' names if/when someone is @ mentioned.
Thredded.user_name_column = :name
# User display name method, by default thredded uses the user_name_column defined above
# You may want to use :to_s or some more elaborate method
# Thredded.user_display_name_method = :to_s
# The path (or URL) you will use to link to your users' profiles.
# When linking to a user, Thredded will use this lambda to spit out
# the path or url to your user. This lambda is evaluated in the view context.
# If the lambda returns nil, a span element is returned instead of a link; so
# setting this to always return nil effectively disables all user links.
Thredded.user_path = ->(user) {
user_path = :"#{Thredded.user_class_name.demodulize.underscore}_path"
main_app.respond_to?(user_path) ? main_app.send(user_path, user) : "/users/#{user.to_param}"
}
# This method is used by Thredded controllers and views to fetch the currently signed-in user
Thredded.current_user_method = :"current_#{Thredded.user_class_name.demodulize.underscore}"
# User avatar URL. rails_gravatar gem is used by default:
Thredded.avatar_url = ->(user) { RailsGravatar.src(user.email, 156, 'mm') }
# ==> Permissions Configuration
# By default, thredded uses a simple permission model, where all the users can post to all message boards,
# and admins and moderators are determined by a flag on the users table.
# The name of the moderator flag column on the users table.
Thredded.moderator_column = :admin
# The name of the admin flag column on the users table.
Thredded.admin_column = :admin
# Whether posts and topics pending moderation are visible to regular users.
Thredded.content_visible_while_pending_moderation = true
# This model can be customized further by overriding a handful of methods on the User model.
# For more information, see app/models/thredded/user_extender.rb.
# ==> UI configuration
# How to calculate the position of messageboards in a list:
# :position (default) set the position manually (new messageboards go to the bottom, by creation timestamp)
# :last_post_at_desc most recent post first
# :topics_count_desc most topics first
Thredded.messageboards_order = :position
# Whether admin users see button to delete entire messageboards on the messageboard edit page.
Thredded.show_messageboard_delete_button = false
# Whether MessageboardGroup show page is enabled.
Thredded.show_messageboard_group_page = true
# Whether users that are following a topic are listed on the topic page.
Thredded.show_topic_followers = false
# Whether the list of users who are currently online is displayed.
Thredded.currently_online_enabled = true
# Whether private messaging functionality is enabled.
Thredded.private_messaging_enabled = true
# The number of topics to display per page.
# Thredded.topics_per_page = 50
# The number of posts to display per page in a topic.
# Thredded.posts_per_page = 25
# The layout for rendering Thredded views.
Thredded.layout = 'thredded_layout'
# ==> Email Configuration
# Email "From:" field will use the following
# (this is also used as the "To" address for both email notifcations, as all the recipients are on bcc)
# Thredded.email_from = 'no-reply@example.com'
# Emails going out will prefix the "Subject:" with the following string
# Thredded.email_outgoing_prefix = '[My Forum] '
#
# The parent mailer for all Thredded mailers
# Thredded.parent_mailer = 'ActionMailer::Base'
# ==> Model configuration
# The range of valid messageboard name lengths. Default:
# Thredded.messageboard_name_length_range = (1..60)
#
# The range of valid topic title lengths. Default:
# Thredded.topic_title_length_range = (1..200)
# ==> Routes and URLs
# How Thredded generates URL slugs from text:
# Default:
# Thredded.slugifier = ->(input) { input.parameterize }
# If your forum is in a language other than English, you might want to use the babosa gem instead
# Thredded.slugifier = ->(input) { Babosa::Identifier.new(input).normalize.transliterate(:russian).to_s }
# By default, thredded uses integers for record ID route constraints.
# For integer based IDs (default):
# Thredded.routes_id_constraint = /[1-9]\d*/
#
# For UUID based IDs (example):
# Thredded.routes_id_constraint = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
# ==> Post Content Formatting
# Customize the way Thredded handles post formatting.
# ===> Emoji using the 'gemoji' gem
# 1. Install `gemoji` following instruction at https://github.com/github/gemoji.
# 2. Uncomment the following line:
# Thredded::ContentFormatter.after_markup_filters.insert(1, HTML::Pipeline::EmojiFilter)
# Change the HTML sanitization settings used by Thredded.
# See the Sanitize docs for more information on the underlying library: https://github.com/rgrove/sanitize/#readme
# E.g. to allow a custom element <custom-element>:
# Thredded::ContentFormatter.allowlist[:elements] += %w(custom-element)
# ==> User autocompletion (Private messages and @-mentions)
# Thredded.autocomplete_min_length = 2 lower to 1 if have 1-letter names -- increase if you want
# ==> Error Handling
# By default Thredded just renders a flash alert on errors such as Topic not found, or Login required.
# Below is an example of overriding the default behavior on LoginRequired:
#
# Rails.application.config.to_prepare do
# Thredded::ApplicationController.module_eval do
# # Render sign in page:
# rescue_from Thredded::Errors::LoginRequired do |exception|
# flash.now[:notice] = exception.message
# controller = Users::SessionsController.new
# controller.request = request
# controller.request.env['devise.mapping'] = Devise.mappings[:user]
# controller.response = response
# controller.response_options = { status: :forbidden }
# controller.process(:new)
# end
# end
# end
# ==> View hooks
#
# Customize the UI before/after/replacing individual components.
# See the full list of view hooks and their arguments by running:
#
# $ grep view_hooks -R --include '*.html.erb' "$(bundle show thredded)"
#
# Rails.application.config.to_prepare do
# Thredded.view_hooks.post_form.content_text_area.config.before do |form:, **args|
# # This is called in the Thredded view context, so all Thredded helpers and URLs are accessible here directly.
# 'hi'
# end
# end
# ==> Topic following
#
# By default, a user will be subscribed to a topic they've created. Uncomment this to not subscribe them:
#
# Thredded.auto_follow_when_creating_topic = false
#
# By default, a user will be subscribed to (follow) a topic they post in. Uncomment this to not subscribe them:
#
# Thredded.auto_follow_when_posting_in_topic = false
#
# By default, a user will be subscribed to the topic they get @-mentioned in.
# Individual users can disable this in the Notification Settings.
# To change the default for all users, simply change the default value of the `follow_topics_on_mention` column
# of the `thredded_user_preferences` and `thredded_user_messageboard_preferences` tables.
# ==> Notifiers
#
# Change how users can choose to be notified, by adding notifiers here, or removing the initializer altogether
#
# default:
# Thredded.notifiers = [Thredded::EmailNotifier.new]
#
# none:
# Thredded.notifiers = []
#
# add in (must install separate gem (under development) as well):
# Thredded.notifiers = [Thredded::EmailNotifier.new, Thredded::PushoverNotifier.new(ENV['PUSHOVER_APP_ID'])]

View File

@ -4,6 +4,7 @@ Rails.application.routes.draw do
resources :members resources :members
mount Thredded::Engine => '/forum'
mount Merged::Engine => "/merged" mount Merged::Engine => "/merged"

View File

@ -0,0 +1,277 @@
# frozen_string_literal: true
# This migration comes from thredded (originally 20160329231848)
require 'thredded/base_migration'
# rubocop:disable Metrics/ClassLength
# rubocop:disable Metrics/MethodLength
class CreateThredded < Thredded::BaseMigration
def change
unless table_exists?(:friendly_id_slugs)
# The user might have installed FriendlyId separately already.
create_table :friendly_id_slugs do |t|
t.string :slug, null: false
t.integer :sluggable_id, null: false
t.string :sluggable_type, limit: 50
t.string :scope
t.datetime :created_at
end
add_index :friendly_id_slugs, :sluggable_id
add_index :friendly_id_slugs, %i[slug sluggable_type], length: { slug: 140, sluggable_type: 50 }
add_index :friendly_id_slugs, %i[slug sluggable_type scope],
length: { slug: 70, sluggable_type: 50, scope: 70 },
unique: true
add_index :friendly_id_slugs, :sluggable_type
end
create_table :thredded_categories do |t|
t.references :messageboard, null: false, index: false
t.text :name, null: false
t.text :description
t.timestamps null: false
t.text :slug, null: false
t.index %i[messageboard_id slug],
name: :index_thredded_categories_on_messageboard_id_and_slug,
unique: true,
length: { slug: max_key_length }
t.index [:messageboard_id], name: :index_thredded_categories_on_messageboard_id
end
DbTextSearch::CaseInsensitive.add_index connection, :thredded_categories, :name,
name: :thredded_categories_name_ci,
**(max_key_length ? { length: max_key_length } : {})
create_table :thredded_messageboards do |t|
t.text :name, null: false
t.text :slug
t.text :description
t.integer :topics_count, default: 0
t.integer :posts_count, default: 0
t.integer :position, null: false
t.references :last_topic, index: false
t.references :messageboard_group, index: false
t.timestamps null: false
t.boolean :locked, null: false, default: false
t.index [:messageboard_group_id], name: :index_thredded_messageboards_on_messageboard_group_id
t.index [:slug],
name: :index_thredded_messageboards_on_slug,
unique: true,
length: { slug: max_key_length }
end
create_table :thredded_posts do |t|
t.references :user, type: user_id_type, index: false
t.text :content, limit: 65_535
t.string :source, limit: 191, default: 'web'
t.references :postable, null: false, index: false
t.references :messageboard, null: false, index: false
t.integer :moderation_state, null: false
t.timestamps null: false
t.index %i[moderation_state updated_at],
order: { updated_at: :asc },
name: :index_thredded_posts_for_display
t.index [:messageboard_id], name: :index_thredded_posts_on_messageboard_id
t.index [:postable_id], name: :index_thredded_posts_on_postable_id
t.index %i[postable_id created_at], name: :index_thredded_posts_on_postable_id_and_created_at
t.index [:user_id], name: :index_thredded_posts_on_user_id
end
DbTextSearch::FullText.add_index connection, :thredded_posts, :content, name: :thredded_posts_content_fts
create_table :thredded_private_posts do |t|
t.references :user, type: user_id_type, index: false
t.text :content, limit: 65_535
t.references :postable, null: false, index: false
t.timestamps null: false
t.index %i[postable_id created_at], name: :index_thredded_private_posts_on_postable_id_and_created_at
end
create_table :thredded_private_topics do |t|
t.references :user, type: user_id_type, index: false
t.references :last_user, type: user_id_type, index: false
t.text :title, null: false
t.text :slug, null: false
t.integer :posts_count, default: 0
t.string :hash_id, limit: 20, null: false
t.datetime :last_post_at
t.timestamps null: false
t.index [:last_post_at], name: :index_thredded_private_topics_on_last_post_at
t.index [:hash_id], name: :index_thredded_private_topics_on_hash_id
t.index [:slug],
name: :index_thredded_private_topics_on_slug,
unique: true,
length: { slug: max_key_length }
end
create_table :thredded_private_users do |t|
t.references :private_topic, index: false
t.references :user, type: user_id_type, index: false
t.timestamps null: false
t.index [:private_topic_id], name: :index_thredded_private_users_on_private_topic_id
t.index [:user_id], name: :index_thredded_private_users_on_user_id
end
create_table :thredded_topic_categories do |t|
t.references :topic, null: false, index: false
t.references :category, null: false, index: false
t.index [:category_id], name: :index_thredded_topic_categories_on_category_id
t.index [:topic_id], name: :index_thredded_topic_categories_on_topic_id
end
create_table :thredded_topics do |t|
t.references :user, type: user_id_type, index: false
t.references :last_user, type: user_id_type, index: false
t.text :title, null: false
t.text :slug, null: false
t.references :messageboard, null: false, index: false
t.integer :posts_count, default: 0, null: false
t.boolean :sticky, default: false, null: false
t.boolean :locked, default: false, null: false
t.string :hash_id, limit: 20, null: false
t.integer :moderation_state, null: false
t.datetime :last_post_at
t.timestamps null: false
t.index %i[moderation_state sticky updated_at],
order: { sticky: :desc, updated_at: :desc },
name: :index_thredded_topics_for_display
t.index [:last_post_at], name: :index_thredded_topics_on_last_post_at
t.index [:hash_id], name: :index_thredded_topics_on_hash_id
t.index [:slug],
name: :index_thredded_topics_on_slug,
unique: true,
length: { slug: max_key_length }
t.index [:messageboard_id], name: :index_thredded_topics_on_messageboard_id
t.index [:user_id], name: :index_thredded_topics_on_user_id
end
DbTextSearch::FullText.add_index connection, :thredded_topics, :title, name: :thredded_topics_title_fts
create_table :thredded_user_details do |t|
t.references :user, type: user_id_type, null: false, index: false
t.datetime :latest_activity_at
t.integer :posts_count, default: 0
t.integer :topics_count, default: 0
t.datetime :last_seen_at
t.integer :moderation_state, null: false, default: 0 # pending_moderation
t.timestamp :moderation_state_changed_at
t.timestamps null: false
t.index %i[moderation_state moderation_state_changed_at],
order: { moderation_state_changed_at: :desc },
name: :index_thredded_user_details_for_moderations
t.index %i[latest_activity_at], name: :index_thredded_user_details_on_latest_activity_at
t.index %i[user_id], name: :index_thredded_user_details_on_user_id, unique: true
end
create_table :thredded_messageboard_users do |t|
t.references :thredded_user_detail, null: false, index: false
t.references :thredded_messageboard, null: false, index: false
t.datetime :last_seen_at, null: false
t.index %i[thredded_messageboard_id thredded_user_detail_id],
name: :index_thredded_messageboard_users_primary,
unique: true
t.index %i[thredded_messageboard_id last_seen_at],
name: :index_thredded_messageboard_users_for_recently_active
end
add_foreign_key :thredded_messageboard_users, :thredded_user_details,
column: :thredded_user_detail_id, on_delete: :cascade
add_foreign_key :thredded_messageboard_users, :thredded_messageboards,
column: :thredded_messageboard_id, on_delete: :cascade
create_table :thredded_user_preferences do |t|
t.references :user, type: user_id_type, null: false, index: false
t.boolean :follow_topics_on_mention, default: true, null: false
t.boolean :auto_follow_topics, default: false, null: false
t.timestamps null: false
t.index [:user_id], name: :index_thredded_user_preferences_on_user_id, unique: true
end
create_table :thredded_user_messageboard_preferences do |t|
t.references :user, type: user_id_type, null: false, index: false
t.references :messageboard, null: false, index: false
t.boolean :follow_topics_on_mention, default: true, null: false
t.boolean :auto_follow_topics, default: false, null: false
t.timestamps null: false
t.index %i[user_id messageboard_id],
name: :thredded_user_messageboard_preferences_user_id_messageboard_id,
unique: true
end
%i[topic private_topic].each do |topics_table|
table_name = :"thredded_user_#{topics_table}_read_states"
create_table table_name do |t|
t.references :messageboard, null: false, index: true if table_name == :thredded_user_topic_read_states
t.references :user, type: user_id_type, null: false, index: false
t.references :postable, null: false, index: false
t.integer :unread_posts_count, default: 0, null: false
t.integer :read_posts_count, :integer, default: 0, null: false
t.timestamp :read_at, null: false
t.index %i[user_id postable_id], name: :"#{table_name}_user_postable", unique: true
end
end
add_index :thredded_user_topic_read_states, %i[user_id messageboard_id],
name: :thredded_user_topic_read_states_user_messageboard
create_table :thredded_messageboard_groups do |t|
t.string :name
t.integer :position, null: false
t.timestamps null: false
end
create_table :thredded_user_topic_follows do |t|
t.references :user, type: user_id_type, null: false, index: false
t.references :topic, null: false, index: false
t.datetime :created_at, null: false
t.integer :reason, limit: 1
t.index %i[user_id topic_id], name: :thredded_user_topic_follows_user_topic, unique: true
end
create_table :thredded_post_moderation_records do |t|
t.references :post, index: false
t.references :messageboard, index: false
t.text :post_content, limit: 65_535
t.references :post_user, index: false, type: user_id_type
t.text :post_user_name
t.references :moderator, index: false, type: user_id_type
t.integer :moderation_state, null: false
t.integer :previous_moderation_state, null: false
t.timestamp :created_at, null: false
t.index %i[messageboard_id created_at],
order: { created_at: :desc },
name: :index_thredded_moderation_records_for_display
end
create_table :thredded_notifications_for_private_topics do |t|
t.references :user, null: false, index: false, type: user_id_type
t.string :notifier_key, null: false, limit: 90
t.boolean :enabled, default: true, null: false
t.index %i[user_id notifier_key],
name: 'thredded_notifications_for_private_topics_unique', unique: true
end
create_table :thredded_notifications_for_followed_topics do |t|
t.references :user, null: false, index: false, type: user_id_type
t.string :notifier_key, null: false, limit: 90
t.boolean :enabled, default: true, null: false
t.index %i[user_id notifier_key],
name: 'thredded_notifications_for_followed_topics_unique', unique: true
end
create_table :thredded_messageboard_notifications_for_followed_topics do |t|
t.references :user, null: false, index: false, type: user_id_type
t.references :messageboard, null: false, index: false
t.string :notifier_key, null: false, limit: 90
t.boolean :enabled, default: true, null: false
t.index %i[user_id messageboard_id notifier_key],
name: 'thredded_messageboard_notifications_for_followed_topics_unique', unique: true
end
create_table :thredded_user_post_notifications do |t|
t.references :user, null: false, index: false, type: user_id_type
t.references :post, null: false, index: false
t.datetime :notified_at, null: false
t.index :post_id, name: :index_thredded_user_post_notifications_on_post_id
t.index %i[user_id post_id], name: :index_thredded_user_post_notifications_on_user_id_and_post_id, unique: true
end
add_foreign_key :thredded_user_post_notifications,
Thredded.user_class.table_name, column: :user_id, on_delete: :cascade
add_foreign_key :thredded_user_post_notifications,
:thredded_posts, column: :post_id, on_delete: :cascade
end
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/ClassLength

249
db/schema.rb generated
View File

@ -10,10 +10,22 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_12_20_150958) do ActiveRecord::Schema[7.0].define(version: 2022_12_31_154221) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
create_table "friendly_id_slugs", force: :cascade do |t|
t.string "slug", null: false
t.integer "sluggable_id", null: false
t.string "sluggable_type", limit: 50
t.string "scope"
t.datetime "created_at", precision: nil
t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
t.index ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id"
t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type"
end
create_table "members", force: :cascade do |t| create_table "members", force: :cascade do |t|
t.string "name" t.string "name"
t.string "bio" t.string "bio"
@ -34,4 +46,239 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_20_150958) do
t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true
end end
create_table "thredded_categories", force: :cascade do |t|
t.bigint "messageboard_id", null: false
t.text "name", null: false
t.text "description"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.text "slug", null: false
t.index "lower(name) text_pattern_ops", name: "thredded_categories_name_ci"
t.index ["messageboard_id", "slug"], name: "index_thredded_categories_on_messageboard_id_and_slug", unique: true
t.index ["messageboard_id"], name: "index_thredded_categories_on_messageboard_id"
end
create_table "thredded_messageboard_groups", force: :cascade do |t|
t.string "name"
t.integer "position", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
end
create_table "thredded_messageboard_notifications_for_followed_topics", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "messageboard_id", null: false
t.string "notifier_key", limit: 90, null: false
t.boolean "enabled", default: true, null: false
t.index ["user_id", "messageboard_id", "notifier_key"], name: "thredded_messageboard_notifications_for_followed_topics_unique", unique: true
end
create_table "thredded_messageboard_users", force: :cascade do |t|
t.bigint "thredded_user_detail_id", null: false
t.bigint "thredded_messageboard_id", null: false
t.datetime "last_seen_at", precision: nil, null: false
t.index ["thredded_messageboard_id", "last_seen_at"], name: "index_thredded_messageboard_users_for_recently_active"
t.index ["thredded_messageboard_id", "thredded_user_detail_id"], name: "index_thredded_messageboard_users_primary", unique: true
end
create_table "thredded_messageboards", force: :cascade do |t|
t.text "name", null: false
t.text "slug"
t.text "description"
t.integer "topics_count", default: 0
t.integer "posts_count", default: 0
t.integer "position", null: false
t.bigint "last_topic_id"
t.bigint "messageboard_group_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.boolean "locked", default: false, null: false
t.index ["messageboard_group_id"], name: "index_thredded_messageboards_on_messageboard_group_id"
t.index ["slug"], name: "index_thredded_messageboards_on_slug", unique: true
end
create_table "thredded_notifications_for_followed_topics", force: :cascade do |t|
t.bigint "user_id", null: false
t.string "notifier_key", limit: 90, null: false
t.boolean "enabled", default: true, null: false
t.index ["user_id", "notifier_key"], name: "thredded_notifications_for_followed_topics_unique", unique: true
end
create_table "thredded_notifications_for_private_topics", force: :cascade do |t|
t.bigint "user_id", null: false
t.string "notifier_key", limit: 90, null: false
t.boolean "enabled", default: true, null: false
t.index ["user_id", "notifier_key"], name: "thredded_notifications_for_private_topics_unique", unique: true
end
create_table "thredded_post_moderation_records", force: :cascade do |t|
t.bigint "post_id"
t.bigint "messageboard_id"
t.text "post_content"
t.bigint "post_user_id"
t.text "post_user_name"
t.bigint "moderator_id"
t.integer "moderation_state", null: false
t.integer "previous_moderation_state", null: false
t.datetime "created_at", precision: nil, null: false
t.index ["messageboard_id", "created_at"], name: "index_thredded_moderation_records_for_display", order: { created_at: :desc }
end
create_table "thredded_posts", force: :cascade do |t|
t.bigint "user_id"
t.text "content"
t.string "source", limit: 191, default: "web"
t.bigint "postable_id", null: false
t.bigint "messageboard_id", null: false
t.integer "moderation_state", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index "to_tsvector('english'::regconfig, content)", name: "thredded_posts_content_fts", using: :gist
t.index ["messageboard_id"], name: "index_thredded_posts_on_messageboard_id"
t.index ["moderation_state", "updated_at"], name: "index_thredded_posts_for_display"
t.index ["postable_id", "created_at"], name: "index_thredded_posts_on_postable_id_and_created_at"
t.index ["postable_id"], name: "index_thredded_posts_on_postable_id"
t.index ["user_id"], name: "index_thredded_posts_on_user_id"
end
create_table "thredded_private_posts", force: :cascade do |t|
t.bigint "user_id"
t.text "content"
t.bigint "postable_id", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["postable_id", "created_at"], name: "index_thredded_private_posts_on_postable_id_and_created_at"
end
create_table "thredded_private_topics", force: :cascade do |t|
t.bigint "user_id"
t.bigint "last_user_id"
t.text "title", null: false
t.text "slug", null: false
t.integer "posts_count", default: 0
t.string "hash_id", limit: 20, null: false
t.datetime "last_post_at", precision: nil
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["hash_id"], name: "index_thredded_private_topics_on_hash_id"
t.index ["last_post_at"], name: "index_thredded_private_topics_on_last_post_at"
t.index ["slug"], name: "index_thredded_private_topics_on_slug", unique: true
end
create_table "thredded_private_users", force: :cascade do |t|
t.bigint "private_topic_id"
t.bigint "user_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["private_topic_id"], name: "index_thredded_private_users_on_private_topic_id"
t.index ["user_id"], name: "index_thredded_private_users_on_user_id"
end
create_table "thredded_topic_categories", force: :cascade do |t|
t.bigint "topic_id", null: false
t.bigint "category_id", null: false
t.index ["category_id"], name: "index_thredded_topic_categories_on_category_id"
t.index ["topic_id"], name: "index_thredded_topic_categories_on_topic_id"
end
create_table "thredded_topics", force: :cascade do |t|
t.bigint "user_id"
t.bigint "last_user_id"
t.text "title", null: false
t.text "slug", null: false
t.bigint "messageboard_id", null: false
t.integer "posts_count", default: 0, null: false
t.boolean "sticky", default: false, null: false
t.boolean "locked", default: false, null: false
t.string "hash_id", limit: 20, null: false
t.integer "moderation_state", null: false
t.datetime "last_post_at", precision: nil
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index "to_tsvector('english'::regconfig, title)", name: "thredded_topics_title_fts", using: :gist
t.index ["hash_id"], name: "index_thredded_topics_on_hash_id"
t.index ["last_post_at"], name: "index_thredded_topics_on_last_post_at"
t.index ["messageboard_id"], name: "index_thredded_topics_on_messageboard_id"
t.index ["moderation_state", "sticky", "updated_at"], name: "index_thredded_topics_for_display", order: { sticky: :desc, updated_at: :desc }
t.index ["slug"], name: "index_thredded_topics_on_slug", unique: true
t.index ["user_id"], name: "index_thredded_topics_on_user_id"
end
create_table "thredded_user_details", force: :cascade do |t|
t.bigint "user_id", null: false
t.datetime "latest_activity_at", precision: nil
t.integer "posts_count", default: 0
t.integer "topics_count", default: 0
t.datetime "last_seen_at", precision: nil
t.integer "moderation_state", default: 0, null: false
t.datetime "moderation_state_changed_at", precision: nil
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["latest_activity_at"], name: "index_thredded_user_details_on_latest_activity_at"
t.index ["moderation_state", "moderation_state_changed_at"], name: "index_thredded_user_details_for_moderations", order: { moderation_state_changed_at: :desc }
t.index ["user_id"], name: "index_thredded_user_details_on_user_id", unique: true
end
create_table "thredded_user_messageboard_preferences", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "messageboard_id", null: false
t.boolean "follow_topics_on_mention", default: true, null: false
t.boolean "auto_follow_topics", default: false, null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["user_id", "messageboard_id"], name: "thredded_user_messageboard_preferences_user_id_messageboard_id", unique: true
end
create_table "thredded_user_post_notifications", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "post_id", null: false
t.datetime "notified_at", precision: nil, null: false
t.index ["post_id"], name: "index_thredded_user_post_notifications_on_post_id"
t.index ["user_id", "post_id"], name: "index_thredded_user_post_notifications_on_user_id_and_post_id", unique: true
end
create_table "thredded_user_preferences", force: :cascade do |t|
t.bigint "user_id", null: false
t.boolean "follow_topics_on_mention", default: true, null: false
t.boolean "auto_follow_topics", default: false, null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["user_id"], name: "index_thredded_user_preferences_on_user_id", unique: true
end
create_table "thredded_user_private_topic_read_states", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "postable_id", null: false
t.integer "unread_posts_count", default: 0, null: false
t.integer "read_posts_count", default: 0, null: false
t.integer "integer", default: 0, null: false
t.datetime "read_at", precision: nil, null: false
t.index ["user_id", "postable_id"], name: "thredded_user_private_topic_read_states_user_postable", unique: true
end
create_table "thredded_user_topic_follows", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "topic_id", null: false
t.datetime "created_at", precision: nil, null: false
t.integer "reason", limit: 2
t.index ["user_id", "topic_id"], name: "thredded_user_topic_follows_user_topic", unique: true
end
create_table "thredded_user_topic_read_states", force: :cascade do |t|
t.bigint "messageboard_id", null: false
t.bigint "user_id", null: false
t.bigint "postable_id", null: false
t.integer "unread_posts_count", default: 0, null: false
t.integer "read_posts_count", default: 0, null: false
t.integer "integer", default: 0, null: false
t.datetime "read_at", precision: nil, null: false
t.index ["messageboard_id"], name: "index_thredded_user_topic_read_states_on_messageboard_id"
t.index ["user_id", "messageboard_id"], name: "thredded_user_topic_read_states_user_messageboard"
t.index ["user_id", "postable_id"], name: "thredded_user_topic_read_states_user_postable", unique: true
end
add_foreign_key "thredded_messageboard_users", "thredded_messageboards", on_delete: :cascade
add_foreign_key "thredded_messageboard_users", "thredded_user_details", on_delete: :cascade
add_foreign_key "thredded_user_post_notifications", "members", column: "user_id", on_delete: :cascade
add_foreign_key "thredded_user_post_notifications", "thredded_posts", column: "post_id", on_delete: :cascade
end end