Class: ClientperfMigrations
- Inherits:
-
Object
- Object
- ClientperfMigrations
- Defined in:
- lib/clientperf_migrations.rb
Constant Summary collapse
- MIGRATION_NAMES =
%w(add_clientperf_tables add_clientperf_indexes)
- MIGRATION_CONTENTS =
{ :add_clientperf_tables => %( class AddClientperfTables < ActiveRecord::Migration def self.up create_table :clientperf_uris do |t| t.string :uri t.timestamps end create_table :clientperf_results do |t| t.integer :clientperf_uri_id t.integer :milliseconds t.timestamps end end def self.down drop_table :clientperf_uris drop_table :clientperf_results end end), :add_clientperf_indexes => %( class AddClientperfIndexes < ActiveRecord::Migration def self.up add_index :clientperf_uris, :uri add_index :clientperf_results, :clientperf_uri_id end def self.down remove_index :clientperf_uris, :uri remove_index :clientperf_results, :clientperf_uri_id end end) }
Class Method Summary collapse
- .generate(migration_name) ⇒ Object
- .install(migration) ⇒ Object
- .install_new ⇒ Object
- .migration_path(migration_name) ⇒ Object (also: exists?)
Class Method Details
.generate(migration_name) ⇒ Object
47 48 49 |
# File 'lib/clientperf_migrations.rb', line 47 def generate(migration_name) Rails::Generator::Scripts::Generate.new.run(['migration', migration_name]) end |
.install(migration) ⇒ Object
56 57 58 59 60 |
# File 'lib/clientperf_migrations.rb', line 56 def install(migration) File.open(migration_path(migration), 'w') do |file| file << MIGRATION_CONTENTS[migration.to_sym] end end |
.install_new ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/clientperf_migrations.rb', line 39 def install_new to_migrate = MIGRATION_NAMES.reject {|name| exists?(name) } to_migrate.each do |migration| generate(migration) install(migration) end end |
.migration_path(migration_name) ⇒ Object Also known as: exists?
51 52 53 |
# File 'lib/clientperf_migrations.rb', line 51 def migration_path(migration_name) Dir[File.join(RAILS_ROOT, 'db', 'migrate', "*_#{migration_name}.rb")].first end |