db-migrate 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/bin/migrate +2 -1
- data/db-migrate.gemspec +1 -1
- data/lib/migrate/migrator.rb +10 -6
- data/lib/migrate/storage/db.rb +8 -0
- data/spec/lib/migrator_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ae6c6492a442ab6fa756c01499bc6fc81d2aa2e
|
4
|
+
data.tar.gz: 3cf19498e617936ffa92e44f6ac1f78ca7cf8e72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 515868059766ce618c04f031cd336a7f7335718dab876660224d643b2c3e87217bb47f18904010233df7181e8f791af82363e1c02f772deed123be2470acd4de
|
7
|
+
data.tar.gz: 757b86fea6a8c192599057930f93fbb76083550f575a46b5e4010c00cdbfea9f87170b693f1092f866f350540aa127914db9092b8903aa3bfdf5c17bfaa10af9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,12 +83,16 @@ version_number=version_number_table_name
|
|
83
83
|
If configuration file does not exist, it will run interactive configuration file creation process. You will answer few questions about your database, and **migrate** will create configuration file for you.
|
84
84
|
|
85
85
|
#### new
|
86
|
-
|
86
|
+
This command will generate migration scripts for you based on your prefered language.
|
87
87
|
|
88
|
-
You will get new directory in format `vXXX-YYYY`, where `XXX` is version number, and `YYY` is short description you provide. Inside generated directory there will be two files. `up.LANG` and `down.LANG`, where `LANG` is language you use for writing migration scripts.
|
88
|
+
You will get new directory in format `vXXX-YYYY`, where `XXX` is version number, and `YYY` is short description you provide. Inside generated directory there will be two files. `up.LANG` and `down.LANG`, where `LANG` is language you use for writing migration scripts.
|
89
89
|
|
90
90
|
#### up
|
91
|
-
When you are done with writing your `up` and `down` migration script, you can execute **migrate up** to run up migration script for new version.
|
91
|
+
When you are done with writing your `up` and `down` migration script, you can execute **migrate up** to run up migration script for new version.
|
92
|
+
|
93
|
+
Running `up` without arguments will move for one version up. You can also execute multiple migrations in single call by providing `--to n` argument, where `n` is highest version where you want to navigate.
|
94
|
+
|
95
|
+
If you want to run all remaining available migrations, you can pass `-a` flag to `up` command, and **migrate** will run all available migrations.
|
92
96
|
|
93
97
|
#### down
|
94
98
|
You can also use **migrate down** to go one version back. `down` comand also accepts `--to n` argument, but in this case `n` is lowest version where you want to navigate.
|
data/bin/migrate
CHANGED
@@ -130,8 +130,9 @@ class CLI < Thor
|
|
130
130
|
|
131
131
|
desc "up", "Upgrade database schema"
|
132
132
|
option :to, :aliases => "-t", :desc => "Upgrade to the version"
|
133
|
+
option :all, :aliases => "-a", :type => :boolean, :default => false, :desc => "Execute all up migrations"
|
133
134
|
def up
|
134
|
-
@migrator.up(options[:to])
|
135
|
+
@migrator.up(options[:to], options[:all])
|
135
136
|
rescue VersionNotFound => e
|
136
137
|
Log.error("Next version not found.")
|
137
138
|
rescue Exception => e
|
data/db-migrate.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'db-migrate'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.1'
|
4
4
|
s.licenses = ['MIT']
|
5
5
|
s.summary = "Tool for managing and executing your database migrations."
|
6
6
|
s.description = "#{s.summary} It supports multiple databases and multiple languages for writing migration scripts."
|
data/lib/migrate/migrator.rb
CHANGED
@@ -104,15 +104,19 @@ module Migrate
|
|
104
104
|
Log.success("Migrations executed. Current version: #{@db.current_version}")
|
105
105
|
end
|
106
106
|
|
107
|
-
def up(to_version=nil)
|
107
|
+
def up(to_version=nil, all=false)
|
108
108
|
@db.tx do
|
109
109
|
self.exec_migrations do |last_version|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
if all
|
111
|
+
@db.migrations_from(@db.next_version)
|
112
|
+
else
|
113
|
+
new_version = @db.next_version
|
114
|
+
if to_version == nil
|
115
|
+
to_version = new_version
|
116
|
+
end
|
114
117
|
|
115
|
-
|
118
|
+
@db.migrations_range(new_version, to_version, true)
|
119
|
+
end
|
116
120
|
end
|
117
121
|
end
|
118
122
|
end
|
data/lib/migrate/storage/db.rb
CHANGED
@@ -41,6 +41,14 @@ module Migrate
|
|
41
41
|
eos
|
42
42
|
end
|
43
43
|
|
44
|
+
def migrations_from(from)
|
45
|
+
self.exec_sql <<-eos
|
46
|
+
SELECT * FROM #{@config.version_info}
|
47
|
+
WHERE version >= #{from}
|
48
|
+
ORDER BY version
|
49
|
+
eos
|
50
|
+
end
|
51
|
+
|
44
52
|
def extract_version(results)
|
45
53
|
if results && results.count > 0
|
46
54
|
results[0]["version"]
|
data/spec/lib/migrator_spec.rb
CHANGED
@@ -65,6 +65,19 @@ describe "Migrator" do
|
|
65
65
|
expect(current.to_i + 2).to eq(db.current_version().to_i)
|
66
66
|
end
|
67
67
|
|
68
|
+
it "should execute all up migrations" do
|
69
|
+
db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
|
70
|
+
db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
|
71
|
+
current = db.current_version().to_i
|
72
|
+
create_migration_dir.call(current + 1)
|
73
|
+
create_migration_dir.call(current + 2)
|
74
|
+
create_migration_dir.call(current + 3)
|
75
|
+
create_migration_dir.call(current + 4)
|
76
|
+
migrator.up(nil, true)
|
77
|
+
|
78
|
+
expect(current.to_i + 4).to eq(db.current_version().to_i)
|
79
|
+
end
|
80
|
+
|
68
81
|
it "should execute one down migration" do
|
69
82
|
current = db.current_version().to_i
|
70
83
|
create_migration_dir.call(current)
|