Database - AlyBadawy/Securial GitHub Wiki

🗂️ Database

Securial is database engine agnostic, meaning it works with any database supported by ActiveRecord. Whether you're using PostgreSQL, MySQL, SQLite, or another database adapter, Securial can integrate seamlessly.


🔌 Migration Integration

When you install the Securial engine, its database migration files are automatically copied to your host Rails application under:

db/migrate/

This allows you to run migrations in your app just like any other Rails migrations, giving you full control and visibility.


📦 Setting Up the Database

To prepare your database for use with Securial, follow these steps:

  1. Create the database (if it doesn't already exist):

    rails db:create
    
  2. Run the migrations (including those from Securial):

    rails db:migrate
    

[!NOTE]

💡 Notes

  • You can edit the copied migration files before running them if you need to customize any fields or indexes.

  • If you upgrade the Securial gem and new migrations are introduced, you may need to re-run:

    bin/rails securial:install:migrations
    

    This will copy any new migrations that haven’t already been added to your app.

  • Securial does not manage its own schema or maintain separate tables within the engine. All data is fully integrated into your host application’s schema.

Database IDs

Securial uses UUIDv7 for all model primary keys. These IDs are stored as strings to ensure compatibility across all database adapters. The migrations automatically set up the correct column types:

# Example of how IDs are defined in migrations
create_table :securial_roles, id: :string do |t|
  # ...other columns
end

Benefits of this approach:

  • Globally unique identifiers across all instances
  • Time-ordered UUIDs for better database performance
  • Compatible with all major database adapters (PostgreSQL, MySQL, SQLite)
  • No need for database-specific UUID extensions

[!NOTE] The IDs are automatically generated when creating new records - you don't need to handle UUID generation manually.

[!TIP] You can edit the copied migrations before running them to add additional fields to the models. If you upgrade Securial and new migrations are added, re‑run the installer to copy them into your application.


For questions or issues related to database setup, please refer to the documentation or open an issue on GitHub.