db-migrate 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c9d9e26ef60000e8df08e69c64785f48916b3cf
4
- data.tar.gz: d0ee951a80e3c977887261eeaa309893b6613e7a
3
+ metadata.gz: 6ae6c6492a442ab6fa756c01499bc6fc81d2aa2e
4
+ data.tar.gz: 3cf19498e617936ffa92e44f6ac1f78ca7cf8e72
5
5
  SHA512:
6
- metadata.gz: ff194194be430978206223312659d01aec0d1f0e9edac2936e56119992f4cb49bab9c82e016c2979610f71bdf215196748d0cd418174c5388ec0b2153264550d
7
- data.tar.gz: 717dfe6e6efa4f7f8c604447b4cd585bd37d4351de73efef85a96f232aa194f81e9e169883240022a71f116eddea57f15e95dd8c9102b909946bf9e276cf952e
6
+ metadata.gz: 515868059766ce618c04f031cd336a7f7335718dab876660224d643b2c3e87217bb47f18904010233df7181e8f791af82363e1c02f772deed123be2470acd4de
7
+ data.tar.gz: 757b86fea6a8c192599057930f93fbb76083550f575a46b5e4010c00cdbfea9f87170b693f1092f866f350540aa127914db9092b8903aa3bfdf5c17bfaa10af9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- db-migrate (0.2.0)
4
+ db-migrate (0.2.1)
5
5
  colorize (= 0.7.7)
6
6
  highline (= 1.7.8)
7
7
  json (= 1.8.3)
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
- After that you can start generating migrations by using **migrate new** command. This will generate migration scripts for you based on your prefered language.
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. You can also execute multiple migrations in single call by providing `--to n` argument, where `n` is highest version where you want to navigate.
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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'db-migrate'
3
- s.version = '0.2.0'
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."
@@ -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
- new_version = @db.next_version
111
- if to_version == nil
112
- to_version = new_version
113
- end
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
- @db.migrations_range(new_version, to_version, true)
118
+ @db.migrations_range(new_version, to_version, true)
119
+ end
116
120
  end
117
121
  end
118
122
  end
@@ -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"]
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Pusic