communard 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/communard/commands.rb +13 -7
- data/lib/communard/version.rb +1 -1
- data/spec/integration_spec.rb +12 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d160711820fe427786947a0718c53cb73a2167df5fb714196ffc81e77fe148a
|
4
|
+
data.tar.gz: 5642f174554fbbdbf006726823d34e582f5b0791fa1e5ee86541fd69f3ec8c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a5811b7dd25ef9aba12a113b12b8b50b22a176c7023ed190356eee6e874840ec0c6a99476252401bef88a06eddc158bb875c4beed249036ebb5286c52544af8
|
7
|
+
data.tar.gz: b098d85743d78519bcb4e57e08dfedc0c574237e3600d97af023524b2ec0a2740c511c153de01681d1cc6c4efe49caa619aa6c7045cb714d72cfe63e693ab692
|
data/lib/communard/commands.rb
CHANGED
@@ -50,11 +50,16 @@ module Communard
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def rollback(step: 1)
|
53
|
-
|
54
|
-
if
|
55
|
-
migrate(target:
|
53
|
+
available = applied_migrations
|
54
|
+
if available.size == 1
|
55
|
+
migrate(target: 0)
|
56
56
|
else
|
57
|
-
|
57
|
+
target = available[-step - 1]
|
58
|
+
if target
|
59
|
+
migrate(target: target.split(/_/, 2).first)
|
60
|
+
else
|
61
|
+
fail ArgumentError, "Cannot roll back to #{step}"
|
62
|
+
end
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
@@ -75,7 +80,7 @@ module Communard
|
|
75
80
|
results = Hash.new { |h, k| h[k] = Status.new(k, false, false) }
|
76
81
|
available = Pathname.glob(migrations_dir.join("*.rb")).map(&:basename).map(&:to_s)
|
77
82
|
available.each { |migration| results[migration].available = true }
|
78
|
-
applied_migrations
|
83
|
+
applied_migrations.each { |migration| results[migration].applied = true }
|
79
84
|
|
80
85
|
$stdout.puts
|
81
86
|
$stdout.puts "database: #{connection.opts.fetch(:database)}"
|
@@ -101,12 +106,13 @@ module Communard
|
|
101
106
|
|
102
107
|
private
|
103
108
|
|
104
|
-
def applied_migrations
|
109
|
+
def applied_migrations
|
110
|
+
available = Pathname.glob(migrations_dir.join("*.rb")).map(&:basename).map(&:to_s)
|
105
111
|
m = migrator(allow_missing_migration_files: true)
|
106
112
|
if m.is_a?(Sequel::IntegerMigrator)
|
107
113
|
available.select { |f| f.split("_", 2).first.to_i <= m.current }
|
108
114
|
else
|
109
|
-
|
115
|
+
m.applied_migrations
|
110
116
|
end
|
111
117
|
end
|
112
118
|
|
data/lib/communard/version.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -6,6 +6,10 @@ RSpec.describe "Integration", type: :aruba do
|
|
6
6
|
run_tests("sqlite://db/test.sqlite3")
|
7
7
|
end
|
8
8
|
|
9
|
+
example "SQLite with timestamps" do
|
10
|
+
run_tests("sqlite://db/test.sqlite3", timestamps: true)
|
11
|
+
end
|
12
|
+
|
9
13
|
example "PostgreSQL" do
|
10
14
|
run_tests("postgresql://localhost:5432/communard_test")
|
11
15
|
end
|
@@ -14,7 +18,7 @@ RSpec.describe "Integration", type: :aruba do
|
|
14
18
|
run_tests("mysql2://root@localhost:3306/communard_test")
|
15
19
|
end
|
16
20
|
|
17
|
-
def run_tests(database_config)
|
21
|
+
def run_tests(database_config, options = {})
|
18
22
|
write_file "Rakefile", <<-FILE.gsub(/^\s{6}/, "")
|
19
23
|
$LOAD_PATH.unshift(File.expand_path("../../../lib", __FILE__))
|
20
24
|
require "communard/rake"
|
@@ -23,7 +27,11 @@ RSpec.describe "Integration", type: :aruba do
|
|
23
27
|
end
|
24
28
|
FILE
|
25
29
|
|
26
|
-
|
30
|
+
if options[:timestamps]
|
31
|
+
run_simple "bundle exec communard migration create_posts --timestamps"
|
32
|
+
else
|
33
|
+
run_simple "bundle exec communard migration create_posts"
|
34
|
+
end
|
27
35
|
|
28
36
|
glob = Dir[expand_path("db/migrate/*_create_posts.rb")]
|
29
37
|
file = glob.first
|
@@ -46,6 +54,8 @@ RSpec.describe "Integration", type: :aruba do
|
|
46
54
|
run_simple "bundle exec rake db:create"
|
47
55
|
|
48
56
|
run_simple "bundle exec rake db:migrate"
|
57
|
+
|
58
|
+
run_simple "bundle exec rake db:migrate:redo"
|
49
59
|
end
|
50
60
|
|
51
61
|
end
|