initial data model implementation

This commit is contained in:
2026-01-22 13:47:01 +01:00
parent bf2f9e9af7
commit c2436fab13
101 changed files with 2667 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
+6
View File
@@ -0,0 +1,6 @@
class Comment < ApplicationRecord
belongs_to :user
belongs_to :commentable, polymorphic: true
validates :body, presence: true
end
View File
+19
View File
@@ -0,0 +1,19 @@
class Entry < ApplicationRecord
belongs_to :created_by, class_name: "User", optional: true
belongs_to :updated_by, class_name: "User", optional: true
has_many :suggested_meanings, dependent: :destroy
has_many :comments, as: :commentable, dependent: :destroy
has_many :entry_versions, dependent: :destroy
enum category: {
word: 0,
phrase: 1,
name: 2,
title: 3,
reference: 4,
other: 5
}
validates :category, presence: true
end
+6
View File
@@ -0,0 +1,6 @@
class EntryVersion < ApplicationRecord
belongs_to :entry
belongs_to :user
validates :changes_made, presence: true
end
+18
View File
@@ -0,0 +1,18 @@
class SuggestedMeaning < ApplicationRecord
belongs_to :entry
belongs_to :submitted_by, class_name: "User"
belongs_to :reviewed_by, class_name: "User", optional: true
belongs_to :language,
class_name: "SupportedLanguage",
foreign_key: :language_code,
primary_key: :code
enum status: {
pending: 0,
accepted: 1,
rejected: 2
}
validates :language_code, presence: true
validates :alternative_translation, presence: true
end
+10
View File
@@ -0,0 +1,10 @@
class SupportedLanguage < ApplicationRecord
has_many :suggested_meanings,
foreign_key: :language_code,
primary_key: :code,
dependent: :restrict_with_exception
validates :code, presence: true, uniqueness: true
validates :name, presence: true
validates :native_name, presence: true
end
+27
View File
@@ -0,0 +1,27 @@
class User < ApplicationRecord
has_secure_password
belongs_to :invited_by, class_name: "User", optional: true
has_many :invited_users, class_name: "User", foreign_key: :invited_by_id, dependent: :nullify
has_many :created_entries, class_name: "Entry", foreign_key: :created_by_id, dependent: :nullify
has_many :updated_entries, class_name: "Entry", foreign_key: :updated_by_id, dependent: :nullify
has_many :submitted_suggested_meanings,
class_name: "SuggestedMeaning",
foreign_key: :submitted_by_id,
dependent: :nullify
has_many :reviewed_suggested_meanings,
class_name: "SuggestedMeaning",
foreign_key: :reviewed_by_id,
dependent: :nullify
has_many :entry_versions, dependent: :nullify
has_many :comments, dependent: :nullify
enum role: {
contributor: 0,
reviewer: 1,
admin: 2
}
validates :email, presence: true, uniqueness: true
end