yeet_db 0.1.0 → 0.1.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/.gitignore +1 -0
- data/README.md +8 -8
- data/lib/generators/yeet_db/foreign_key_migration_generator.rb +1 -1
- data/lib/generators/yeet_db/templates/add_foreign_keys_yeet_db.rb +2 -1
- data/lib/yeet_db/ar_table.rb +5 -3
- data/lib/yeet_db/version.rb +1 -1
- data/yeet_db.png +0 -0
- 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: 8ec13f950af908e43a89e326bb81e173575c1ffe3e9ce9a122bc8eb8f2d45752
|
4
|
+
data.tar.gz: 19d2ddeae5479d30e5b804475887ff8f7f8de72a49295ff2402a82a05c0694d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e422f69dcd856fff98303b7794501da77592f39d378e11e5c424381bdcdad79614fd94fd9d6ba2ef6cc41d092cfaeed39b5483e248a389f323272381b70830dd
|
7
|
+
data.tar.gz: f2c7eeecae89d56097ef9200533e09a07d6157208debb290be1dc5564bccff664b6d9969ddb80fa3941075aac03ea43e0fe52f1063382606400f47539deeb9f1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
# yeet_db
|
3
|
+
# yeet_db - find missing foreign key constraints
|
4
4
|
|
5
5
|
yeet_db scans your rails tables for missing foreign key constraints. If there are no dangling records, it will create a migration to add the foreign key constraints on all the table it is safe.
|
6
6
|
|
7
7
|
If you have dangling migrations, check the generator logs to see where you have invalid orphaned rows. Orphaned row meaning a row with an id that doesn't exist in the associated table.
|
8
8
|
|
9
|
+
but [why should I use foreign keys?](https://softwareengineering.stackexchange.com/questions/375704/why-should-i-use-foreign-keys-in-database)
|
10
|
+
|
9
11
|
## Installation
|
10
12
|
|
11
13
|
Add this line to your application's Gemfile:
|
@@ -44,13 +46,11 @@ Rails 5.2 (but it may work with 5.0+)
|
|
44
46
|
|
45
47
|
## Road map to v1
|
46
48
|
|
47
|
-
[ ]
|
48
|
-
|
49
|
-
[ ] add rake task to automatically nullify or destroy dangling records
|
50
|
-
|
51
|
-
[ ]
|
52
|
-
|
53
|
-
[ ] support "soft delete" gems
|
49
|
+
- [ ] rspec tests
|
50
|
+
- [ ] add rake task identify all dangling records
|
51
|
+
- [ ] add rake task to automatically nullify or destroy dangling records
|
52
|
+
- [ ] run as a rake task
|
53
|
+
- [ ] support "soft delete" gems
|
54
54
|
|
55
55
|
|
56
56
|
## Development
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
class AddForeignKeysYeetDb < ActiveRecord::Migration<%= migration_version %>
|
3
4
|
def change
|
4
5
|
<% ::YeetDb::MissingForeignKeys.foreign_keys.each do |foreign_key| %>
|
5
6
|
add_foreign_key :<%= foreign_key.table_a %>,
|
6
|
-
:<%= foreign_key.table_b %>,
|
7
|
+
:<%= foreign_key.table_b %>,
|
7
8
|
column: :<%= foreign_key.column %>
|
8
9
|
<% end %>
|
9
10
|
end
|
data/lib/yeet_db/ar_table.rb
CHANGED
@@ -14,11 +14,11 @@ module YeetDb
|
|
14
14
|
next unless column.is_association?
|
15
15
|
|
16
16
|
unless column.model
|
17
|
-
puts "
|
17
|
+
puts "YeetDb - cannot find model for #{table_name} . #{column_name.name} | #{column&.association_table_name}"
|
18
18
|
end
|
19
19
|
|
20
20
|
unless column.association
|
21
|
-
puts "
|
21
|
+
puts "YeetDb - cannot find association for #{table_name} . #{column_name.name} | #{column&.association_table_name}"
|
22
22
|
end
|
23
23
|
|
24
24
|
next if column.polymorphic_association?
|
@@ -26,8 +26,10 @@ module YeetDb
|
|
26
26
|
next if column.association_table_name.blank?
|
27
27
|
|
28
28
|
if VerifyData.new(column: column).orphaned_rows?
|
29
|
-
puts "
|
29
|
+
puts "YeetDb - orphaned rows. Skipping #{table_name} . #{column_name.name} | #{column&.association_table_name}"
|
30
|
+
next
|
30
31
|
end
|
32
|
+
|
31
33
|
foreign_key = ForeignKey.new(table_a: table_name,
|
32
34
|
table_b: column&.association_table_name,
|
33
35
|
column: column_name.name)
|
data/lib/yeet_db/version.rb
CHANGED
data/yeet_db.png
CHANGED
Binary file
|