Skip to content

Commit

Permalink
Merge pull request #80 from gocardless/add_reference
Browse files Browse the repository at this point in the history
Remove add_reference and remove_reference
  • Loading branch information
James Turley authored Mar 16, 2020
2 parents 171bc69 + 6ad4908 commit 592f626
Show file tree
Hide file tree
Showing 18 changed files with 8 additions and 357 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ We now have three new migration files:

class AddReferenceOnFoosToBars < Nandi::Migration
def up
add_reference :foos, :bar
add_column :foos, :bar_id, :bigint
end

def down
remove_reference :foos, :bar
remove_column :foos, :bar_id
end
end

Expand Down Expand Up @@ -286,12 +286,6 @@ create_table :widgets do |t|
end
```

### `#add_reference(table, ref_name, **extra_args)`
Adds a new reference column. Nandi will validate that the foreign key flag is not set to true; use `add_foreign_key` and `validate_foreign_key` instead!

### `#remove_reference(table, ref_name, **extra_args)`
Removes a reference column.

### `#remove_column(table, name, **extra_args)`
Remove an existing column.

Expand Down
6 changes: 3 additions & 3 deletions lib/generators/nandi/foreign_key/foreign_key_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ForeignKeyGenerator < Rails::Generators::Base
argument :target, type: :string
class_option :name, type: :string
class_option :column, type: :string
class_option :type, type: :string
class_option :type, type: :string, default: "bigint"
class_option :no_create_column, type: :boolean
class_option :validation_timeout, type: :numeric, default: 15 * 60 * 1000

Expand Down Expand Up @@ -61,11 +61,11 @@ def validate_foreign_key
private

def type
options["type"]&.to_sym
options["type"].to_sym
end

def reference_name
target.singularize.to_sym
"#{target.singularize}_id".to_sym
end

def base_path
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/nandi/foreign_key/templates/add_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

class <%= add_reference_name.camelize %> < Nandi::Migration
def up
add_reference <%= format_value(table) %>, <%= format_value(reference_name) %><% if type %>, type: <%= format_value(type) %><% end %>
add_column <%= format_value(table) %>, <%= format_value(reference_name) %>, <%= format_value(type) %>
end

def down
remove_reference <%= format_value(table) %>, <%= format_value(reference_name) %>
remove_column <%= format_value(table) %>, <%= format_value(reference_name) %>
end
end
2 changes: 0 additions & 2 deletions lib/nandi/instructions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
require "nandi/instructions/create_table"
require "nandi/instructions/drop_table"
require "nandi/instructions/add_column"
require "nandi/instructions/add_reference"
require "nandi/instructions/remove_reference"
require "nandi/instructions/remove_column"
require "nandi/instructions/add_foreign_key"
require "nandi/instructions/drop_constraint"
Expand Down
23 changes: 0 additions & 23 deletions lib/nandi/instructions/add_reference.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/nandi/instructions/remove_reference.rb

This file was deleted.

25 changes: 0 additions & 25 deletions lib/nandi/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,6 @@ def add_column(table, name, type, **kwargs)
)
end

# Adds a new reference column. Nandi will validate that the foreign key flag
# is not set to true; use `add_foreign_key` and `validate_foreign_key` instead!
# @param table [Symbol, String] The name of the table to add the column to
# @param ref_name [Symbol, String] The referenced column name
# @param kwargs [Hash] Arbitrary options to be passed to the backend.
def add_reference(table, ref_name, **kwargs)
current_instructions << Instructions::AddReference.new(
table: table,
ref_name: ref_name,
**kwargs,
)
end

# Removes a reference column.
# @param table [Symbol, String] The name of the table to remove the reference from
# @param ref_name [Symbol, String] The referenced column name
# @param kwargs [Hash] Arbitrary options to be passed to the backend.
def remove_reference(table, ref_name, **kwargs)
current_instructions << Instructions::RemoveReference.new(
table: table,
ref_name: ref_name,
**kwargs,
)
end

# Remove an existing column.
# @param table [Symbol, String] The name of the table to remove the column
# from.
Expand Down
12 changes: 0 additions & 12 deletions lib/nandi/renderers/active_record/instructions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,6 @@ class AddColumnCell < Base
formatted_property :extra_args
end

class AddReferenceCell < Base
formatted_property :table
formatted_property :ref_name
formatted_property :extra_args
end

class RemoveReferenceCell < Base
formatted_property :table
formatted_property :ref_name
formatted_property :extra_args
end

class RemoveColumnCell < Base
formatted_property :table
formatted_property :name
Expand Down
1 change: 0 additions & 1 deletion lib/nandi/validation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "nandi/validation/add_column_validator"
require "nandi/validation/add_reference_validator"
require "nandi/validation/remove_index_validator"
require "nandi/validation/each_validator"
require "nandi/validation/result"
Expand Down
38 changes: 0 additions & 38 deletions lib/nandi/validation/add_reference_validator.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/nandi/validation/each_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def call
RemoveIndexValidator.call(instruction)
when :add_column
AddColumnValidator.call(instruction)
when :add_reference
AddReferenceValidator.call(instruction)
else
success
end
Expand Down
2 changes: 1 addition & 1 deletion lib/nandi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Nandi
VERSION = "0.8.0"
VERSION = "0.9.0"
end

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 592f626

Please sign in to comment.