Class: Familia::Migration::RakeTasks

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/familia/migration/rake_tasks.rb

Overview

RakeTasks provides a set of Rake tasks for managing Familia migrations.

Tasks are installed automatically when this file is required. Available tasks:

familia:migrate - Run all pending migrations familia:migrate:run - Run all pending migrations familia:migrate:status - Show migration status table familia:migrate:dry_run - Preview pending migrations (dry run) familia:migrate:rollback[ID] - Rollback a specific migration familia:migrate:validate - Validate migration dependencies familia:migrate:schema_drift - List models with schema drift

Examples:

Loading tasks in a Rakefile

require 'familia/migration/rake_tasks'

Loading tasks via .rake file

load 'familia/migration/rake_tasks.rake'

Instance Method Summary collapse

Constructor Details

#initializeRakeTasks

Returns a new instance of RakeTasks.



29
30
31
# File 'lib/familia/migration/rake_tasks.rb', line 29

def initialize
  define_tasks
end

Instance Method Details

#define_tasksObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/familia/migration/rake_tasks.rb', line 33

def define_tasks
  namespace :familia do
    namespace :migrate do
      desc 'Run all pending migrations'
      task :run do
        runner = Runner.new
        results = runner.run(dry_run: false)
        print_results(results)
      end

      desc 'Show migration status table'
      task :status do
        runner = Runner.new
        print_status(runner.status)
      end

      desc 'Preview pending migrations (dry run)'
      task :dry_run do
        runner = Runner.new
        results = runner.run(dry_run: true)
        print_results(results)
      end

      desc 'Rollback a specific migration'
      task :rollback, [:id] do |_t, args|
        abort 'Usage: rake familia:migrate:rollback[MIGRATION_ID]' unless args[:id]

        runner = Runner.new
        result = runner.rollback(args[:id])
        print_result(result)
      end

      desc 'Validate migration dependencies'
      task :validate do
        runner = Runner.new
        issues = runner.validate

        if issues.empty?
          puts 'All migrations valid'
        else
          puts "Found #{issues.size} issue(s):"
          issues.each do |issue|
            puts "  - #{issue[:type]}: #{issue[:message] || issue[:dependency] || issue[:migration_id]}"
          end
          exit 1
        end
      end

      desc 'List models with schema drift'
      task :schema_drift do
        registry = Registry.new
        drift = registry.schema_drift

        if drift.empty?
          puts 'No schema drift detected'
        else
          puts 'Models with schema drift:'
          drift.each { |model| puts "  - #{model}" }
        end
      end
    end

    # Shortcut: familia:migrate runs all pending
    desc 'Run all pending migrations'
    task migrate: 'migrate:run'
  end
end