Red — README

An existing project with three schema versions

This is a project a new developer can clone and use immediately. Its current models describe v3; its complete prepared migration history is already committed. No preparation or helper script is needed. Requires Raku, Red's dependencies (zef install --/test --test-depends --deps-only . from the repository root), and the sqlite3 command-line client.

Run commands below from examples/schema-versions. Within this checkout, replace red with raku -I../../lib ../../bin/red to use the repository's CLI. The SQLite connection creates example.db here; it is ignored by Git.

VersionApplication tables
v1project (id, name)
v2project, task (id, title, project_id → project.id)
v3project, task, comment (id, body, task_id → task.id)

First checkout

red migration status
red migration apply
red migration status
sqlite3 example.db '.schema'
sqlite3 example.db '.tables'

Before application, status reports an uninitialized database. Apply executes all three migrations. A second apply reports zero work. Red also maintains its own migration bookkeeping tables.

Load fixtures

Three named fixtures provide 3 projects, 4 tasks and 3 comments. Apply them in this order on a fresh v3 database:

red fixture list
red fixture apply projects
red fixture apply tasks
red fixture apply comments
sqlite3 -header -column example.db 'SELECT * FROM project; SELECT * FROM task; SELECT * FROM comment;'

At v1 apply only projects. At v2 apply projects, then tasks. At v3 all three are available. Tasks reference the projects; comments reference the tasks. Fixtures use fixed IDs: apply each only once while its records are present. Applying an existing fixture again fails on duplicate IDs; it does not replace or clear existing records. Fixtures run in a transaction.

Go backward and forward

# v3 -> v2: drops comment, including its data.
red migration rollback
sqlite3 example.db '.schema'
sqlite3 example.db 'SELECT * FROM task;'

# v2 -> v1: drops task; project remains with its data.
red migration rollback
sqlite3 example.db '.schema'
sqlite3 example.db 'SELECT * FROM project;'

# v1 -> v3: recreates task and comment, now empty.
red migration apply
red migration status
sqlite3 example.db 'SELECT * FROM project; SELECT * FROM task; SELECT * FROM comment;'

Models in lib/ always represent v3. Use SQL to inspect older schemas; querying newer models against an older schema can fail. Rollback restores structure, not lost records. The up/down SQL and snapshots are available under migrations/.

Apply only part of the history

On a fresh database, or after rolling back all three versions:

red migration apply --to=01M6T0BGTRR7RD5PM7CB578945
sqlite3 example.db '.schema'
red migration apply --to=01M6T0BGTRMVJEEHW0WTY0930S
sqlite3 example.db '.schema'
red migration apply

--to limits forward application; use rollback to move backward. Rolling back v1 also removes project and its records. Inspect red migration status before each rollback to see the current version.

Restore data after rollback

After the v3 → v2 → v1 → v3 sequence above, projects still exist. Reload only the fixtures for the tables that were dropped:

red fixture apply tasks
red fixture apply comments
sqlite3 -header -column example.db 'SELECT p.name, t.title, c.body FROM project p LEFT JOIN task t ON t.project_id = p.id LEFT JOIN comment c ON c.task_id = t.id ORDER BY p.id, t.id, c.id;'

If you only roll back v3 to v2 and apply again, reload only comments. If you roll back all three migrations and apply again, reload all three fixtures. Migrations never load fixtures automatically.

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.