Class: Sequel::RakeTasks
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Sequel::RakeTasks
- Includes:
- Rake::DSL
- Defined in:
- lib/sequel_rake_tasks.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#connection_config ⇒ Object
readonly
Returns the value of attribute connection_config.
-
#migrations_dir ⇒ Object
readonly
Returns the value of attribute migrations_dir.
-
#migrator_klass ⇒ Object
readonly
Returns the value of attribute migrator_klass.
-
#schema_file ⇒ Object
readonly
Returns the value of attribute schema_file.
-
#seed_file ⇒ Object
readonly
Returns the value of attribute seed_file.
-
#structure_file ⇒ Object
readonly
Returns the value of attribute structure_file.
Instance Method Summary collapse
- #db_commands ⇒ Object
- #define_tasks ⇒ Object
-
#initialize(options) ⇒ RakeTasks
constructor
A new instance of RakeTasks.
- #migrator ⇒ Object
Constructor Details
#initialize(options) ⇒ RakeTasks
Returns a new instance of RakeTasks.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sequel_rake_tasks.rb', line 20 def initialize() @connection = [:connection] @connection_config = [:connection_config] @migrator_klass = [:migrator] @migrations_dir = [:migrations_dir] @schema_file = [:schema_file] @seed_file = [:seed_file] @structure_file = [:structure_file] define_tasks end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def connection @connection end |
#connection_config ⇒ Object (readonly)
Returns the value of attribute connection_config.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def connection_config @connection_config end |
#migrations_dir ⇒ Object (readonly)
Returns the value of attribute migrations_dir.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def migrations_dir @migrations_dir end |
#migrator_klass ⇒ Object (readonly)
Returns the value of attribute migrator_klass.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def migrator_klass @migrator_klass end |
#schema_file ⇒ Object (readonly)
Returns the value of attribute schema_file.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def schema_file @schema_file end |
#seed_file ⇒ Object (readonly)
Returns the value of attribute seed_file.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def seed_file @seed_file end |
#structure_file ⇒ Object (readonly)
Returns the value of attribute structure_file.
12 13 14 |
# File 'lib/sequel_rake_tasks.rb', line 12 def structure_file @structure_file end |
Instance Method Details
#db_commands ⇒ Object
31 32 33 |
# File 'lib/sequel_rake_tasks.rb', line 31 def db_commands @db_commands ||= MysqlDbCommands.new(connection_config) end |
#define_tasks ⇒ Object
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 |
# File 'lib/sequel_rake_tasks.rb', line 39 def define_tasks namespace :db do desc 'Setup the database.' task :setup => [:create, :migrate] desc 'Reset the database.' task :reset => [:drop, :setup] desc 'Create the database.' task :create do |t, args| db_commands.create_database end desc 'Drop the database.' task :drop do db_commands.drop_database end desc 'Load the seeds' task :seed do load(seed_file) end desc 'Migrate the database.' task :migrate do migrator.run Rake::Task['db:schema:dump'].invoke end namespace :schema do desc 'Dump the current database schema as a migration.' task :dump do connection.extension :schema_dumper text = connection.dump_schema_migration(same_db: false) text = text.gsub(/ +$/, '') # remove trailing whitespace File.open(schema_file, 'w') { |f| f.write(text) } end end namespace :structure do desc 'Load the database structure file' task :load do raise '`structure_file` option not defined!' unless structure_file db_commands.load_sql_file(structure_file) end end end end |
#migrator ⇒ Object
35 36 37 |
# File 'lib/sequel_rake_tasks.rb', line 35 def migrator @migrator ||= migrator_klass.new(connection, migrations_dir) end |