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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e71e7e7fb74ddf4213f433033223462415c8b89a1e073d6121ccfc003936502
4
- data.tar.gz: ff1bd69f2c3e8297a66225e616bcce8f5fefaf9e5bebeac7860496d7df071cf9
3
+ metadata.gz: 8ec13f950af908e43a89e326bb81e173575c1ffe3e9ce9a122bc8eb8f2d45752
4
+ data.tar.gz: 19d2ddeae5479d30e5b804475887ff8f7f8de72a49295ff2402a82a05c0694d8
5
5
  SHA512:
6
- metadata.gz: ae85df15bf889bae95de1caaae5f515ff81c340a21cef83498ad6a713c4341b5da9ccfc91f52d660681eee429891b5b0f0af763dbc5b075f7dbf003f6c1938e4
7
- data.tar.gz: '099ed8ea5a188f40d77c7e587ce758991368c1729348a88b85c41554cc4c081680817f31e1896015ed3513e1c146050518dfb32d83e012027dbfaead7db48567'
6
+ metadata.gz: e422f69dcd856fff98303b7794501da77592f39d378e11e5c424381bdcdad79614fd94fd9d6ba2ef6cc41d092cfaeed39b5483e248a389f323272381b70830dd
7
+ data.tar.gz: f2c7eeecae89d56097ef9200533e09a07d6157208debb290be1dc5564bccff664b6d9969ddb80fa3941075aac03ea43e0fe52f1063382606400f47539deeb9f1
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.gem
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  ![Foreign Key by Ary Prasetyo from the Noun Project](./yeet_db.png)
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
- [ ] add rake task identify all dangling records
48
-
49
- [ ] add rake task to automatically nullify or destroy dangling records
50
-
51
- [ ] run as a rake task
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
@@ -16,7 +16,7 @@ module YeetDb
16
16
  private
17
17
 
18
18
  def migration_file
19
- File.join("db/migrate", "add_foreign_keys.rb")
19
+ File.join("db/migrate", "add_foreign_keys_yeet_db.rb")
20
20
  end
21
21
 
22
22
  def migration_version
@@ -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
@@ -14,11 +14,11 @@ module YeetDb
14
14
  next unless column.is_association?
15
15
 
16
16
  unless column.model
17
- puts "WARNING - cannot find model for #{table_name} . #{column_name.name} | #{column&.association_table_name}"
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 "WARNING - cannot find association for #{table_name} . #{column_name.name} | #{column&.association_table_name}"
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 "WARNING - orphaned rows #{table_name} . #{column_name.name} | #{column&.association_table_name}"
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)
@@ -1,3 +1,3 @@
1
1
  module YeetDb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/yeet_db.png CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeet_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Coleman