Module: SimpleDataMigrations
- Defined in:
- lib/simple_data_migrations.rb,
lib/simple_data_migrations/entry.rb,
lib/simple_data_migrations/utils.rb,
lib/simple_data_migrations/railtie.rb,
lib/simple_data_migrations/version.rb,
lib/simple_data_migrations/concurrent_run.rb,
lib/generators/simple_data_migrations/install_generator.rb,
lib/generators/simple_data_migrations/template_generator.rb
Defined Under Namespace
Modules: ConcurrentRun, Utils
Classes: Entry, InstallGenerator, Railtie, TemplateGenerator
Constant Summary
collapse
- VERSION =
"0.2.2"
Class Method Summary
collapse
Class Method Details
.bootstrap ⇒ Object
52
53
54
55
|
# File 'lib/simple_data_migrations.rb', line 52
def self.bootstrap
attributes = Utils.script_files.map { |filename| {version: Utils.version(filename)} }
Entry.insert_all!(attributes)
end
|
.run ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/simple_data_migrations.rb', line 28
def self.run
ran_versions = Utils.ran_versions
non_run_scripts = Utils.script_files.select do |filename|
!ran_versions.include?(Utils.version(filename))
end
if ENV["VERSION"]
non_run_scripts.select! { |filename| Utils.version(filename) == ENV["VERSION"] }
end
non_run_scripts.each do |filename|
Thor::Shell::Basic.new.say("Running data migration: #{filename}")
time = Benchmark.measure do
load Utils.root.join(filename)
end
measure = "%.4fs" % time.real
Thor::Shell::Basic.new.say("Finished in #{measure}")
end
end
|
.status ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/simple_data_migrations.rb', line 13
def self.status
ran_versions = Utils.ran_versions
files = Utils.script_files
all_versions = ran_versions | files.map { |filename| Utils.version(filename) }
result = all_versions.sort.map do |version|
filename = files.find { |file| file.start_with?(version) }
[ran_versions.include?(version) ? "up" : "down", version, Utils.humanize_filename(filename)]
end
result.prepend(["Status", "Version", "Name"])
Thor::Shell::Basic.new.print_table(result)
end
|