Red — cli

Red CLI

Red CLI is a tool to give easy access to some of Red features. Currently it has this experimental features:

  • list-tables

    list tables on a given db connection

$ red list-tables --driver=SQLite --database=example.db     
post
sqlite_sequence
person
  • print-stub

    prints a stub code to use the given database

$ red print-stub --driver=SQLite --schema-class=Blog --database=example.db
use Red:api<2>;
use Blog;

red-defaults "SQLite", :database("example.db");

.say for Post.^all;
.say for SqliteSequence.^all;
.say for Person.^all;
  • migration prepare-database

Receives database connection and a list of models and create those on that database. If passed the option --populate calls the .^populate metamethod on those models.

$ red migration prepare-database --models=Ad --populate --driver=SQLite

The Ad module must be available in Raku's module search path. For a local lib/ directory, set RAKULIB=lib before running the command.

  • migration-plan - WiP

  • generate-code - WiP

Named fixtures

Store named database snapshots in a configurable directory:

use Red;
use Red::Migration::Configuration;

config {
    .models = [User, Post];
    .connections = %(default => { database 'SQLite', :database<app.sqlite> });
    .fixtures-directory = 'fixtures'; # default
}

The models must be imported before this configuration. Relative fixture paths start at the directory containing red.rakuconf.

red fixture save demo
red fixture list
red fixture apply demo
red fixture save demo --force
red fixture apply demo --config=config/development.rakuconf

save exports every row of the configured models into fixtures/demo.raku, preserving IDs, NULLs and stored column values. It orders rows by foreign keys, including references within one model. Missing referenced rows and cycles that prevent insertion fail without publishing a partial fixture. An existing fixture requires --force to replace it.

list prints valid fixture names alphabetically, without extensions. It does not open the database or execute fixtures; a missing directory produces an empty list. Names contain only ASCII letters, digits, underscores and hyphens.

apply executes the named Raku script in a transaction using Red's normal connection resolution. Existing tables and the same configured model names are required; model order may change. Conflicts and exceptions roll back all inserted rows. Reapplying executes the script again; Red keeps no fixture history and performs no automatic updates or migrations. In a migration test environment, commands use the disposable test database.

Generated scripts call Model.^populate(:rows([...]), :deflated) through the configured model types. :deflated hydrates stored values with the model's column inflators before insertion. Handwritten trusted scripts may import models and call User.^populate without arguments, or pass ordinary attribute values with :rows. Existing custom no-argument population methods continue to work; explicit rows use the generic insertion path.

SQLite and MySQL advance automatic IDs for explicit inserts. PostgreSQL sequences are advanced after the script succeeds, without lowering their existing values. Sequence counters can have gaps after failed transactions, as with normal inserts.

Fixtures contain executable Raku code and should only be applied from trusted projects. Values without a supported serializable representation are rejected.

Rebuild a migration database

red migration drop-tables
red migration reset
red migration reset --force --connection=development

drop-tables removes managed model and historical tables plus all migration bookkeeping. reset then reapplies the prepared migrations, including their seed data. Both preserve the migration files and show a confirmation prompt unless --force is supplied. Reset does not automatically apply fixtures. See versioned migrations for dependency handling and transaction behavior.

Red v0.2.17

A Raku ORM

Authors

  • Fernando Correa de Oliveira

License

Artistic-2.0

Dependencies

ConfigurationDBIishUUIDJSON::Fast

Test Dependencies

