Class: Familia::Migration::RakeTasks

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

Overview

Installs familia:migrate rake tasks. See file header for task list.

Instance Method Summary collapse

Constructor Details

#initializeRakeTasks

Returns a new instance of RakeTasks.



23
24
25
# File 'lib/familia/migration/rake_tasks.rb', line 23

def initialize
  define_tasks
end

Instance Method Details

#define_tasksObject



27
28
29
30
31
32
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
# File 'lib/familia/migration/rake_tasks.rb', line 27

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