ridgepole 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/ridgepole/delta.rb +1 -1
- data/lib/ridgepole/dsl_parser.rb +24 -1
- data/lib/ridgepole/version.rb +1 -1
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +10 -10
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a3e5a9549db69b5028a0f9a8bc7cff951a3617ca7eced3c6be06f31bc373f4e
|
4
|
+
data.tar.gz: 756a16fecffa1a8c0f62a3f0a5d58a142377ca99509106865354ae6b8676317f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6441491b72d7dcdfad0e74e58bfd6a950d3ed7876e9060e5812b86b013ddae9cd69d65f86ac1d7d32f4b046d0c1e2e126deade4ef891ab25954b4683d13bd32d
|
7
|
+
data.tar.gz: f30396aead19b62e243a2b135a27a2313ebbd05d429803ea8e0ee38c841f6729801a211cfa57e6d8f9b59fbef834f23d43d73d4f1684455bee19210f8eecce0e
|
data/README.md
CHANGED
@@ -101,6 +101,8 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
101
101
|
* Fix for `add_foreign_key(..., column: ,,,)` ([pull#278](https://github.com/winebarrel/ridgepole/pull/278))
|
102
102
|
* `>= 0.8.0`
|
103
103
|
* Support Rails 6.0
|
104
|
+
* `>= 0.8.1`
|
105
|
+
* Drop tables in an order considering foreign key constraints ([pull#284](https://github.com/winebarrel/ridgepole/pull/284))
|
104
106
|
</details>
|
105
107
|
|
106
108
|
## Installation
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -42,7 +42,7 @@ module Ridgepole
|
|
42
42
|
append_change(table_name, attrs, buf, pre_buf_for_fk, post_buf_for_fk)
|
43
43
|
end
|
44
44
|
|
45
|
-
(@delta[:delete] || {}).
|
45
|
+
(@delta[:delete] || {}).reverse_each do |table_name, attrs|
|
46
46
|
append_drop_table(table_name, attrs, buf)
|
47
47
|
end
|
48
48
|
|
data/lib/ridgepole/dsl_parser.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tsort'
|
4
|
+
|
3
5
|
module Ridgepole
|
4
6
|
class DSLParser
|
5
7
|
def initialize(options = {})
|
@@ -10,7 +12,11 @@ module Ridgepole
|
|
10
12
|
definition, execute = Context.eval(dsl, opts)
|
11
13
|
check_orphan_index(definition)
|
12
14
|
check_orphan_foreign_key(definition)
|
13
|
-
|
15
|
+
sorted_definition = {}
|
16
|
+
DependencyGraph.new(definition).tsort_each do |table_name|
|
17
|
+
sorted_definition[table_name] = definition[table_name]
|
18
|
+
end
|
19
|
+
[sorted_definition, execute]
|
14
20
|
end
|
15
21
|
|
16
22
|
private
|
@@ -26,5 +32,22 @@ module Ridgepole
|
|
26
32
|
raise "Table `#{table_name}` to create the foreign key is not defined: #{attrs[:foreign_keys].keys.join(',')}" if attrs[:foreign_keys] && !(attrs[:definition])
|
27
33
|
end
|
28
34
|
end
|
35
|
+
|
36
|
+
class DependencyGraph
|
37
|
+
include TSort
|
38
|
+
|
39
|
+
def initialize(definition)
|
40
|
+
@definition = definition
|
41
|
+
end
|
42
|
+
|
43
|
+
def tsort_each_child(table_name, &block)
|
44
|
+
keys = @definition[table_name].fetch(:foreign_keys, {})
|
45
|
+
keys.each_value { |v| block.call(v[:to_table]) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def tsort_each_node(&block)
|
49
|
+
@definition.each_key(&block)
|
50
|
+
end
|
51
|
+
end
|
29
52
|
end
|
30
53
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -60,29 +60,29 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
60
60
|
context 'when drop fk when drop table' do
|
61
61
|
let(:dsl) do
|
62
62
|
erbh(<<-ERB)
|
63
|
-
create_table "
|
63
|
+
create_table "0_parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
|
64
64
|
end
|
65
65
|
|
66
|
-
create_table "
|
67
|
-
t.integer "
|
68
|
-
t.index ["
|
66
|
+
create_table "1_child", force: :cascade do |t|
|
67
|
+
t.integer "0_parent_id"
|
68
|
+
t.index ["0_parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
69
69
|
end
|
70
70
|
|
71
|
-
add_foreign_key "
|
71
|
+
add_foreign_key "1_child", "0_parent", name: "child_ibfk_1"
|
72
72
|
ERB
|
73
73
|
end
|
74
74
|
|
75
75
|
let(:sorted_dsl) do
|
76
76
|
erbh(<<-ERB)
|
77
|
-
create_table "
|
78
|
-
t.integer "parent_id"
|
79
|
-
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
77
|
+
create_table "0_parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
|
80
78
|
end
|
81
79
|
|
82
|
-
create_table "
|
80
|
+
create_table "1_child", force: :cascade do |t|
|
81
|
+
t.integer "0_parent_id"
|
82
|
+
t.index ["0_parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
83
83
|
end
|
84
84
|
|
85
|
-
add_foreign_key "
|
85
|
+
add_foreign_key "1_child", "0_parent", name: "child_ibfk_1"
|
86
86
|
ERB
|
87
87
|
end
|
88
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridgepole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -442,8 +442,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
442
442
|
- !ruby/object:Gem::Version
|
443
443
|
version: '0'
|
444
444
|
requirements: []
|
445
|
-
|
446
|
-
rubygems_version: 2.7.6
|
445
|
+
rubygems_version: 3.0.3
|
447
446
|
signing_key:
|
448
447
|
specification_version: 4
|
449
448
|
summary: Ridgepole is a tool to manage DB schema.
|