Provides

  • CX::Red::Bool
  • MetamodelX::Red::Comparate
  • MetamodelX::Red::Describable
  • MetamodelX::Red::Dirtable
  • MetamodelX::Red::GlobalNotifiable
  • MetamodelX::Red::Id
  • MetamodelX::Red::Migration
  • MetamodelX::Red::Model
  • MetamodelX::Red::OnDB
  • MetamodelX::Red::Populatable
  • MetamodelX::Red::PreFetch
  • MetamodelX::Red::Refreshable
  • MetamodelX::Red::Relationship
  • MetamodelX::Red::Specialisable
  • MetamodelX::Red::SubModelHOW
  • MetamodelX::Red::Supply
  • MetamodelX::Red::View
  • MetamodelX::Red::VirtualView
  • Red
  • Red::AST
  • Red::AST::AddForeignKeyOnTable
  • Red::AST::BeginTransaction
  • Red::AST::Between
  • Red::AST::BoundFilter
  • Red::AST::Case
  • Red::AST::Chained
  • Red::AST::ChangeColumn
  • Red::AST::Comment
  • Red::AST::CommitTransaction
  • Red::AST::Constraints
  • Red::AST::CreateColumn
  • Red::AST::CreateIndex
  • Red::AST::CreateTable
  • Red::AST::CreateView
  • Red::AST::DateTimeFuncs
  • Red::AST::Delete
  • Red::AST::Divisible
  • Red::AST::DriverExtension
  • Red::AST::DropColumn
  • Red::AST::Empty
  • Red::AST::Function
  • Red::AST::Generic::Infix
  • Red::AST::Generic::Postfix
  • Red::AST::Generic::Prefix
  • Red::AST::Infix
  • Red::AST::Infixes
  • Red::AST::Insert
  • Red::AST::Intersect
  • Red::AST::IsDefined
  • Red::AST::JsonItem
  • Red::AST::JsonOperation
  • Red::AST::JsonRemoveItem
  • Red::AST::JsonSetItem
  • Red::AST::LastInsertedRow
  • Red::AST::Minus
  • Red::AST::MultiSelect
  • Red::AST::Native
  • Red::AST::Next
  • Red::AST::Operator
  • Red::AST::Optimizer::AND
  • Red::AST::Optimizer::Case
  • Red::AST::Optimizer::OR
  • Red::AST::Ordering
  • Red::AST::ProductSource
  • Red::AST::ProjectionField
  • Red::AST::Reference
  • Red::AST::RegexCapture
  • Red::AST::RegexChars
  • Red::AST::RegexMatch
  • Red::AST::ReleaseSavepoint
  • Red::AST::RollbackToSavepoint
  • Red::AST::RollbackTransaction
  • Red::AST::RowContext
  • Red::AST::RowParameter
  • Red::AST::Savepoint
  • Red::AST::Select
  • Red::AST::StringFuncs
  • Red::AST::TableComment
  • Red::AST::Unary
  • Red::AST::Union
  • Red::AST::Update
  • Red::AST::Value
  • Red::Attr::Column
  • Red::Attr::Index
  • Red::Attr::Query
  • Red::Attr::Relationship
  • Red::Class
  • Red::Cli
  • Red::Cli::Column
  • Red::Cli::Relationship
  • Red::Cli::Table
  • Red::Column
  • Red::ColumnMethods
  • Red::Compiler::Emitter
  • Red::Compiler::RakuAST
  • Red::Compiler::Regex
  • Red::Compiler::Runtime
  • Red::Compiler::Template
  • Red::Config
  • Red::DB
  • Red::Database
  • Red::DefaultResultSeq
  • Red::Do
  • Red::Driver
  • Red::Driver::Cache
  • Red::Driver::Cache::Memory
  • Red::Driver::CacheInvalidateOnWrite
  • Red::Driver::CacheWithStrKey
  • Red::Driver::CommonSQL
  • Red::Driver::Events
  • Red::Driver::Migrations
  • Red::Driver::Mock
  • Red::Driver::SQLite
  • Red::Driver::SQLite::Regex
  • Red::Driver::SQLite::SQLiteMaster
  • Red::Driver::SQLite::SchemaReader
  • Red::Event
  • Red::Fixture
  • Red::Formatter
  • Red::Formatter::ResultSeq
  • Red::Formatter::ResultSeq::Vertical
  • Red::FromRelationship
  • Red::GlobalEvents
  • Red::HiddenFromSQLCommenting
  • Red::Index
  • Red::LockType
  • Red::Migration::Applied
  • Red::Migration::Artifact
  • Red::Migration::Bundle
  • Red::Migration::Column
  • Red::Migration::Configuration
  • Red::Migration::Data
  • Red::Migration::Dependencies
  • Red::Migration::Driver
  • Red::Migration::Environment
  • Red::Migration::File
  • Red::Migration::Import
  • Red::Migration::Logical
  • Red::Migration::Manager
  • Red::Migration::Migration
  • Red::Migration::Planner
  • Red::Migration::Resolution
  • Red::Migration::SQL
  • Red::Migration::Scripts
  • Red::Migration::Snapshot
  • Red::Migration::Storage
  • Red::Migration::Table
  • Red::Migration::Test
  • Red::Model
  • Red::Operators
  • Red::Phaser
  • Red::PrepareCode
  • Red::Projection
  • Red::QueryPlan
  • Red::QueryPlan::Cache
  • Red::Regex
  • Red::Regex::Automaton
  • Red::Regex::Unicode
  • Red::ResultAssociative
  • Red::ResultSeq
  • Red::ResultSeq::Iterator
  • Red::ResultSeq::Supply
  • Red::ResultSeqMethods
  • Red::ResultSeqSeq
  • Red::RowSecurity
  • Red::RowSecurity::Context
  • Red::RowSecurity::DDL
  • Red::RowSecurity::PostgreSQL
  • Red::RowSecurity::Statement
  • Red::RowSecurity::Write
  • Red::Runtime::Configuration
  • Red::Schema
  • Red::SchemaReader
  • Red::Statement
  • Red::Traits
  • Red::Transaction::Guard
  • Red::Type
  • Red::Type::Json
  • Red::Type::Map
  • Red::Utils
  • X::Red::Exceptions
  • X::Red::Migration

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.