Skip to main content

BackboneModule

Trait BackboneModule 

Source
pub trait BackboneModule: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn version(&self) -> &'static str;
    fn migrations_path(&self) -> Option<PathBuf>;

    // Provided methods
    fn dependencies(&self) -> Vec<&'static str> { ... }
    fn seeds_path(&self) -> Option<PathBuf> { ... }
    fn on_boot<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn migration_info(&self) -> Option<MigrationInfo> { ... }
    fn seed_info(&self) -> Option<SeedInfo> { ... }
}
Expand description

Trait for Backbone modules with migration support

Implement this trait to register a module with the Backbone framework. The framework will automatically discover and run migrations for all registered modules in dependency order.

§Example

ⓘ
use backbone_core::module::BackboneModule;
use std::path::PathBuf;

pub struct BersihirModule;

impl BackboneModule for BersihirModule {
    fn name(&self) -> &'static str { "bersihir" }
    fn version(&self) -> &'static str { env!("CARGO_PKG_VERSION") }

    fn dependencies(&self) -> Vec<&'static str> {
        vec!["sapiens"] // Depends on user module
    }

    fn migrations_path(&self) -> Option<PathBuf> {
        Some(PathBuf::from("libs/modules/bersihir/migrations"))
    }
}

Required Methods§

Source

fn name(&self) -> &'static str

Returns the unique identifier for this module

This should be a short, lowercase name like “bersihir”, “sapiens”, etc.

Source

fn version(&self) -> &'static str

Returns the version of this module

Typically uses env!("CARGO_PKG_VERSION") to get from Cargo.toml

Source

fn migrations_path(&self) -> Option<PathBuf>

Returns the path to this module’s migrations directory

Path should be relative to the repository root. Return None if the module has no migrations.

§Example paths:
  • libs/modules/bersihir/migrations
  • libs/modules/sapiens/migrations

Provided Methods§

Source

fn dependencies(&self) -> Vec<&'static str>

Returns the list of module names this module depends on

Dependencies are used to determine migration order. A module’s migrations will only run after all its dependencies have been migrated.

§Returns

A list of module names (e.g., vec!["sapiens", "bucket"])

Source

fn seeds_path(&self) -> Option<PathBuf>

Returns the path to this module’s seeds directory (optional)

Seeds are used to populate the database with initial data.

Source

fn on_boot<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called after migrations are run to initialize the module

Use this for any setup that needs to happen after the database is ready but before the application starts serving requests.

Source

fn on_shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the application is shutting down

Use this for cleanup tasks.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a health check for this module

Returns true if the module is healthy and ready to serve requests.

Source

fn migration_info(&self) -> Option<MigrationInfo>

Get migration info for this module

Source

fn seed_info(&self) -> Option<SeedInfo>

Get seed info for this module

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§