laravel-comments 0.3.0

Comments for Laravel Rust models: threaded replies, moderation, reactions, and events, without N+1 queries.
Documentation
//! The migration helper: `table.comments()`.

use laravel::db::schema::Blueprint;
use laravel_nestedset::NestedSetBlueprint;

/// Adds the columns of a comments table to a migration's blueprint. The package's own migration
/// uses it for the `comments` table.
pub trait CommentsBlueprint {
    /// Adds every column and index that [`comment_model!`](crate::comment_model) reads:
    /// the commentable, the thread's tree, the author or guest, the text, the moderation status,
    /// the timestamps, and the counters.
    fn comments(&mut self);
}

impl CommentsBlueprint for Blueprint {
    fn comments(&mut self) {
        self.id();
        self.morphs("commentable");
        self.string("thread").length(26);
        self.nested_set_scoped(&["thread"]);
        self.nested_set_depth();
        self.big_integer("author_id").nullable();
        self.string("guest_name").nullable();
        self.string("guest_email").nullable();
        self.text("body");
        self.string("status").length(16);
        self.timestamp("moderated_at").nullable();
        self.timestamp("edited_at").nullable();
        self.timestamp("deleted_at").nullable();
        self.big_integer("replies_count").default(0);
        self.big_integer("reactions_count").default(0);
        self.timestamps();

        // Top-level comments of a model, in posting order, and the moderation queue. Named, as
        // MySQL takes index names of up to 64 characters.
        self.index(["commentable_type", "commentable_id", "parent_id", "created_at"])
            .name("comments_commentable_roots_index");
        self.index(["status", "id"]).name("comments_status_index");
        self.index("author_id").name("comments_author_index");
    }
}