Class: Sequent::Rake::Tasks
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Sequent::Rake::Tasks
- Includes:
- Rake::DSL
- Defined in:
- lib/sequent/rake/tasks.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ migrations_path: 'db/migrate', event_store_schema: 'public' }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #display_deprecation_warning ⇒ Object
-
#initialize(options) ⇒ Tasks
constructor
A new instance of Tasks.
- #register! ⇒ Object
- #register_db_tasks! ⇒ Object
- #register_view_schema_tasks! ⇒ Object
Constructor Details
#initialize(options) ⇒ Tasks
Returns a new instance of Tasks.
19 20 21 |
# File 'lib/sequent/rake/tasks.rb', line 19 def initialize() @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/sequent/rake/tasks.rb', line 17 def @options end |
Instance Method Details
#display_deprecation_warning ⇒ Object
23 24 25 |
# File 'lib/sequent/rake/tasks.rb', line 23 def display_deprecation_warning warn '[DEPRECATED] Sequent::Rake::Tasks is deprecated. Please use Sequent::Rake::MigrationTasks tasks instead.' end |
#register! ⇒ Object
27 28 29 30 31 32 |
# File 'lib/sequent/rake/tasks.rb', line 27 def register! display_deprecation_warning register_db_tasks! register_view_schema_tasks! end |
#register_db_tasks! ⇒ Object
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 |
# File 'lib/sequent/rake/tasks.rb', line 34 def register_db_tasks! namespace :db do desc 'Create the database' task :create do display_deprecation_warning current_environments.each do |env| env_db = db_config(env) puts "Create database #{env_db['database']}" Sequent::Support::Database.create!(env_db) end end desc 'Drop the database' task :drop do display_deprecation_warning current_environments.each do |env| env_db = db_config(env) puts "Drop database #{env_db['database']}" Sequent::Support::Database.drop!(env_db) end end task :establish_connection do env_db = db_config(.fetch(:environment)) Sequent::Support::Database.establish_connection(env_db) end desc 'Migrate the database' task migrate: :establish_connection do display_deprecation_warning database.create_schema!(.fetch(:event_store_schema)) database.migrate(.fetch(:migrations_path)) end end end |
#register_view_schema_tasks! ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sequent/rake/tasks.rb', line 73 def register_view_schema_tasks! namespace :view_schema do desc 'Build the view schema' task build: :'db:establish_connection' do display_deprecation_warning if database.schema_exists?(view_projection.schema_name) puts "View version #{view_projection.version} already exists; no need to build it" else database.create_schema!(view_projection.schema_name) view_projection.build! end end desc 'Drop the view schema' task drop: :'db:establish_connection' do display_deprecation_warning database.drop_schema!(view_projection.schema_name) end end end |